MCPcopy
hub / github.com/istio/istio / TestIncludeFlagCommaHandling

Function TestIncludeFlagCommaHandling

tools/bug-report/pkg/bugreport/flags_test.go:26–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestIncludeFlagCommaHandling(t *testing.T) {
27 tests := []struct {
28 name string
29 args []string
30 want []*config2.SelectionSpec
31 }{
32 {
33 name: "comma-separated namespaces in single flag",
34 args: []string{"--include", "istio-system,istio-gateways"},
35 want: []*config2.SelectionSpec{
36 {Namespaces: []string{"istio-system", "istio-gateways"}},
37 },
38 },
39 {
40 name: "multiple include flags",
41 args: []string{"--include", "istio-system", "--include", "istio-gateways"},
42 want: []*config2.SelectionSpec{
43 {Namespaces: []string{"istio-system"}},
44 {Namespaces: []string{"istio-gateways"}},
45 },
46 },
47 {
48 name: "comma-separated namespaces with deployment filter",
49 args: []string{"--include", "ns1,ns2/istiod"},
50 want: []*config2.SelectionSpec{
51 {
52 Namespaces: []string{"ns1", "ns2"},
53 Deployments: []string{"istiod"},
54 },
55 },
56 },
57 {
58 name: "full spec with commas in multiple fields",
59 args: []string{"--include", "ns1,ns2/d1,d2/p1,p2"},
60 want: []*config2.SelectionSpec{
61 {
62 Namespaces: []string{"ns1", "ns2"},
63 Deployments: []string{"d1", "d2"},
64 Pods: []string{"p1", "p2"},
65 },
66 },
67 },
68 }
69
70 for _, tt := range tests {
71 t.Run(tt.name, func(t *testing.T) {
72 // Reset global state for each test case.
73 included = nil
74 gConfig = &config2.BugReportConfig{}
75
76 cmd := &cobra.Command{Use: "test"}
77 addFlags(cmd, gConfig)
78 cmd.SetArgs(tt.args)
79 // Parse flags without executing the command.
80 if err := cmd.ParseFlags(tt.args); err != nil {
81 t.Fatal(err)
82 }
83

Callers

nothing calls this directly

Calls 5

EqualFunction · 0.92
addFlagsFunction · 0.70
parseConfigFunction · 0.70
RunMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…