-
Notifications
You must be signed in to change notification settings - Fork 3
/
profile_test.go
83 lines (75 loc) · 1.91 KB
/
profile_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
package cmd_test
import (
"io"
"testing"
"time"
"github.com/hamba/cmd/v2"
"github.com/hamba/logger/v2"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v2"
)
func TestNewProfiler(t *testing.T) {
log := logger.New(io.Discard, logger.LogfmtFormat(), logger.Error)
tests := []struct {
name string
dsn string
uploadRate time.Duration
tags []string
types []string
wantErr assert.ErrorAssertionFunc
}{
{
name: "ignores no profiling",
wantErr: assert.NoError,
},
{
name: "starts profiler",
dsn: "https://example.com?token=test&tenantid=me",
wantErr: assert.NoError,
},
{
name: "supports tags",
dsn: "https://example.com?token=test&tenantid=me",
tags: []string{"cluster=test", "namespace=num"},
wantErr: assert.NoError,
},
{
name: "supports types",
dsn: "https://example.com?token=test&tenantid=me",
types: []string{"cpu"},
wantErr: assert.NoError,
},
{
name: "handles bad dsn",
dsn: ":/",
wantErr: assert.Error,
},
{
name: "handles basic and token auth",
dsn: "https://test:[email protected]?token=test&tenantid=me",
wantErr: assert.Error,
},
{
name: "handles bad tags",
dsn: "https://example.com?token=test&tenantid=me",
tags: []string{"cluster", "namespace=num"},
wantErr: assert.Error,
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
// t.Parallel()
c, fs := newTestContext()
fs.String(cmd.FlagProfilingDSN, test.dsn, "doc")
fs.Duration(cmd.FlagProfileUploadRate, test.uploadRate, "doc")
fs.Var(cli.NewStringSlice(test.tags...), cmd.FlagProfilingTags, "doc")
fs.Var(cli.NewStringSlice(test.types...), cmd.FlagProfilingTypes, "doc")
profiler, err := cmd.NewProfiler(c, "my-service", log)
if profiler != nil {
_ = profiler.Stop()
}
test.wantErr(t, err)
})
}
}