Skip to content

Commit

Permalink
feat: Add to detect test
Browse files Browse the repository at this point in the history
  • Loading branch information
lperdereau committed Jul 3, 2023
1 parent 63e28b3 commit 9a9c8d8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/go-tests.yml
Expand Up @@ -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: "Set up Go ${{ matrix.go-version }}"
Expand Down
Expand Up @@ -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()
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/acquisition/modules/loki/loki_test.go
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions pkg/setup/detect_test.go
Expand Up @@ -981,6 +981,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",
},
}

Expand Down

0 comments on commit 9a9c8d8

Please sign in to comment.