-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathflags_test.go
More file actions
107 lines (100 loc) · 2.91 KB
/
Copy pathflags_test.go
File metadata and controls
107 lines (100 loc) · 2.91 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package command
import (
"testing"
runsCmd "github.com/deepsourcelabs/cli/command/runs"
issuesCmd "github.com/deepsourcelabs/cli/command/issues"
metricsCmd "github.com/deepsourcelabs/cli/command/metrics"
vulnsCmd "github.com/deepsourcelabs/cli/command/vulnerabilities"
"github.com/spf13/cobra"
)
type flagExpectation struct {
name string
defaultValue string
}
func TestRootSkipTLSVerifyFlag(t *testing.T) {
cmd := NewCmdRoot()
f := cmd.PersistentFlags().Lookup("skip-tls-verify")
if f == nil {
t.Fatal("expected skip-tls-verify persistent flag on root command, got nil")
}
if f.DefValue != "false" {
t.Errorf("expected default value %q, got %q", "false", f.DefValue)
}
}
func TestFlagDefaults(t *testing.T) {
tests := []struct {
name string
buildCmd func() *cobra.Command
expected []flagExpectation
}{
{
name: "issues",
buildCmd: issuesCmd.NewCmdIssues,
expected: []flagExpectation{
{name: "limit", defaultValue: "0"},
{name: "output", defaultValue: "pretty"},
{name: "verbose", defaultValue: "false"},
{name: "pr", defaultValue: "0"},
{name: "commit", defaultValue: ""},
{name: "repo", defaultValue: ""},
{name: "severity", defaultValue: "[]"},
{name: "category", defaultValue: "[]"},
{name: "analyzer", defaultValue: "[]"},
{name: "path", defaultValue: "[]"},
{name: "source", defaultValue: "[]"},
{name: "default-branch", defaultValue: "false"},
},
},
{
name: "metrics",
buildCmd: metricsCmd.NewCmdMetrics,
expected: []flagExpectation{
{name: "limit", defaultValue: "0"},
{name: "output", defaultValue: "pretty"},
{name: "verbose", defaultValue: "false"},
{name: "pr", defaultValue: "0"},
{name: "commit", defaultValue: ""},
{name: "repo", defaultValue: ""},
},
},
{
name: "vulnerabilities",
buildCmd: vulnsCmd.NewCmdVulnerabilities,
expected: []flagExpectation{
{name: "limit", defaultValue: "0"},
{name: "output", defaultValue: "pretty"},
{name: "verbose", defaultValue: "false"},
{name: "pr", defaultValue: "0"},
{name: "commit", defaultValue: ""},
{name: "repo", defaultValue: ""},
{name: "severity", defaultValue: "[]"},
},
},
{
name: "runs",
buildCmd: runsCmd.NewCmdRuns,
expected: []flagExpectation{
{name: "limit", defaultValue: "20"},
{name: "output", defaultValue: "pretty"},
{name: "commit", defaultValue: ""},
{name: "repo", defaultValue: ""},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := tt.buildCmd()
for _, exp := range tt.expected {
flag := cmd.Flags().Lookup(exp.name)
if flag == nil {
t.Errorf("flag %q not found on command %q", exp.name, tt.name)
continue
}
if flag.DefValue != exp.defaultValue {
t.Errorf("flag %q on command %q: expected default %q, got %q",
exp.name, tt.name, exp.defaultValue, flag.DefValue)
}
}
})
}
}