summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-04-15 17:54:43 -0600
committermo khan <mo@mokhan.ca>2025-04-15 17:54:43 -0600
commitb7ff80b7be532f4bb64c1daf8cef3462f9938362 (patch)
tree3d88661d72339be3fc81425b6d4397bcc8e8c603 /app/controllers
parent655fb6c4cc180dfcbc13c1b85e0fbf47019caec0 (diff)
feat: connect a blank dashboard controller
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/dashboard/controller.go18
-rw-r--r--app/controllers/dashboard/controller_test.go29
2 files changed, 47 insertions, 0 deletions
diff --git a/app/controllers/dashboard/controller.go b/app/controllers/dashboard/controller.go
new file mode 100644
index 0000000..060dbfa
--- /dev/null
+++ b/app/controllers/dashboard/controller.go
@@ -0,0 +1,18 @@
+package dashboard
+
+import "net/http"
+
+type Controller struct {
+}
+
+func New() *Controller {
+ return &Controller{}
+}
+
+func (c *Controller) MountTo(mux *http.ServeMux) {
+ mux.HandleFunc("GET /dashboard", c.Show)
+}
+
+func (c *Controller) Show(w http.ResponseWriter, r *http.Request) {
+ http.Redirect(w, r, "/", http.StatusFound)
+}
diff --git a/app/controllers/dashboard/controller_test.go b/app/controllers/dashboard/controller_test.go
new file mode 100644
index 0000000..0bfb3d6
--- /dev/null
+++ b/app/controllers/dashboard/controller_test.go
@@ -0,0 +1,29 @@
+package dashboard
+
+import (
+ "net/http"
+ "testing"
+
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test"
+ "gotest.tools/v3/assert"
+)
+
+func TestController(t *testing.T) {
+ mux := http.NewServeMux()
+ controller := New()
+ controller.MountTo(mux)
+
+ t.Run("GET /dashboard", func(t *testing.T) {
+ t.Run("when unauthenticated", func(t *testing.T) {
+ t.Run("redirects to the home page", func(t *testing.T) {
+ r, w := test.RequestResponse("GET", "/dashboard")
+
+ mux.ServeHTTP(w, r)
+
+ assert.Equal(t, http.StatusFound, w.Code)
+ location := w.HeaderMap.Get("Location")
+ assert.Equal(t, "/", location)
+ })
+ })
+ })
+}