mesh-sdk is pinned to feat/r4d-groups f0f66d5b8d42 (mesh-sdk #58) until it merges.
55 lines
2.0 KiB
Go
55 lines
2.0 KiB
Go
package apply
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/declaration"
|
|
)
|
|
|
|
// Issue 1637 (novox/hq ADR 0480 clause 7): a container's supplementary groups reach the runtime as --group-add.
|
|
|
|
func groupsContainer(groups ...int64) *declaration.Container {
|
|
return &declaration.Container{ID: "n8n.app", Name: "n8n", Image: pinned, Groups: groups}
|
|
}
|
|
|
|
// 1637/AC1: both run commands carry one --group-add per group, and none without groups.
|
|
func TestAContainerIsAddedItsSupplementaryGroups(t *testing.T) {
|
|
with := groupsContainer(2000, 2001)
|
|
for name, args := range map[string][]string{
|
|
"detached": detachedRunArgs(with, "x"),
|
|
"foreground": foregroundRunArgs(with, "x"),
|
|
} {
|
|
got := " " + strings.Join(args, " ") + " "
|
|
if !strings.Contains(got, " --group-add 2000 ") || !strings.Contains(got, " --group-add 2001 ") {
|
|
t.Errorf("1637/AC1: the %s run does not add both groups: %s", name, got)
|
|
}
|
|
}
|
|
without := groupsContainer()
|
|
for name, args := range map[string][]string{
|
|
"detached": detachedRunArgs(without, "x"),
|
|
"foreground": foregroundRunArgs(without, "x"),
|
|
} {
|
|
if strings.Contains(strings.Join(args, " "), "--group-add") {
|
|
t.Errorf("1637/AC1: the %s run adds a group none was declared", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 1637/AC2: a changed set of groups recreates the container; no groups leaves the spec as it was.
|
|
func TestAChangeOfGroupsRecreatesTheContainer(t *testing.T) {
|
|
none, a, b := groupsContainer(), groupsContainer(2000), groupsContainer(2000, 2001)
|
|
if containerSpec(none, inputs{}) == containerSpec(a, inputs{}) || containerSpec(a, inputs{}) == containerSpec(b, inputs{}) {
|
|
t.Error("1637/AC2: a change of groups does not change the container's spec")
|
|
}
|
|
same := groupsContainer(2000)
|
|
if containerSpec(a, inputs{}) != containerSpec(same, inputs{}) {
|
|
t.Error("1637/AC2: the same groups changed the spec")
|
|
}
|
|
plain := *none
|
|
plain.Groups = nil
|
|
if containerSpec(none, inputs{}) != containerSpec(&plain, inputs{}) {
|
|
t.Error("1637/AC2: a container with no groups has its spec moved")
|
|
}
|
|
}
|