Skip to content

Commit 9e26167

Browse files
committed
Fix API config tests to use direct API validation
- Change tests to use cfg.API.Config.Validate() instead of full cfg.Validate() - Prevents Java config validation errors from interfering with API tests - Update error message assertions to match actual API validation messages - All tests now pass correctly Fixes test failures after PR minekube#563 merge.
1 parent 21d747c commit 9e26167

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

pkg/gate/config/api_config_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ api:
2323
assert.True(t, cfg.API.Enabled, "API should be enabled")
2424
assert.Equal(t, "0.0.0.0:3000", cfg.API.Config.Bind, "API bind should be parsed correctly")
2525

26-
// Test validation
27-
warns, errs := cfg.Validate()
28-
assert.Empty(t, errs, "Should have no validation errors")
29-
assert.Empty(t, warns, "Should have no validation warnings")
26+
// Test API config validation directly (not full config validation)
27+
warns, errs := cfg.API.Config.Validate()
28+
assert.Empty(t, errs, "Should have no API validation errors")
29+
assert.Empty(t, warns, "Should have no API validation warnings")
3030
}
3131

3232
func TestAPIConfigNested(t *testing.T) {
@@ -46,9 +46,9 @@ api:
4646
assert.Equal(t, "", cfg.API.Config.Bind, "API bind should be empty (nested structure not supported with inline)")
4747

4848
// Test validation (should fail because bind is empty)
49-
_, errs := cfg.Validate()
49+
_, errs := cfg.API.Config.Validate()
5050
assert.NotEmpty(t, errs, "Should have validation errors because nested config is ignored")
51-
assert.Contains(t, errs[0].Error(), "api:", "Error should mention API validation")
51+
assert.Contains(t, errs[0].Error(), "bind address must not be empty", "Error should mention empty bind")
5252
}
5353

5454
func TestAPIConfigDisabled(t *testing.T) {
@@ -67,9 +67,9 @@ api:
6767
assert.Equal(t, "localhost:8080", cfg.API.Config.Bind, "API bind should still be parsed")
6868

6969
// Test validation (should pass even when disabled)
70-
warns, errs := cfg.Validate()
71-
assert.Empty(t, errs, "Should have no validation errors for disabled API")
72-
assert.Empty(t, warns, "Should have no validation warnings for disabled API")
70+
warns, errs := cfg.API.Config.Validate()
71+
assert.Empty(t, errs, "Should have no API validation errors for disabled API")
72+
assert.Empty(t, warns, "Should have no API validation warnings for disabled API")
7373
}
7474

7575
func TestAPIConfigInvalidBind(t *testing.T) {
@@ -88,9 +88,9 @@ api:
8888
assert.Equal(t, "invalid-address", cfg.API.Config.Bind, "Invalid bind should be parsed")
8989

9090
// Test validation (should fail)
91-
_, errs := cfg.Validate()
91+
_, errs := cfg.API.Config.Validate()
9292
assert.NotEmpty(t, errs, "Should have validation errors for invalid bind")
93-
assert.Contains(t, errs[0].Error(), "api:", "Error should mention API validation")
93+
assert.Contains(t, errs[0].Error(), "invalid bind", "Error should mention invalid bind")
9494
}
9595

9696
func TestAPIConfigEmptyBind(t *testing.T) {
@@ -109,20 +109,20 @@ api:
109109
assert.Equal(t, "", cfg.API.Config.Bind, "Empty bind should be parsed")
110110

111111
// Test validation (should fail)
112-
_, errs := cfg.Validate()
112+
_, errs := cfg.API.Config.Validate()
113113
assert.NotEmpty(t, errs, "Should have validation errors for empty bind")
114-
assert.Contains(t, errs[0].Error(), "api:", "Error should mention API validation")
114+
assert.Contains(t, errs[0].Error(), "bind address must not be empty", "Error should mention empty bind")
115115
}
116116

117117
func TestAPIConfigDefaultSecurity(t *testing.T) {
118118
// Test that default config uses localhost (not 0.0.0.0) for security
119119
cfg := DefaultConfig
120-
120+
121121
assert.False(t, cfg.API.Enabled, "API should be disabled by default")
122122
assert.Equal(t, "localhost:8080", cfg.API.Config.Bind, "Default API bind should use localhost for security")
123-
123+
124124
// Test that API config itself is valid (even though full config may have other warnings)
125125
apiWarns, apiErrs := cfg.API.Config.Validate()
126126
assert.Empty(t, apiErrs, "Default API config should have no validation errors")
127127
assert.Empty(t, apiWarns, "Default API config should have no validation warnings")
128-
}
128+
}

0 commit comments

Comments
 (0)