feat: Add to detect test
This commit is contained in:
parent
2017e6b113
commit
9520670d97
6
.github/workflows/go-tests.yml
vendored
6
.github/workflows/go-tests.yml
vendored
|
@ -108,6 +108,12 @@ jobs:
|
||||||
--health-timeout 10s
|
--health-timeout 10s
|
||||||
--health-retries 5
|
--health-retries 5
|
||||||
|
|
||||||
|
loki:
|
||||||
|
image: grafana/loki:2.8.0
|
||||||
|
ports:
|
||||||
|
- "3100:3100"
|
||||||
|
command: -config.file=/etc/loki/local-config.yaml
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Check out CrowdSec repository
|
- name: Check out CrowdSec repository
|
||||||
|
|
|
@ -136,14 +136,14 @@ func (lc *LokiClient) getURLFor(endpoint string, params map[string]string) strin
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
switch endpoint {
|
if endpoint == "loki/api/v1/tail" {
|
||||||
case "loki/api/v1/tail":
|
|
||||||
if u.Scheme == "http" {
|
if u.Scheme == "http" {
|
||||||
u.Scheme = "ws"
|
u.Scheme = "ws"
|
||||||
} else {
|
} else {
|
||||||
u.Scheme = "wss"
|
u.Scheme = "wss"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return u.String()
|
return u.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -235,7 +235,7 @@ func feedLoki(logger *log.Entry, n int, title string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if resp.StatusCode != 204 {
|
if resp.StatusCode != 204 {
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
logger.Error(string(b))
|
logger.Error(string(b))
|
||||||
return fmt.Errorf("Bad post status %d", resp.StatusCode)
|
return fmt.Errorf("Bad post status %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
@ -423,6 +423,9 @@ query: >
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
feedLoki(subLogger, 1, title)
|
feedLoki(subLogger, 1, title)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error : %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
lokiTomb.Kill(nil)
|
lokiTomb.Kill(nil)
|
||||||
err = lokiTomb.Wait()
|
err = lokiTomb.Wait()
|
||||||
|
|
|
@ -983,6 +983,16 @@ func TestDetectDatasourceValidation(t *testing.T) {
|
||||||
source: kafka`,
|
source: kafka`,
|
||||||
expected: setup.Setup{Setup: []setup.ServiceSetup{}},
|
expected: setup.Setup{Setup: []setup.ServiceSetup{}},
|
||||||
expectedErr: "invalid datasource for foobar: cannot create a kafka reader with an empty list of broker addresses",
|
expectedErr: "invalid datasource for foobar: cannot create a kafka reader with an empty list of broker addresses",
|
||||||
|
}, {
|
||||||
|
name: "source loki: required fields",
|
||||||
|
config: `
|
||||||
|
version: 1.0
|
||||||
|
detect:
|
||||||
|
foobar:
|
||||||
|
datasource:
|
||||||
|
source: loki`,
|
||||||
|
expected: setup.Setup{Setup: []setup.ServiceSetup{}},
|
||||||
|
expectedErr: "invalid datasource for foobar: Loki query is mandatory",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue