88 "strings"
99 "testing"
1010
11+ "caldo/internal/assets"
1112 "caldo/internal/logging"
1213 "caldo/internal/view"
1314 "github.com/google/uuid"
@@ -254,7 +255,7 @@ func TestReverseProxyAuthMiddlewareAllowsHealthWithoutAuth(t *testing.T) {
254255func TestSetupGateMiddlewareRedirectsDisallowedRoutesWhenSetupIncomplete (t * testing.T ) {
255256 t .Parallel ()
256257
257- h := SetupGateMiddleware (NewSetupState (false ))(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
258+ h := SetupGateMiddleware (NewSetupState (false ), assets. Manifest { "app.css" : "app.8f3a1c2.css" , "htmx.min.js" : "htmx.5e741aa.min.js" } )(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
258259 w .WriteHeader (http .StatusNoContent )
259260 }))
260261
@@ -270,11 +271,10 @@ func TestSetupGateMiddlewareRedirectsDisallowedRoutesWhenSetupIncomplete(t *test
270271 }
271272}
272273
273-
274274func TestSetupGateMiddlewareAllowsStaticAssetsWhenSetupIncomplete (t * testing.T ) {
275275 t .Parallel ()
276276
277- h := SetupGateMiddleware (NewSetupState (false ))(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
277+ h := SetupGateMiddleware (NewSetupState (false ), assets. Manifest { "app.css" : "app.8f3a1c2.css" , "htmx.min.js" : "htmx.5e741aa.min.js" } )(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
278278 w .WriteHeader (http .StatusNoContent )
279279 }))
280280
@@ -286,10 +286,26 @@ func TestSetupGateMiddlewareAllowsStaticAssetsWhenSetupIncomplete(t *testing.T)
286286 t .Fatalf ("unexpected status code: got %d want %d" , rr .Code , http .StatusNoContent )
287287 }
288288}
289+ func TestSetupGateMiddlewareRedirectsUnknownStaticAssetWhenSetupIncomplete (t * testing.T ) {
290+ t .Parallel ()
291+
292+ h := SetupGateMiddleware (NewSetupState (false ), assets.Manifest {"app.css" : "app.8f3a1c2.css" })(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
293+ w .WriteHeader (http .StatusNoContent )
294+ }))
295+
296+ rr := httptest .NewRecorder ()
297+ req := httptest .NewRequest (http .MethodGet , "/static/unknown.js" , nil )
298+ h .ServeHTTP (rr , req )
299+
300+ if rr .Code != http .StatusFound {
301+ t .Fatalf ("unexpected status code: got %d want %d" , rr .Code , http .StatusFound )
302+ }
303+ }
304+
289305func TestSetupGateMiddlewareAllowsSetupRoutesWhenSetupIncomplete (t * testing.T ) {
290306 t .Parallel ()
291307
292- h := SetupGateMiddleware (NewSetupState (false ))(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
308+ h := SetupGateMiddleware (NewSetupState (false ), assets. Manifest { "app.css" : "app.8f3a1c2.css" , "htmx.min.js" : "htmx.5e741aa.min.js" } )(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
293309 w .WriteHeader (http .StatusNoContent )
294310 }))
295311
@@ -305,7 +321,7 @@ func TestSetupGateMiddlewareAllowsSetupRoutesWhenSetupIncomplete(t *testing.T) {
305321func TestSetupGateMiddlewareAllowsAllRoutesWhenSetupComplete (t * testing.T ) {
306322 t .Parallel ()
307323
308- h := SetupGateMiddleware (NewSetupState (true ))(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
324+ h := SetupGateMiddleware (NewSetupState (true ), assets. Manifest { "app.css" : "app.8f3a1c2.css" } )(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
309325 w .WriteHeader (http .StatusNoContent )
310326 }))
311327
@@ -322,7 +338,7 @@ func TestSetupGateMiddlewareReflectsRuntimeCompletionState(t *testing.T) {
322338 t .Parallel ()
323339
324340 state := NewSetupState (false )
325- h := SetupGateMiddleware (state )(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
341+ h := SetupGateMiddleware (state , assets. Manifest { "app.css" : "app.8f3a1c2.css" } )(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
326342 w .WriteHeader (http .StatusNoContent )
327343 }))
328344
0 commit comments