diff --git a/pkgs/router-webui/gitupdate_test.go b/pkgs/router-webui/gitupdate_test.go index d2d5358..3af9dd4 100644 --- a/pkgs/router-webui/gitupdate_test.go +++ b/pkgs/router-webui/gitupdate_test.go @@ -11,6 +11,43 @@ import ( const testRepository = "https://git.example.org/me/nixos-router" +// While the look at the repository runs, the page is covered by the same kind +// of box as an update, and keeps asking for itself until it is done. +func TestLookingAtTheRepositoryShowsABox(t *testing.T) { + a, sys := newTestApp(t) + sys.RepositoryFile = filepath.Join(t.TempDir(), "router-update-repository") + os.WriteFile(sys.RepositoryFile, []byte(testRepository), 0o644) + a.sys = sys + orig := unitProperty + state := "inactive" + unitProperty = func(unit, prop string) string { + if unit == gitCheckUnit && prop == "ActiveState" { + return state + } + return "" + } + defer func() { unitProperty = orig }() + h := a.routes() + cookie := login(t, h) + + body := do(h, "GET", "/update", nil, cookie).Body.String() + if strings.Contains(body, "Looking at the repository…") || strings.Contains(body, "data-live") { + t.Fatalf("a box with nothing running:\n%s", body) + } + if !strings.Contains(body, "Look for a newer release") { + t.Fatalf("no button:\n%s", body) + } + + state = "activating" + body = do(h, "GET", "/update", nil, cookie).Body.String() + if !strings.Contains(body, "Looking at the repository…") || !strings.Contains(body, `class="upload-overlay"`) || !strings.Contains(body, "data-live") { + t.Fatalf("no box while looking:\n%s", body) + } + if !strings.Contains(body, testRepository) { + t.Fatalf("the box does not say where it looks:\n%s", body) + } +} + func TestUpdatesFromGit(t *testing.T) { a, sys := newTestApp(t) dir := t.TempDir() diff --git a/pkgs/router-webui/system.go b/pkgs/router-webui/system.go index 614076f..83c49d6 100644 --- a/pkgs/router-webui/system.go +++ b/pkgs/router-webui/system.go @@ -49,7 +49,8 @@ func command(name string, args ...string) (string, error) { return strings.TrimSpace(string(out)), err } -func unitProperty(unit, prop string) string { +// unitProperty is a property of a systemd unit (replaced in tests). +var unitProperty = func(unit, prop string) string { out, _ := command("systemctl", "show", "--value", "-p", prop, unit) return out } diff --git a/pkgs/router-webui/templates/update.html b/pkgs/router-webui/templates/update.html index aaf0904..d9de95d 100644 --- a/pkgs/router-webui/templates/update.html +++ b/pkgs/router-webui/templates/update.html @@ -22,6 +22,16 @@

The page reloads when it is done. The web UI restarts when an upgrade is switched on, and you log in again.

+{{else if $u.GitRun.Running}} + {{else if $u.Pending}}

Waiting for confirmation

A new system is active and not confirmed yet. Confirm it on the Overview, or the router goes back to the