forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtail_test.go
57 lines (52 loc) · 1.53 KB
/
tail_test.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package loghttp
import (
"net/http"
"reflect"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/grafana/loki/pkg/logproto"
)
func TestParseTailQuery(t *testing.T) {
t.Parallel()
tests := []struct {
name string
r *http.Request
want *logproto.TailRequest
wantErr bool
}{
{"bad time", &http.Request{URL: mustParseURL(`?query={foo="bar"}&start=t`)}, nil, true},
{"bad limit", &http.Request{URL: mustParseURL(`?query={foo="bar"}&start=2016-06-10T21:42:24.760738998Z&limit=h`)}, nil, true},
{"bad delay",
&http.Request{
URL: mustParseURL(`?query={foo="bar"}&time=2016-06-10T21:42:24.760738998Z&limit=100&delay_for=fw`),
}, nil, true},
{"too much delay",
&http.Request{
URL: mustParseURL(`?query={foo="bar"}&time=2016-06-10T21:42:24.760738998Z&limit=100&delay_for=20`),
}, nil, true},
{"good",
&http.Request{
URL: mustParseURL(`?query={foo="bar"}&start=2017-06-10T21:42:24.760738998Z&limit=1000&delay_for=5`),
}, &logproto.TailRequest{
Query: `{foo="bar"}`,
DelayFor: 5,
Start: time.Date(2017, 06, 10, 21, 42, 24, 760738998, time.UTC),
Limit: 1000,
}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.r.ParseForm()
require.Nil(t, err)
got, err := ParseTailQuery(tt.r)
if (err != nil) != tt.wantErr {
t.Errorf("ParseTailQuery() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseTailQuery() = %v, want %v", got, tt.want)
}
})
}
}