MCPcopy Create free account
hub / github.com/conforma/cli / TestGlobalTimeout

Function TestGlobalTimeout

cmd/root/root_cmd_test.go:28–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestGlobalTimeout(t *testing.T) {
29 tests := []struct {
30 name string
31 timeoutFlag string
32 expectedValue time.Duration
33 expectedString string
34 }{
35 {
36 name: "default timeout",
37 timeoutFlag: "",
38 expectedValue: 5 * time.Minute,
39 expectedString: "5m0s",
40 },
41 {
42 name: "custom timeout in hours",
43 timeoutFlag: "100h",
44 expectedValue: 100 * time.Hour,
45 expectedString: "100h0m0s",
46 },
47 {
48 name: "custom timeout in minutes",
49 timeoutFlag: "30m",
50 expectedValue: 30 * time.Minute,
51 expectedString: "30m0s",
52 },
53 {
54 name: "zero timeout",
55 timeoutFlag: "0",
56 expectedValue: 0,
57 expectedString: "0s",
58 },
59 }
60
61 for _, tt := range tests {
62 t.Run(tt.name, func(t *testing.T) {
63 // Reset globalTimeout to default value before each test
64 globalTimeout = 5 * time.Minute
65
66 cmd := NewRootCmd()
67 if tt.timeoutFlag != "" {
68 cmd.SetArgs([]string{"--timeout", tt.timeoutFlag})
69 }
70
71 // Execute the command to trigger flag parsing
72 err := cmd.Execute()
73 assert.NoError(t, err)
74
75 // Verify the timeout value
76 assert.Equal(t, tt.expectedValue, globalTimeout)
77 assert.Equal(t, tt.expectedString, globalTimeout.String())
78 })
79 }
80}
81
82func TestRetryConfigurationFlags(t *testing.T) {
83 tests := []struct {

Callers

nothing calls this directly

Calls 3

NewRootCmdFunction · 0.85
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected