47 lines
2.0 KiB
Go
47 lines
2.0 KiB
Go
package forgeaccount
|
|
|
|
import "testing"
|
|
|
|
// Issue 1481 (novox/hq ADR 0466 §3): the build modules' forge user, team and key scope.
|
|
func TestTheBuildModulesHaveOneForgeUserAndTheMachinesKeepTheirs(t *testing.T) {
|
|
for kind, want := range map[string]string{"machine": "nox-agent", "builder": "nox-builder", "session": ""} {
|
|
if got := ForgeUser("ace", kind); got != want {
|
|
t.Errorf("ForgeUser(ace, %s) = %q, want %q", kind, got, want)
|
|
}
|
|
}
|
|
if ForgeUser("Not A Node", "builder") != "" {
|
|
t.Errorf("a name no account could be named for got a user")
|
|
}
|
|
for module, want := range map[string]string{"mesh-build-go": "builder", "mesh-build-node": "builder", "ssh-client": "machine", "": "machine"} {
|
|
if got := KindOfModule(module); got != want {
|
|
t.Errorf("KindOfModule(%q) = %s, want %s", module, got, want)
|
|
}
|
|
}
|
|
if TeamOfUser(BuilderUser).Name != "builders" || TeamOfUser(AgentUser).Name != "agents" {
|
|
t.Errorf("teams: %s and %s", TeamOfUser(BuilderUser).Name, TeamOfUser(AgentUser).Name)
|
|
}
|
|
}
|
|
|
|
// A build module's scope names the module, so one module's pass does not remove the other's key on the same machine;
|
|
// the machine's scope is every key of the machine.
|
|
func TestABuilderScopeNamesTheModule(t *testing.T) {
|
|
if got := BuilderScope("ace", "mesh-build-go"); got != "mesh:ace.mesh-build-go" {
|
|
t.Errorf("scope = %q", got)
|
|
}
|
|
if BuilderScope("ace", "mesh-build-go") == BuilderScope("ace", "mesh-build-node") {
|
|
t.Errorf("two build modules share a scope")
|
|
}
|
|
if got := KeyTitle("ace", "mesh-build-go"); got != BuilderScope("ace", "mesh-build-go") {
|
|
t.Errorf("the key's title %q is not inside the scope", got)
|
|
}
|
|
}
|
|
|
|
// The builders team reads the code of every repository of the organisation and has no other right.
|
|
func TestTheBuildersTeamReadsCodeOnly(t *testing.T) {
|
|
s := BuildersTeam.Shape()
|
|
units, _ := s["units_map"].(map[string]string)
|
|
if s["permission"] != "read" || s["includes_all_repositories"] != true || s["can_create_org_repo"] != false || len(units) != 1 || units["repo.code"] != "read" {
|
|
t.Errorf("shape = %v", s)
|
|
}
|
|
}
|