37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package catalog
|
|
|
|
import "testing"
|
|
|
|
func TestCatalogRejectsUnknownAndProtectsManagementActions(t *testing.T) {
|
|
if _, ok := DescriptorByID("invented.action"); ok {
|
|
t.Fatal("unknown action registered")
|
|
}
|
|
got, ok := DescriptorByID("system.roles.manage")
|
|
if !ok || got.Scope != ScopeSystem || !got.Protected {
|
|
t.Fatalf("descriptor=%+v", got)
|
|
}
|
|
create, ok := DescriptorByID("project.create")
|
|
if !ok || create.Scope != ScopeSystem || create.Protected {
|
|
t.Fatalf("project.create=%+v", create)
|
|
}
|
|
}
|
|
|
|
func TestCatalogProjectAccessIsTheOnlyRoleAction(t *testing.T) {
|
|
access, ok := DescriptorByID(ProjectAccessAction)
|
|
if !ok || access.ActionID != "project.create" || access.Scope != ScopeSystem || access.Protected {
|
|
t.Fatalf("project access descriptor=%+v ok=%v", access, ok)
|
|
}
|
|
}
|
|
|
|
func TestCatalogReturnsIndependentCopies(t *testing.T) {
|
|
first := Catalog()
|
|
if len(first) == 0 {
|
|
t.Fatal("empty catalog")
|
|
}
|
|
first[0].Label = "mutated"
|
|
second := Catalog()
|
|
if second[0].Label == "mutated" {
|
|
t.Fatal("Catalog exposed mutable registry storage")
|
|
}
|
|
}
|