(t *testing.T)
| 307 | } |
| 308 | |
| 309 | func TestConfigPrecedence(t *testing.T) { |
| 310 | // Helper to build config with optional config file |
| 311 | buildConfig := func(t *testing.T, args []string, configFile string) (*config.Config, error) { |
| 312 | t.Helper() |
| 313 | if configFile != "" { |
| 314 | args = append([]string{"--config=" + configFile}, args...) |
| 315 | } |
| 316 | return controller.BuildConfigFromArgs(args) |
| 317 | } |
| 318 | |
| 319 | t.Run("defaults applied when nothing set", func(t *testing.T) { |
| 320 | cleanTestEnv(t) |
| 321 | |
| 322 | cfg, err := buildConfig(t, []string{}, "") |
| 323 | require.NoError(t, err) |
| 324 | |
| 325 | assert.Equal(t, 25, cfg.MaxInFlight) |
| 326 | assert.Equal(t, "default", cfg.Namespace) |
| 327 | assert.Equal(t, 10*time.Minute, cfg.JobTTL) |
| 328 | assert.Equal(t, 15*time.Minute, cfg.PodPendingTimeout) |
| 329 | assert.False(t, cfg.Debug) |
| 330 | }) |
| 331 | |
| 332 | t.Run("config file overrides defaults", func(t *testing.T) { |
| 333 | cleanTestEnv(t) |
| 334 | configFile := createTempConfigFile(t, ` |
| 335 | max-in-flight: 100 |
| 336 | namespace: from-file |
| 337 | debug: true |
| 338 | `) |
| 339 | |
| 340 | cfg, err := buildConfig(t, []string{}, configFile) |
| 341 | require.NoError(t, err) |
| 342 | |
| 343 | assert.Equal(t, 100, cfg.MaxInFlight) |
| 344 | assert.Equal(t, "from-file", cfg.Namespace) |
| 345 | assert.True(t, cfg.Debug) |
| 346 | }) |
| 347 | |
| 348 | t.Run("config file can set zero value", func(t *testing.T) { |
| 349 | cleanTestEnv(t) |
| 350 | configFile := createTempConfigFile(t, `max-in-flight: 0`) |
| 351 | |
| 352 | cfg, err := buildConfig(t, []string{}, configFile) |
| 353 | require.NoError(t, err) |
| 354 | |
| 355 | assert.Equal(t, 0, cfg.MaxInFlight) |
| 356 | }) |
| 357 | |
| 358 | t.Run("config file can set false", func(t *testing.T) { |
| 359 | cleanTestEnv(t) |
| 360 | configFile := createTempConfigFile(t, `debug: false`) |
| 361 | |
| 362 | cfg, err := buildConfig(t, []string{}, configFile) |
| 363 | require.NoError(t, err) |
| 364 | |
| 365 | assert.False(t, cfg.Debug) |
| 366 | }) |
nothing calls this directly
no test coverage detected