-
Notifications
You must be signed in to change notification settings - Fork 3
/
stats_test.go
126 lines (118 loc) · 2.58 KB
/
stats_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package cmd_test
import (
"io"
"testing"
"time"
"github.com/hamba/cmd/v2"
"github.com/hamba/logger/v2"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
)
func TestNewStats(t *testing.T) {
tests := []struct {
name string
dsn string
prefix string
tags *cli.StringSlice
wantErr require.ErrorAssertionFunc
}{
{
name: "no stats",
dsn: "",
prefix: "test",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "statsd",
dsn: "statsd://localhost:8125?flushBytes=1423&flushInterval=10s",
prefix: "test",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "l2met",
dsn: "l2met://",
prefix: "test",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "prometheus",
dsn: "prometheus://",
prefix: "test",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "prometheus with server",
dsn: "prom://127.0.0.1:51234",
prefix: "test",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "victoria metrics",
dsn: "victoriametrics://",
prefix: "test",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "victoria metrics with server",
dsn: "vm://127.0.0.1:51234",
prefix: "test",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "unknown stats scheme",
dsn: "unknownscheme://",
prefix: "",
tags: cli.NewStringSlice(),
wantErr: require.Error,
},
{
name: "invalid DSN",
dsn: "://",
prefix: "",
tags: cli.NewStringSlice(),
wantErr: require.Error,
},
{
name: "no prefix",
dsn: "l2met://",
prefix: "",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "tags",
dsn: "l2met://",
prefix: "",
tags: cli.NewStringSlice("a=b"),
wantErr: require.NoError,
},
{
name: "invalid tags",
dsn: "l2met://",
prefix: "",
tags: cli.NewStringSlice("a"),
wantErr: require.Error,
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
c, fs := newTestContext()
fs.String(cmd.FlagStatsDSN, test.dsn, "doc")
fs.Duration(cmd.FlagStatsInterval, time.Second, "doc")
fs.String(cmd.FlagStatsPrefix, test.prefix, "doc")
fs.Var(test.tags, cmd.FlagStatsTags, "doc")
log := logger.New(io.Discard, logger.LogfmtFormat(), logger.Error)
_, err := cmd.NewStatter(c, log)
test.wantErr(t, err)
})
}
}