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