(t *testing.T)
| 80 | } |
| 81 | |
| 82 | func TestRetryConfigurationFlags(t *testing.T) { |
| 83 | tests := []struct { |
| 84 | name string |
| 85 | args []string |
| 86 | expectedConfig http.RetryConfig |
| 87 | }{ |
| 88 | { |
| 89 | name: "default retry configuration", |
| 90 | args: []string{}, |
| 91 | expectedConfig: http.RetryConfig{ |
| 92 | MaxWait: 3 * time.Second, |
| 93 | MaxRetry: 3, |
| 94 | Duration: 1 * time.Second, |
| 95 | Factor: 2.0, |
| 96 | Jitter: 0.1, |
| 97 | }, |
| 98 | }, |
| 99 | { |
| 100 | name: "custom retry configuration", |
| 101 | args: []string{ |
| 102 | "--retry-max-wait", "2s", |
| 103 | "--retry-max-retry", "5", |
| 104 | "--retry-duration", "500ms", |
| 105 | "--retry-factor", "1.5", |
| 106 | "--retry-jitter", "0.2", |
| 107 | }, |
| 108 | expectedConfig: http.RetryConfig{ |
| 109 | MaxWait: 2 * time.Second, |
| 110 | MaxRetry: 5, |
| 111 | Duration: 500 * time.Millisecond, |
| 112 | Factor: 1.5, |
| 113 | Jitter: 0.2, |
| 114 | }, |
| 115 | }, |
| 116 | } |
| 117 | |
| 118 | for _, tt := range tests { |
| 119 | t.Run(tt.name, func(t *testing.T) { |
| 120 | // Reset to default values |
| 121 | retryMaxWait = 3 * time.Second |
| 122 | retryMaxRetry = 3 |
| 123 | retryDuration = 1 * time.Second |
| 124 | retryFactor = 2.0 |
| 125 | retryJitter = 0.1 |
| 126 | |
| 127 | cmd := NewRootCmd() |
| 128 | if len(tt.args) > 0 { |
| 129 | cmd.SetArgs(append(tt.args, "version")) |
| 130 | } else { |
| 131 | cmd.SetArgs([]string{"version"}) |
| 132 | } |
| 133 | |
| 134 | // Execute the command to trigger flag parsing and configuration |
| 135 | err := cmd.Execute() |
| 136 | assert.NoError(t, err) |
| 137 | |
| 138 | // Verify the configuration was applied by checking the actual values |
| 139 | // The configuration is applied in PersistentPreRun, so we need to check |
nothing calls this directly
no test coverage detected