One upgrade for nixos-router and the packages
Check, preview and apply look at the repository's release tags and the channel together; the new nixos-router is a highlighted row in the preview table. The update server section and the separate git update are gone; bundles stay. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,96 +11,40 @@ 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) {
|
||||
// One check, one preview: the page shows nixos-router and the packages
|
||||
// together, and the preview marks the router's own row.
|
||||
func TestUpgradeShowsRouterAndPackages(t *testing.T) {
|
||||
a, sys := newTestApp(t)
|
||||
dir := t.TempDir()
|
||||
sys.ReleaseFile = filepath.Join(dir, "router-release")
|
||||
sys.RepositoryFile = filepath.Join(dir, "router-update-repository")
|
||||
os.WriteFile(sys.ReleaseFile, []byte(`{"version":"1.0.0","serial":1000}`), 0o600)
|
||||
os.WriteFile(sys.RepositoryFile, []byte(testRepository+"\n"), 0o644)
|
||||
a.sys = sys
|
||||
orig := startUnit
|
||||
var started []string
|
||||
startUnit = func(unit string) error { started = append(started, unit); return nil }
|
||||
defer func() { startUnit = orig }()
|
||||
h := a.routes()
|
||||
cookie := login(t, h)
|
||||
token := csrfFrom(t, do(h, "GET", "/update", nil, cookie).Body.String())
|
||||
post := func(path string, form url.Values) string {
|
||||
form.Set("csrf", token)
|
||||
return do(h, "POST", path, form, cookie).Header().Get("Location")
|
||||
}
|
||||
|
||||
// A router without a repository has nothing to look at.
|
||||
if loc := post("/update/gitcheck", url.Values{}); !strings.Contains(loc, "no+repository") || len(started) != 0 {
|
||||
t.Fatalf("a check without a repository: %q %v", loc, started)
|
||||
body := do(h, "GET", "/update", nil, cookie).Body.String()
|
||||
for _, want := range []string{testRepository, "Check for upgrades"} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Fatalf("the page lacks %q:\n%s", want, body)
|
||||
}
|
||||
}
|
||||
if loc := post("/update/gitinstall", url.Values{"tag": {"v1.1.0"}}); !strings.Contains(loc, "no+repository") {
|
||||
t.Fatalf("an install without a repository: %q", loc)
|
||||
}
|
||||
if rec := do(h, "POST", "/update/repository", url.Values{"csrf": {token}, "repository": {"https://evil.example.org/r"}}, cookie); rec.Code != 404 && rec.Code != 405 {
|
||||
t.Fatalf("the repository can be set from the page: %d", rec.Code)
|
||||
}
|
||||
if body := do(h, "GET", "/update", nil, cookie).Body.String(); strings.Contains(body, `name="repository"`) {
|
||||
if strings.Contains(body, `name="repository"`) {
|
||||
t.Fatalf("the page has a field for the repository:\n%s", body)
|
||||
}
|
||||
|
||||
// The repository is the installed version's; the page names it.
|
||||
os.WriteFile(sys.RepositoryFile, []byte(testRepository+"\n"), 0o644)
|
||||
if body := do(h, "GET", "/update", nil, cookie).Body.String(); !strings.Contains(body, testRepository) || !strings.Contains(body, "Not looked yet") {
|
||||
t.Fatalf("the page does not say which repository:\n%s", body)
|
||||
if rec := do(h, "POST", "/update/repository", nil, cookie); rec.Code != 404 && rec.Code != 405 {
|
||||
t.Fatalf("the repository can be set from the page: %d", rec.Code)
|
||||
}
|
||||
|
||||
// Looking starts the unit; what it found is shown while it is about this repository and version.
|
||||
post("/update/gitcheck", url.Values{})
|
||||
if len(started) != 1 || started[0] != "router-update-check.service" {
|
||||
t.Fatalf("started %v", started)
|
||||
}
|
||||
token := csrfFrom(t, body)
|
||||
do(h, "POST", "/upgrade/channel", url.Values{"csrf": {token}, "channel": {"26.05"}}, cookie)
|
||||
write := func(repo, installed string, newer bool) {
|
||||
os.MkdirAll(sys.updateDir(), 0o755)
|
||||
data, _ := json.Marshal(map[string]any{"repository": repo, "time": "2026-11-26T08:00:00Z", "installed": installed,
|
||||
"newest": map[string]string{"tag": "v1.1.0", "version": "1.1.0", "rev": "0123456789abcdef0123456789abcdef01234567"}, "newer": newer})
|
||||
os.WriteFile(filepath.Join(sys.updateDir(), "check.json"), data, 0o644)
|
||||
}
|
||||
write("https://git.example.org/someone-else/nixos-router", "1.0.0", true)
|
||||
if body := do(h, "GET", "/", nil, cookie).Body.String(); strings.Contains(body, "is out") {
|
||||
t.Fatalf("a notice from another repository:\n%s", body)
|
||||
os.MkdirAll(sys.upgradeDir(), 0o755)
|
||||
data, _ := json.Marshal(map[string]any{"channel": "26.05", "running": map[string]string{"version": a.sys.runningVersion()}, "time": "2026-11-26T08:00:00Z", "upToDate": !newer, "packagesUpToDate": true,
|
||||
"router": map[string]any{"repository": repo, "installed": installed, "newer": newer,
|
||||
"newest": map[string]string{"tag": "v1.1.0", "version": "1.1.0", "rev": "0123456789abcdef0123456789abcdef01234567"}}})
|
||||
os.WriteFile(filepath.Join(sys.upgradeDir(), "check.json"), data, 0o644)
|
||||
}
|
||||
write(testRepository, "0.9.0", true)
|
||||
if body := do(h, "GET", "/", nil, cookie).Body.String(); strings.Contains(body, "is out") {
|
||||
@@ -117,22 +61,15 @@ func TestUpdatesFromGit(t *testing.T) {
|
||||
t.Fatalf("a notice when up to date")
|
||||
}
|
||||
|
||||
// Installing asks the update unit to build the tag, and only a release tag.
|
||||
if loc := post("/update/gitinstall", url.Values{"tag": {"v1.1.0; reboot"}}); !strings.Contains(loc, "Not+a+release+tag") {
|
||||
t.Fatalf("a bad tag: %q", loc)
|
||||
}
|
||||
started = nil
|
||||
post("/update/gitinstall", url.Values{"tag": {"v1.1.0"}, "force": {"on"}})
|
||||
var req struct {
|
||||
Mode string `json:"mode"`
|
||||
URL string `json:"url"`
|
||||
Force bool `json:"force"`
|
||||
}
|
||||
data, _ := os.ReadFile(filepath.Join(sys.updateDir(), "request.json"))
|
||||
if err := json.Unmarshal(data, &req); err != nil || req.Mode != "git" || req.URL != "v1.1.0" || !req.Force {
|
||||
t.Fatalf("request: %s", data)
|
||||
}
|
||||
if len(started) != 1 || started[0] != "router-update.service" {
|
||||
t.Fatalf("started %v", started)
|
||||
// A preview that includes the router: one table, the router's row marked.
|
||||
preview, _ := json.Marshal(map[string]any{"channel": "26.05", "release": "1.0.0", "rev": "", "version": "26.05", "time": "t",
|
||||
"router": map[string]string{"from": "1.0.0", "to": "1.1.0", "tag": "v1.1.0", "rev": "abc"},
|
||||
"changes": []map[string]string{{"name": "curl", "from": "8.0", "to": "8.1"}}})
|
||||
os.WriteFile(filepath.Join(sys.upgradeDir(), "preview.json"), preview, 0o644)
|
||||
body = do(h, "GET", "/update", nil, cookie).Body.String()
|
||||
for _, want := range []string{`class="highlight"`, "<td>nixos-router</td>", "<td>curl</td>", "Upgrade nixos-router to 1.1.0 and"} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Fatalf("the preview lacks %q:\n%s", want, body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user