-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathclient_test.go
More file actions
39 lines (29 loc) · 986 Bytes
/
client_test.go
File metadata and controls
39 lines (29 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package log
import (
"bytes"
"context"
"fmt"
"testing"
"time"
"github.com/grafana/loki/v3/pkg/logcli/output"
"github.com/stretchr/testify/require"
)
func TestClient(t *testing.T) {
t.Parallel()
is := require.New(t)
ctx, cancel := context.WithTimeout(t.Context(), time.Second)
defer cancel()
expectedTime := time.Now()
expectedLine := "hello loki client"
c := &Client{Client: NewFake(t, expectedTime, expectedLine)}
var buf bytes.Buffer
out, err := output.NewLogOutput(&buf, "default", &output.LogOutputOptions{
NoLabels: true, ColoredOutput: false, Timezone: time.Local,
})
is.NoError(err)
is.NoError(c.QueryRange(ctx, out, Query{Limit: 10}))
is.Equal(fmt.Sprintf("%s %s\n", expectedTime.Local().Format(time.RFC3339), expectedLine), buf.String())
buf.Reset()
is.NoError(c.TailQuery(ctx, 0, out, Query{QueryString: "{app=\"test\"}", Limit: 10}))
is.Equal(fmt.Sprintf("%s %s\n", expectedTime.Local().Format(time.RFC3339), expectedLine), buf.String())
}