package openapi import ( "net/http" "net/http/httptest" "strings" "testing" "github.com/gorilla/mux" ) func TestUIHandler_SwaggerUI(t *testing.T) { config := UIConfig{ UIType: SwaggerUI, SpecURL: "/openapi", Title: "Test API Docs", } handler := UIHandler(config) req := httptest.NewRequest("GET", "/docs", nil) w := httptest.NewRecorder() handler(w, req) resp := w.Result() if resp.StatusCode != http.StatusOK { t.Errorf("Expected status 200, got %d", resp.StatusCode) } body := w.Body.String() // Check for Swagger UI specific content if !strings.Contains(body, "swagger-ui") { t.Error("Expected Swagger UI content") } if !strings.Contains(body, "SwaggerUIBundle") { t.Error("Expected SwaggerUIBundle script") } if !strings.Contains(body, config.Title) { t.Errorf("Expected title '%s' in HTML", config.Title) } if !strings.Contains(body, config.SpecURL) { t.Errorf("Expected spec URL '%s' in HTML", config.SpecURL) } if !strings.Contains(body, "swagger-ui-dist") { t.Error("Expected Swagger UI CDN link") } } func TestUIHandler_RapiDoc(t *testing.T) { config := UIConfig{ UIType: RapiDoc, SpecURL: "/api/spec", Title: "RapiDoc Test", } handler := UIHandler(config) req := httptest.NewRequest("GET", "/docs", nil) w := httptest.NewRecorder() handler(w, req) resp := w.Result() if resp.StatusCode != http.StatusOK { t.Errorf("Expected status 200, got %d", resp.StatusCode) } body := w.Body.String() // Check for RapiDoc specific content if !strings.Contains(body, "rapi-doc") { t.Error("Expected rapi-doc element") } if !strings.Contains(body, "rapidoc-min.js") { t.Error("Expected RapiDoc script") } if !strings.Contains(body, config.Title) { t.Errorf("Expected title '%s' in HTML", config.Title) } if !strings.Contains(body, config.SpecURL) { t.Errorf("Expected spec URL '%s' in HTML", config.SpecURL) } } func TestUIHandler_Redoc(t *testing.T) { config := UIConfig{ UIType: Redoc, SpecURL: "/spec.json", Title: "Redoc Test", } handler := UIHandler(config) req := httptest.NewRequest("GET", "/docs", nil) w := httptest.NewRecorder() handler(w, req) resp := w.Result() if resp.StatusCode != http.StatusOK { t.Errorf("Expected status 200, got %d", resp.StatusCode) } body := w.Body.String() // Check for Redoc specific content if !strings.Contains(body, "