fixed benchmark
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-04-20 16:24:48 +10:00
parent 8ccf5a7009
commit aa0d8099c7
5 changed files with 156 additions and 8 deletions
+50
View File
@@ -1,9 +1,11 @@
package router
import (
"encoding/json"
"net/http"
"net/http/httptest"
"regexp"
"reflect"
"strings"
"testing"
"vctp/version"
@@ -112,3 +114,51 @@ func TestStaticResourcesAreCacheableInReleaseMode(t *testing.T) {
})
}
}
func TestSwaggerJSONDefaultsToHTTPSWhenTLSEnabled(t *testing.T) {
cfg := testRouterSettings(t, false)
cfg.Values.Settings.BindDisableTLS = false
app := testRouter(t, cfg)
req := httptest.NewRequest(http.MethodGet, "/swagger.json", nil)
rr := httptest.NewRecorder()
app.ServeHTTP(rr, req)
if rr.Code != http.StatusOK {
t.Fatalf("expected status %d, got %d", http.StatusOK, rr.Code)
}
var spec struct {
Schemes []string `json:"schemes"`
}
if err := json.Unmarshal(rr.Body.Bytes(), &spec); err != nil {
t.Fatalf("failed to decode swagger spec: %v", err)
}
if !reflect.DeepEqual(spec.Schemes, []string{"https"}) {
t.Fatalf("unexpected schemes: got %v want %v", spec.Schemes, []string{"https"})
}
}
func TestSwaggerJSONDefaultsToHTTPWhenTLSDisabled(t *testing.T) {
cfg := testRouterSettings(t, false)
cfg.Values.Settings.BindDisableTLS = true
app := testRouter(t, cfg)
req := httptest.NewRequest(http.MethodGet, "/swagger.json", nil)
rr := httptest.NewRecorder()
app.ServeHTTP(rr, req)
if rr.Code != http.StatusOK {
t.Fatalf("expected status %d, got %d", http.StatusOK, rr.Code)
}
var spec struct {
Schemes []string `json:"schemes"`
}
if err := json.Unmarshal(rr.Body.Bytes(), &spec); err != nil {
t.Fatalf("failed to decode swagger spec: %v", err)
}
if !reflect.DeepEqual(spec.Schemes, []string{"http"}) {
t.Fatalf("unexpected schemes: got %v want %v", spec.Schemes, []string{"http"})
}
}