generated from coulomb/repo-seed
44 lines
1.2 KiB
Go
44 lines
1.2 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 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)
|
|
}
|
|
}
|