test: make type assertions stricter and replaced silent returns with explicit errors

This commit is contained in:
2026-01-09 18:44:18 +01:00
parent 34fbc2f8b1
commit 56770955d4

View File

@@ -82,10 +82,13 @@ func TestE2E_SwaggerDocumentation(t *testing.T) {
return return
} }
paths, ok := swaggerDoc["paths"].(map[string]any) pathsRaw, exists := swaggerDoc["paths"]
if !exists {
t.Fatalf("Swagger doc missing 'paths' section")
}
paths, ok := pathsRaw.(map[string]any)
if !ok { if !ok {
t.Error("Paths section is not a map") t.Fatalf("Swagger doc 'paths' section has invalid type: expected map[string]any, got %T", pathsRaw)
return
} }
requiredPaths := []string{ requiredPaths := []string{
@@ -113,11 +116,29 @@ func TestE2E_SwaggerDocumentation(t *testing.T) {
return return
} }
definitions, ok := swaggerDoc["definitions"].(map[string]any) var definitions map[string]any
var ok bool
definitionsRaw, exists := swaggerDoc["definitions"]
if exists {
definitions, ok = definitionsRaw.(map[string]any)
if !ok { if !ok {
definitions, ok = swaggerDoc["components"].(map[string]any) t.Fatalf("Swagger doc 'definitions' section has invalid type: expected map[string]any, got %T", definitionsRaw)
if ok { }
definitions, _ = definitions["schemas"].(map[string]any) } else {
componentsRaw, exists := swaggerDoc["components"]
if exists {
components, ok := componentsRaw.(map[string]any)
if !ok {
t.Fatalf("Swagger doc 'components' section has invalid type: expected map[string]any, got %T", componentsRaw)
}
schemasRaw, exists := components["schemas"]
if exists {
definitions, ok = schemasRaw.(map[string]any)
if !ok {
t.Fatalf("Swagger doc 'components.schemas' section has invalid type: expected map[string]any, got %T", schemasRaw)
}
}
} }
} }
@@ -159,9 +180,13 @@ func TestE2E_APIEndpointDocumentation(t *testing.T) {
return return
} }
paths, ok := swaggerDoc["paths"].(map[string]any) pathsRaw, exists := swaggerDoc["paths"]
if !exists {
t.Fatalf("Swagger doc missing 'paths' section")
}
paths, ok := pathsRaw.(map[string]any)
if !ok { if !ok {
return t.Fatalf("Swagger doc 'paths' section has invalid type: expected map[string]any, got %T", pathsRaw)
} }
apiPath, ok := paths["/api"].(map[string]any) apiPath, ok := paths["/api"].(map[string]any)
@@ -187,9 +212,13 @@ func TestE2E_APIEndpointDocumentation(t *testing.T) {
return return
} }
paths, ok := swaggerDoc["paths"].(map[string]any) pathsRaw, exists := swaggerDoc["paths"]
if !exists {
t.Fatalf("Swagger doc missing 'paths' section")
}
paths, ok := pathsRaw.(map[string]any)
if !ok { if !ok {
return t.Fatalf("Swagger doc 'paths' section has invalid type: expected map[string]any, got %T", pathsRaw)
} }
authEndpoints := []string{ authEndpoints := []string{