Skip to content

Commit cf4fde7

Browse files
authored
Fix duplicate test functions in config validation tests (#4156)
Three test functions were declared in both `validation_otel_test.go` and `validation_gateway_coverage_test.go`, causing `go vet` to fail with redeclaration errors: - `TestValidateTrustedBots` - `TestValidateGatewayConfig_OpenTelemetry` - `TestValidateGatewayConfig_TrustedBots` The `validation_gateway_coverage_test.go` versions are more comprehensive (extra edge cases like tab-only entries, invalid spanId, service name), so this PR removes the duplicates from `validation_otel_test.go`. **Verified:** `make agent-finished` passes (format, build, lint, all tests).
2 parents 189246a + 15f37a3 commit cf4fde7

File tree

1 file changed

+3
-213
lines changed

1 file changed

+3
-213
lines changed

internal/config/validation_otel_test.go

Lines changed: 3 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -264,75 +264,7 @@ func TestValidateOpenTelemetryConfig(t *testing.T) {
264264
}
265265
}
266266

267-
// TestValidateTrustedBots tests the trustedBots list validation (spec §4.1.3.4).
268-
func TestValidateTrustedBots(t *testing.T) {
269-
tests := []struct {
270-
name string
271-
bots []string
272-
wantErr bool
273-
errContains string
274-
}{
275-
{
276-
name: "nil bots is valid",
277-
bots: nil,
278-
wantErr: false,
279-
},
280-
{
281-
name: "empty slice is rejected",
282-
bots: []string{},
283-
wantErr: true,
284-
errContains: "non-empty",
285-
},
286-
{
287-
name: "single valid bot name",
288-
bots: []string{"github-actions[bot]"},
289-
wantErr: false,
290-
},
291-
{
292-
name: "multiple valid bot names",
293-
bots: []string{"dependabot[bot]", "github-actions[bot]", "renovate[bot]"},
294-
wantErr: false,
295-
},
296-
{
297-
name: "empty string bot is rejected",
298-
bots: []string{"valid-bot", ""},
299-
wantErr: true,
300-
errContains: "non-empty string",
301-
},
302-
{
303-
name: "whitespace-only bot is rejected",
304-
bots: []string{" "},
305-
wantErr: true,
306-
errContains: "non-empty string",
307-
},
308-
{
309-
name: "empty string at index 0 is rejected",
310-
bots: []string{""},
311-
wantErr: true,
312-
errContains: "trusted_bots[0]",
313-
},
314-
{
315-
name: "empty string at index 1 is rejected with index in message",
316-
bots: []string{"valid-bot", ""},
317-
wantErr: true,
318-
errContains: "trusted_bots[1]",
319-
},
320-
}
321-
322-
for _, tt := range tests {
323-
t.Run(tt.name, func(t *testing.T) {
324-
err := validateTrustedBots(tt.bots)
325-
if tt.wantErr {
326-
require.Error(t, err)
327-
if tt.errContains != "" {
328-
assert.ErrorContains(t, err, tt.errContains)
329-
}
330-
} else {
331-
assert.NoError(t, err)
332-
}
333-
})
334-
}
335-
}
267+
// TestValidateTrustedBots is in validation_gateway_coverage_test.go.
336268

337269
// TestValidateCustomSchemas tests custom schema type name and URL validation.
338270
func TestValidateCustomSchemas(t *testing.T) {
@@ -539,147 +471,5 @@ func TestValidateGuardPolicies(t *testing.T) {
539471
}
540472
}
541473

