aboutsummaryrefslogtreecommitdiff
path: root/internal/httputil/routing_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/httputil/routing_test.go')
-rw-r--r--internal/httputil/routing_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/httputil/routing_test.go b/internal/httputil/routing_test.go
new file mode 100644
index 00000000..21e2bf48
--- /dev/null
+++ b/internal/httputil/routing_test.go
@@ -0,0 +1,38 @@
+package httputil
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "path/filepath"
+ "testing"
+)
+
+func TestRoutersError(t *testing.T) {
+ r := NewRouters()
+
+ // not found test
+ rec := httptest.NewRecorder()
+ req := httptest.NewRequest(http.MethodGet, filepath.Join(PublicFederationPathPrefix, "doesnotexist"), nil)
+ r.Federation.ServeHTTP(rec, req)
+ if rec.Code != http.StatusNotFound {
+ t.Fatalf("unexpected status code: %d - %s", rec.Code, rec.Body.String())
+ }
+ if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
+ t.Fatalf("unexpected content-type: %s", ct)
+ }
+
+ // not allowed test
+ r.DendriteAdmin.
+ Handle("/test", http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {})).
+ Methods(http.MethodPost)
+
+ rec = httptest.NewRecorder()
+ req = httptest.NewRequest(http.MethodGet, filepath.Join(DendriteAdminPathPrefix, "test"), nil)
+ r.DendriteAdmin.ServeHTTP(rec, req)
+ if rec.Code != http.StatusMethodNotAllowed {
+ t.Fatalf("unexpected status code: %d - %s", rec.Code, rec.Body.String())
+ }
+ if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
+ t.Fatalf("unexpected content-type: %s", ct)
+ }
+}