diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-21 12:00:16 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-21 12:00:16 -0600 |
| commit | 2854b695a0df016ef1a9c67303c15911b0ed4b72 (patch) | |
| tree | 80d492014012b4b6d4e8e99fc30f0ee8afc43e51 /app | |
| parent | 49a8ef7441ac9355a7a8e4890f0a1c9004571f37 (diff) | |
refactor: provide the root dir as a parameter
Diffstat (limited to 'app')
| -rw-r--r-- | app/app.go | 6 | ||||
| -rw-r--r-- | app/app_test.go | 6 |
2 files changed, 8 insertions, 4 deletions
@@ -2,6 +2,7 @@ package app import ( "net/http" + "path/filepath" "github.com/rs/zerolog" "github.com/xlgmokha/x/pkg/ioc" @@ -15,7 +16,7 @@ import ( "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web/middleware" ) -func New() http.Handler { +func New(rootDir string) http.Handler { mux := ioc.MustResolve[*http.ServeMux](ioc.Default) mountable := []web.Mountable{ @@ -28,7 +29,8 @@ func New() http.Handler { m.MountTo(mux) } - mux.Handle("GET /", http.FileServer(http.Dir("public"))) + dir := http.Dir(filepath.Join(rootDir, "public")) + mux.Handle("GET /", http.FileServer(dir)) logger := ioc.MustResolve[*zerolog.Logger](ioc.Default) oidc := ioc.MustResolve[*oidc.OpenID](ioc.Default) diff --git a/app/app_test.go b/app/app_test.go index 27f5f9c..bf706bc 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -3,18 +3,20 @@ package app import ( "net/http" "net/http/httptest" + "os" "testing" "github.com/stretchr/testify/assert" + "github.com/xlgmokha/x/pkg/x" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" ) func TestApp(t *testing.T) { t.Run("New", func(t *testing.T) { - server := New() + wd := x.Must(os.Getwd()) + server := New(wd + "/..") t.Run("GET /index.html", func(t *testing.T) { - t.Skip() response := httptest.NewRecorder() server.ServeHTTP(response, test.Request("GET", "/")) |
