63 lines
2.1 KiB
Go
63 lines
2.1 KiB
Go
package adminui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestManifestEndpointDescribesPawSQLPlugin(t *testing.T) {
|
|
response := httptest.NewRecorder()
|
|
Handler(nil).ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/barkstack/ui/manifest.json", nil))
|
|
if response.Code != http.StatusOK {
|
|
t.Fatalf("status = %d", response.Code)
|
|
}
|
|
if got := response.Header().Get("Content-Type"); got != "application/json" {
|
|
t.Fatalf("content type = %q", got)
|
|
}
|
|
var got manifest
|
|
if err := json.Unmarshal(response.Body.Bytes(), &got); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.APIVersion != "barkstack.dev/ui/v1" || got.ID != "pawsql" || got.Entry != entryPath || got.Element != "barkstack-pawsql" {
|
|
t.Fatalf("manifest = %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestEmbeddedEntryAssetIsServedWithJavaScriptContentType(t *testing.T) {
|
|
response := httptest.NewRecorder()
|
|
Handler(nil).ServeHTTP(response, httptest.NewRequest(http.MethodGet, entryPath, nil))
|
|
if response.Code != http.StatusOK {
|
|
t.Fatalf("status = %d", response.Code)
|
|
}
|
|
if got := response.Header().Get("Content-Type"); !strings.Contains(got, "javascript") {
|
|
t.Fatalf("content type = %q", got)
|
|
}
|
|
if response.Body.Len() == 0 {
|
|
t.Fatal("embedded entry asset is empty")
|
|
}
|
|
}
|
|
|
|
func TestStatusEndpointReportsConfiguredRoutes(t *testing.T) {
|
|
routes := []RouteSummary{{Name: "reporting", Hostname: "reports.example.com", Managed: true}}
|
|
response := httptest.NewRecorder()
|
|
Handler(routes).ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/barkstack/ui/status.json", nil))
|
|
var got statusResponse
|
|
if err := json.Unmarshal(response.Body.Bytes(), &got); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.Status != "running" || len(got.Routes) != 1 || got.Routes[0] != routes[0] {
|
|
t.Fatalf("status response = %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestUnknownAssetReturnsNotFound(t *testing.T) {
|
|
response := httptest.NewRecorder()
|
|
Handler(nil).ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/barkstack/ui/assets/missing.js", nil))
|
|
if response.Code != http.StatusNotFound {
|
|
t.Fatalf("status = %d, want 404", response.Code)
|
|
}
|
|
}
|