542-
// TestValidateGatewayConfig_OpenTelemetry adds OTel-specific cases to validateGatewayConfig
543-
// coverage that are not exercised by the main TestValidateGatewayConfig table.
544-
func TestValidateGatewayConfig_OpenTelemetry(t *testing.T) {
545-
validTraceID := "4bf92f3577b34da6a3ce929d0e0e4736"
546-
validSpanID := "00f067aa0ba902b7"
547-
548-
tests := []struct {
549-
name string
550-
gateway *StdinGatewayConfig
551-
wantErr bool
552-
errContains string
553-
}{
554-
{
555-
name: "valid opentelemetry section passes",
556-
gateway: &StdinGatewayConfig{
557-
OpenTelemetry: &StdinOpenTelemetryConfig{
558-
Endpoint: "https://otel.example.com",
559-
},
560-
},
561-
wantErr: false,
562-
},
563-
{
564-
name: "opentelemetry with traceId and spanId passes",
565-
gateway: &StdinGatewayConfig{
566-
OpenTelemetry: &StdinOpenTelemetryConfig{
567-
Endpoint: "https://otel.example.com",
568-
TraceID: validTraceID,
569-
SpanID: validSpanID,
570-
},
571-
},
572-
wantErr: false,
573-
},
574-
{
575-
name: "opentelemetry missing endpoint fails",
576-
gateway: &StdinGatewayConfig{
577-
OpenTelemetry: &StdinOpenTelemetryConfig{},
578-
},
579-
wantErr: true,
580-
errContains: "endpoint",
581-
},
582-
{
583-
name: "opentelemetry with http endpoint fails",
584-
gateway: &StdinGatewayConfig{
585-
OpenTelemetry: &StdinOpenTelemetryConfig{
586-
Endpoint: "http://otel.example.com",
587-
},
588-
},
589-
wantErr: true,
590-
errContains: "HTTPS",
591-
},
592-
{
593-
name: "opentelemetry with invalid traceId fails",
594-
gateway: &StdinGatewayConfig{
595-
OpenTelemetry: &StdinOpenTelemetryConfig{
596-
Endpoint: "https://otel.example.com",
597-
TraceID: "invalid",
598-
},
599-
},
600-
wantErr: true,
601-
errContains: "traceId",
602-
},
603-
{
604-
name: "opentelemetry with all-zero traceId fails",
605-
gateway: &StdinGatewayConfig{
606-
OpenTelemetry: &StdinOpenTelemetryConfig{
607-
Endpoint: "https://otel.example.com",
608-
TraceID: "00000000000000000000000000000000",
609-
},
610-
},
611-
wantErr: true,
612-
errContains: "traceId",
613-
},
614-
}
615-
616-
for _, tt := range tests {
617-
t.Run(tt.name, func(t *testing.T) {
618-
err := validateGatewayConfig(tt.gateway)
619-
if tt.wantErr {
620-
require.Error(t, err)
621-
if tt.errContains != "" {
622-
assert.ErrorContains(t, err, tt.errContains)
623-
}
624-
} else {
625-
assert.NoError(t, err)
626-
}
627-
})
628-
}
629-
}
630-
631-
// TestValidateGatewayConfig_TrustedBots adds trustedBots-specific cases to validateGatewayConfig
632-
// coverage that are not exercised by the main TestValidateGatewayConfig table.
633-
func TestValidateGatewayConfig_TrustedBots(t *testing.T) {
634-
tests := []struct {
635-
name string
636-
gateway *StdinGatewayConfig
637-
wantErr bool
638-
errContains string
639-
}{
640-
{
641-
name: "valid trustedBots list passes",
642-
gateway: &StdinGatewayConfig{
643-
TrustedBots: []string{"github-actions[bot]", "dependabot[bot]"},
644-
},
645-
wantErr: false,
646-
},
647-
{
648-
name: "empty trustedBots list is rejected",
649-
gateway: &StdinGatewayConfig{
650-
TrustedBots: []string{},
651-
},
652-
wantErr: true,
653-
errContains: "non-empty",
654-
},
655-
{
656-
name: "trustedBots with empty string entry is rejected",
657-
gateway: &StdinGatewayConfig{
658-
TrustedBots: []string{"valid-bot", ""},
659-
},
660-
wantErr: true,
661-
errContains: "non-empty string",
662-
},
663-
{
664-
name: "nil trustedBots (not set) is valid",
665-
gateway: &StdinGatewayConfig{
666-
TrustedBots: nil,
667-
},
668-
wantErr: false,
669-
},
670-
}
671-
672-
for _, tt := range tests {
673-
t.Run(tt.name, func(t *testing.T) {
674-
err := validateGatewayConfig(tt.gateway)
675-
if tt.wantErr {
676-
require.Error(t, err)
677-
if tt.errContains != "" {
678-
assert.ErrorContains(t, err, tt.errContains)
679-
}
680-
} else {
681-
assert.NoError(t, err)
682-
}
683-
})
684-
}
685-
}
474+
// TestValidateGatewayConfig_OpenTelemetry is in validation_gateway_coverage_test.go.
475+
// TestValidateGatewayConfig_TrustedBots is in validation_gateway_coverage_test.go.

0 commit comments

Comments
 (0)