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

Function TestDebugArgsModule

pkg/modules/debug/debug_test.go:55–90  ·  view source on GitHub ↗

TestDebugArgsModule tests module execution - requires actual variable

(t *testing.T)

Source from the content-addressed store, hash-verified

53
54// TestDebugArgsModule tests module execution - requires actual variable
55func TestDebugArgsModule(t *testing.T) {
56 testcases := []struct {
57 name string
58 opt internal.ExecOptions
59 expectStdout string
60 expectError bool
61 description string
62 }{
63 {
64 name: "missing both msg and var",
65 opt: internal.ExecOptions{
66 Host: "node1",
67 Variable: NewTestVariable([]string{"node1"}, nil),
68 Args: createRawArgs(map[string]any{}),
69 },
70 expectStdout: internal.StdoutFailed,
71 expectError: true,
72 description: "When both msg and var are missing, should return failed",
73 },
74 }
75
76 for _, tc := range testcases {
77 t.Run(tc.name, func(t *testing.T) {
78 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
79 defer cancel()
80 stdout, stderr, err := ModuleDebug(ctx, tc.opt)
81 require.Equal(t, tc.expectStdout, stdout, tc.description)
82 if tc.expectError {
83 require.Error(t, err, tc.description)
84 require.NotEmpty(t, stderr, tc.description)
85 } else {
86 require.NoError(t, err, tc.description)
87 }
88 })
89 }
90}
91
92// TestDebugArgsParse tests argument parsing edge cases.
93func TestDebugArgsParse(t *testing.T) {

Callers

nothing calls this directly

Calls 5

ModuleDebugFunction · 0.85
ErrorMethod · 0.80
NewTestVariableFunction · 0.70
createRawArgsFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected