package declaration import ( "strings" "testing" ) // novox/hq ADR 0177: a unit is in the system manager or an account's own; a user-scoped one names // the account, a system one may not, and any other word is refused. func TestAUserScopedUnitNamesItsAccountAndASystemOneMayNot(t *testing.T) { cases := []struct{ scope, user, wants string }{ {"user", "ops", ""}, {"", "", ""}, {"system", "", ""}, {"user", "", "names the account"}, {"", "ops", "names no user"}, {"session", "ops", "scope \"session\""}, } for _, c := range cases { s := &Service{ID: "m.u", Type: TypeService, Unit: "u.service", State: "running", Scope: c.scope, User: c.user} problems := s.validate("m.u", false) got := strings.Join(problems, "; ") if c.wants == "" && len(problems) != 0 { t.Fatalf("scope %q user %q refused: %s", c.scope, c.user, got) } if c.wants != "" && !strings.Contains(got, c.wants) { t.Fatalf("scope %q user %q: wanted a refusal saying %q, got %q", c.scope, c.user, c.wants, got) } } }