| 1 | package tinygit |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "reflect" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/FelineStateMachine/tinyrelay/internal/policy" |
| 9 | ) |
| 10 | |
| 11 | func TestCapabilitiesRequireEventSyncTransport(t *testing.T) { |
| 12 | p := policy.Policy{Features: policy.Features{Grasp: true, Grasp02: true, Grasp03: true, Grasp06: true}} |
| 13 | g := &GitRelay{policy: func() Policy { return fromInternalPolicy(p) }} |
| 14 | if got := g.Capabilities(); !reflect.DeepEqual(got, []string{"GRASP-01" , "GRASP-06" }) { |
| 15 | t.Fatalf("without event transport: %v" , got) |
| 16 | } |
| 17 | g.eventSync = func(context.Context, Repository) error { return nil } |
| 18 | if got := g.Capabilities(); !reflect.DeepEqual(got, []string{"GRASP-01" , "GRASP-02" , "GRASP-03" , "GRASP-06" }) { |
| 19 | t.Fatalf("with event transport: %v" , got) |
| 20 | } |
| 21 | p.Features.Grasp02 = false |
| 22 | if got := g.Capabilities(); !reflect.DeepEqual(got, []string{"GRASP-01" , "GRASP-06" }) { |
| 23 | t.Fatalf("without base sync: %v" , got) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | func TestCapabilitiesPreservePrivateProfiles(t *testing.T) { |
| 28 | p := policy.Policy{Reads: "members" , Features: policy.Features{Grasp: true, Grasp02: true, Grasp03: true, Grasp06: true, Grasp08: true}} |
| 29 | g := &GitRelay{policy: func() Policy { return fromInternalPolicy(p) }, eventSync: func(context.Context, Repository) error { return nil }} |
| 30 | want := []string{"GRASP-01" , "GRASP-02" , "GRASP-03" , "GRASP-06" , "GRASP-08" } |
| 31 | if got := g.SupportedGRASPs(); !reflect.DeepEqual(got, want) { |
| 32 | t.Fatalf("private profiles: %v" , got) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestPolicyPrivateServiceRequiresGRASP(t *testing.T) { |
| 37 | p := Policy{Reads: "members" , Features: PolicyFeatures{Grasp08: true}} |
| 38 | if p.PrivateServiceEnabled() { |
| 39 | t.Fatal("private service enabled without GRASP" ) |
| 40 | } |
| 41 | p.Features.Grasp = true |
| 42 | if !p.PrivateServiceEnabled() { |
| 43 | t.Fatal("private service not enabled with complete profile" ) |
| 44 | } |
| 45 | } |