-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprofile_test.go
More file actions
90 lines (83 loc) · 1.87 KB
/
profile_test.go
File metadata and controls
90 lines (83 loc) · 1.87 KB
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
package cmd_test
import (
"context"
"io"
"testing"
"github.com/hamba/cmd/v3"
"github.com/hamba/logger/v2"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v3"
)
func TestNewProfiler(t *testing.T) {
log := logger.New(io.Discard, logger.LogfmtFormat(), logger.Error)
tests := []struct {
name string
args []string
wantErr assert.ErrorAssertionFunc
}{
{
name: "ignores no profiling",
wantErr: assert.NoError,
},
{
name: "starts profiler",
args: []string{
"--profiling.dsn=https://example.com?token=test&tenantid=me",
},
wantErr: assert.NoError,
},
{
name: "supports tags",
args: []string{
"--profiling.dsn=https://example.com?token=test&tenantid=me",
"--profiling.tags=cluster=test",
"--profiling.tags=namespace=num",
},
wantErr: assert.NoError,
},
{
name: "supports types",
args: []string{
"--profiling.dsn=https://example.com?token=test&tenantid=me",
"--profiling.types=cpu",
},
wantErr: assert.NoError,
},
{
name: "handles bad dsn",
args: []string{
"--profiling.dsn=:/",
},
wantErr: assert.Error,
},
{
name: "handles basic and token auth",
args: []string{
"--profiling.dsn=https://test:test@example.com?token=test&tenantid=me",
},
wantErr: assert.Error,
},
{
name: "handles bad tags",
args: []string{
"--profiling.dsn=https://example.com?token=test&tenantid=me",
"--profiling.tags=cluster",
"--profiling.tags=namespace=num",
},
wantErr: assert.Error,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
c := &cli.Command{
Flags: cmd.ProfilingFlags,
Action: func(_ context.Context, c *cli.Command) error {
_, err := cmd.NewProfiler(c, "my-service", log)
return err
},
}
err := c.Run(t.Context(), append([]string{"test"}, test.args...))
test.wantErr(t, err)
})
}
}