hub/internal/pillar/pillar_test.go
trvon 0d7a219c5d
Some checks failed
release / build (push) Failing after 2m13s
hub: operator CLI with signed self-update
2026-11-10 20:32:32 -07:00

41 lines
1.3 KiB
Go

// SPDX-License-Identifier: GPL-3.0-or-later
package pillar_test
import (
"strings"
"testing"
"git.trevon.dev/trevon/hub/internal/pillar"
)
func TestOrderServices(t *testing.T) {
got := strings.Join(pillar.OrderServices("forgejo", []string{"caddy", "forgejo", "zed"}), ",")
if got != "forgejo,caddy,zed" {
t.Errorf("got %s", got)
}
if got := strings.Join(pillar.OrderServices("challenges", []string{"lab-d", "lab-a"}), ","); got != "lab-a,lab-d" {
t.Errorf("got %s", got)
}
}
func TestRender(t *testing.T) {
out := pillar.Render("beta-ci", []pillar.ComposeProject{
{Name: "a", Services: []string{"x", "yes", "my svc"}, AllowedPorts: []int{80}, ForbidRoot: true},
{Name: "b", Services: []string{"y"}, PortsNote: "many"},
}, []string{"admin"})
for _, want := range []string{
" beta-ci:\n compose_projects:\n - name: a\n",
" services: [x, 'yes', 'my svc']\n allowed_ports: [80]\n forbid_root: true\n",
" # allowed_ports omitted: many\n",
"# pillar/security_hub/beta_ci.sls",
" - admin\n",
} {
if !strings.Contains(out, want) {
t.Errorf("missing %q in:\n%s", want, out)
}
}
if !strings.Contains(pillar.Render("h", nil, nil), "no compose projects") {
t.Error("empty render must say so")
}
}