Files
flex-auth/internal/registry/manifest_test.go
tegwick 18054bd160
Some checks failed
CI / Build and Test (push) Has been cancelled
CI / Lint (push) Has been cancelled
Add CARING examples and coverage
2026-05-17 06:05:18 +02:00

70 lines
2.5 KiB
Go

package registry_test
import (
"os"
"path/filepath"
"testing"
"gopkg.in/yaml.v3"
"github.com/netkingdom/flex-auth/pkg/api"
)
func TestRegistryManifestsParse(t *testing.T) {
var subjects api.SubjectManifest
loadYAML(t, filepath.Join("..", "..", "examples", "caring", "subject_manifest.yaml"), &subjects)
if len(subjects.Subjects) != 1 {
t.Fatalf("Subjects len = %d; want 1", len(subjects.Subjects))
}
if subjects.Subjects[0].Roles[0] != api.CanonicalRoleDoer {
t.Errorf("Subject role = %q; want Doer", subjects.Subjects[0].Roles[0])
}
var fact api.RelationshipFact
loadYAML(t, filepath.Join("..", "..", "examples", "caring", "relationship_fact.yaml"), &fact)
if fact.Subject != "group:platform-architecture" || fact.Object != "document:internal-note" {
t.Fatalf("relationship fact did not parse as expected: %+v", fact)
}
if fact.Caring == nil || fact.Caring.Profile != api.CaringProfileCaring040RC2 {
t.Fatalf("fact.Caring = %+v; want CARING profile descriptor", fact.Caring)
}
}
func TestExpandedRegistryExamplesParse(t *testing.T) {
var subjects api.SubjectManifest
loadYAML(t, filepath.Join("..", "..", "examples", "caring", "team_subject_manifest.yaml"), &subjects)
if len(subjects.Teams) != 1 || subjects.Teams[0].ID != "team:project-reviewers" {
t.Fatalf("subjects.Teams = %+v; want team:project-reviewers", subjects.Teams)
}
var resources api.ResourceManifest
loadYAML(t, filepath.Join("..", "..", "examples", "caring", "project_resource_manifest.yaml"), &resources)
if len(resources.Resources) != 2 || resources.Resources[1].Parent != "project:alpha-redesign" {
t.Fatalf("resources = %+v; want document inheriting from project", resources.Resources)
}
var relationships []api.RelationshipFact
loadYAML(t, filepath.Join("..", "..", "examples", "caring", "inherited_relationships.yaml"), &relationships)
if len(relationships) != 2 {
t.Fatalf("relationships len = %d; want 2", len(relationships))
}
if relationships[0].Caring == nil || relationships[0].Caring.CanonicalRole != api.CanonicalRoleVerifier {
t.Fatalf("relationships[0].Caring = %+v; want Verifier descriptor", relationships[0].Caring)
}
if relationships[1].Relation != "inherits" {
t.Fatalf("relationships[1].Relation = %q; want inherits", relationships[1].Relation)
}
}
func loadYAML(t *testing.T, path string, out any) {
t.Helper()
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read %s: %v", path, err)
}
if err := yaml.Unmarshal(data, out); err != nil {
t.Fatalf("unmarshal %s: %v", path, err)
}
}