MCPcopy
hub / github.com/kubesphere/kubekey / TestDebugArgsParse

Function TestDebugArgsParse

pkg/modules/debug/debug_test.go:93–144  ·  view source on GitHub ↗

TestDebugArgsParse tests argument parsing edge cases.

(t *testing.T)

Source from the content-addressed store, hash-verified

91
92// TestDebugArgsParse tests argument parsing edge cases.
93func TestDebugArgsParse(t *testing.T) {
94 testcases := []struct {
95 name string
96 args map[string]any
97 expectParseError bool
98 description string
99 }{
100 {
101 name: "valid args with string msg",
102 args: map[string]any{"msg": "Hello World"},
103 expectParseError: false,
104 description: "When msg is a string, should parse successfully",
105 },
106 {
107 name: "valid args with number msg",
108 args: map[string]any{"msg": 42},
109 expectParseError: false,
110 description: "When msg is a number, should parse successfully",
111 },
112 {
113 name: "valid args with object msg",
114 args: map[string]any{"msg": map[string]any{"key": "value"}},
115 expectParseError: false,
116 description: "When msg is an object, should parse successfully",
117 },
118 {
119 name: "valid args with array msg",
120 args: map[string]any{"msg": []string{"a", "b", "c"}},
121 expectParseError: false,
122 description: "When msg is an array, should parse successfully",
123 },
124 {
125 name: "missing msg",
126 args: map[string]any{},
127 expectParseError: true,
128 description: "When msg is missing, should return error",
129 },
130 }
131
132 for _, tc := range testcases {
133 t.Run(tc.name, func(t *testing.T) {
134 raw := createRawArgs(tc.args)
135 args := variable.Extension2Variables(raw)
136 v, ok := args["msg"]
137 if tc.expectParseError {
138 require.False(t, ok || v != nil, tc.description)
139 } else {
140 require.True(t, ok || v != nil, tc.description)
141 }
142 })
143 }
144}
145
146// TestDebugArgsTemplate tests template variable resolution in arguments.
147func TestDebugArgsTemplate(t *testing.T) {

Callers

nothing calls this directly

Calls 3

Extension2VariablesFunction · 0.92
createRawArgsFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected