The node line still judged a system Node against the old minimum of 22, so a machine with Node 22 read "too old for a host install of the webmail" two lines above the shapes section offering one with --install-deps. A host webmail runs on inbuxa's own Node 26 in /opt/inbuxa, so that's the one the line now describes: there, there in the wrong version, or not there yet with the same --install-deps offer. A system Node is reported as not used.
88 lines
3.2 KiB
Go
88 lines
3.2 KiB
Go
// SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package plan
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.coffeylabs.org/inbuxa/inbuxa-installer/internal/host"
|
|
)
|
|
|
|
func machine() host.Facts {
|
|
return host.Facts{
|
|
Root: true, Systemd: true,
|
|
Runtime: host.Runtime{Kind: "docker", Present: true, Usable: true, Compose: "v2"},
|
|
Glibc: host.Glibc{Version: "2.41", Major: 2, Minor: 41},
|
|
Node: host.Node{Present: true, Path: host.OwnPath, Version: "26.11.1", Major: 26},
|
|
}
|
|
}
|
|
|
|
func shapes(server, console, webmail Shape) []Choice {
|
|
return []Choice{{Server, server}, {Console, console}, {Webmail, webmail}}
|
|
}
|
|
|
|
func TestTheConsoleOnTheHostNeedsAWebServer(t *testing.T) {
|
|
t.Setenv("INBUXA_CONSOLE_TARBALL", "/tmp/console.tar.gz")
|
|
f := machine()
|
|
for _, tc := range []struct {
|
|
local bool
|
|
proxy string
|
|
ok bool
|
|
}{
|
|
{false, "caddy", true}, {false, "snippets", true}, {false, "none", false}, {true, "", false},
|
|
} {
|
|
o := Options{Domain: "example.org", Local: tc.local, Proxy: tc.proxy, Choices: shapes(Container, Host, Container)}
|
|
_, err := Build(f, o)
|
|
if (err == nil) != tc.ok {
|
|
t.Errorf("local=%v proxy=%q: err = %v", tc.local, tc.proxy, err)
|
|
}
|
|
if err != nil && !strings.Contains(err.Error(), "web server") {
|
|
t.Errorf("the refusal does not say why: %v", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestHostFrontEndsComeFromTheirReleases(t *testing.T) {
|
|
f := machine()
|
|
if a := Available(f, Console, Host); !a.OK {
|
|
t.Errorf("console host with a pinned release: %+v", a)
|
|
}
|
|
if a := Available(f, Webmail, Host); !a.OK {
|
|
t.Errorf("webmail host with a pinned release and Node 26: %+v", a)
|
|
}
|
|
f.Node = host.Node{Present: true, Path: "/usr/bin/node", Major: 26}
|
|
if a := Available(f, Webmail, Host); a.OK || !strings.Contains(a.Why, "own Node") {
|
|
t.Errorf("the system's Node was accepted for the webmail: %+v", a)
|
|
}
|
|
// ...and the installer offers to fetch its own
|
|
p, err := Build(f, Options{Domain: "example.org", InstallDeps: true, Choices: shapes(Container, Container, Host)})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(p.Needs) != 1 || p.Needs[0].Name != "node" {
|
|
t.Errorf("needs = %+v", p.Needs)
|
|
}
|
|
}
|
|
|
|
func TestTheSurveyOffersWhatTheInstallerCanAdd(t *testing.T) {
|
|
f := machine()
|
|
f.Node = host.Node{} // only the installer's own Node is missing
|
|
text := SurveyText(f)
|
|
if !strings.Contains(text, "host (with --install-deps: the webmail runs on the installer's own Node") {
|
|
t.Errorf("a webmail on the host is refused rather than offered:\n%s", text)
|
|
}
|
|
if !strings.Contains(text, "node not installed (a host webmail runs on inbuxa's own Node 26; --install-deps adds it)") {
|
|
t.Errorf("the node line doesn't make the same offer:\n%s", text)
|
|
}
|
|
f.Node = host.Node{Present: true, Version: "22.14.0", Major: 22, Path: "/usr/bin/node"}
|
|
if text := SurveyText(f); !strings.Contains(text, "22.14.0 at /usr/bin/node (not used:") || strings.Contains(text, "too old") {
|
|
t.Errorf("a system Node is judged rather than reported:\n%s", text)
|
|
}
|
|
f.Systemd = false // and this, nothing installs
|
|
if text := SurveyText(f); !strings.Contains(text, "host (no: a host install needs systemd") {
|
|
t.Errorf("a machine without systemd is offered a host webmail:\n%s", text)
|
|
}
|
|
}
|