gui: don't run fetch-gui on make

- Fail gracefully if `make fetch-gui` hasn't been run
- Return errors instead of panic or fatal errrors
- Don't run `make fetch-gui` on every make since we have it in the workflow
This commit is contained in:
Nick Craig-Wood
2026-04-11 15:27:05 +01:00
parent 5337b14739
commit a08b48adaa
7 changed files with 50 additions and 27 deletions
+15 -4
View File
@@ -94,8 +94,19 @@ func TestFreePort(t *testing.T) {
assert.Less(t, port, 65536)
}
// newTestHandler returns a guiHandler, or skips the test if the embedded
// GUI bundle is not present (i.e. `make fetch-gui` has not been run).
func newTestHandler(t *testing.T) http.Handler {
t.Helper()
h, err := guiHandler()
if err != nil {
t.Skipf("skipping: GUI dist not embedded (run `make fetch-gui`): %v", err)
}
return h
}
func TestHandlerServesIndexHTML(t *testing.T) {
h := guiHandler()
h := newTestHandler(t)
req := httptest.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, req)
@@ -109,7 +120,7 @@ func TestHandlerServesIndexHTML(t *testing.T) {
}
func TestHandlerServesStaticAssets(t *testing.T) {
h := guiHandler()
h := newTestHandler(t)
req := httptest.NewRequest("GET", "/icon.svg", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, req)
@@ -123,7 +134,7 @@ func TestHandlerServesStaticAssets(t *testing.T) {
}
func TestHandlerSPAFallback(t *testing.T) {
h := guiHandler()
h := newTestHandler(t)
// /login is not a real file — it should fall back to index.html
req := httptest.NewRequest("GET", "/login", nil)
@@ -140,7 +151,7 @@ func TestHandlerSPAFallback(t *testing.T) {
}
func TestHandlerSPAFallbackDeepPath(t *testing.T) {
h := guiHandler()
h := newTestHandler(t)
req := httptest.NewRequest("GET", "/some/deep/route", nil)
w := httptest.NewRecorder()