This commit is contained in:
1 parent
624093773b
commit
568e516b1a
18 files changed
+912
-80
No files matched your search
@@ -0,0 +1,39 @@
|
||||
package scalar
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestScalarUIHandlesQueryAndMissingAssets(t *testing.T) {
|
||||
engine := gin.New()
|
||||
engine.GET("/docs/*any", New("Test <API>", "/docs").Handler())
|
||||
|
||||
t.Run("index with query", func(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
request := httptest.NewRequest(http.MethodGet, "/docs/index.html?cache=1", nil)
|
||||
engine.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, want %d", recorder.Code, http.StatusOK)
|
||||
}
|
||||
if contentType := recorder.Header().Get("Content-Type"); !strings.HasPrefix(contentType, "text/html") {
|
||||
t.Fatalf("Content-Type = %q, want HTML", contentType)
|
||||
}
|
||||
if strings.Contains(recorder.Body.String(), "Test <API>") {
|
||||
t.Fatal("document title was not HTML escaped")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("missing asset", func(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
request := httptest.NewRequest(http.MethodGet, "/docs/missing.js", nil)
|
||||
engine.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusNotFound {
|
||||
t.Fatalf("status = %d, want %d", recorder.Code, http.StatusNotFound)
|
||||
}
|
||||
})
|
||||
}
|
||||