This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / spindle / server_test.go
2.6 kB 105 lines
1package spindle 2 3import ( 4 "slices" 5 "testing" 6 7 "github.com/bluesky-social/indigo/atproto/syntax" 8 kgit "tangled.org/core/knotserver/git" 9 "tangled.org/core/spindle/db" 10) 11 12func TestHasSkipCIPushOption(t *testing.T) { 13 tests := []struct { 14 name string 15 pushOptions []string 16 want bool 17 }{ 18 { 19 name: "skip-ci requests skip", 20 pushOptions: []string{"skip-ci"}, 21 want: true, 22 }, 23 { 24 name: "ci-skip requests skip", 25 pushOptions: []string{"ci-skip"}, 26 want: true, 27 }, 28 { 29 name: "unrelated ci options do not skip", 30 pushOptions: []string{"verbose-ci", "ci-verbose"}, 31 want: false, 32 }, 33 { 34 name: "empty options do not skip", 35 pushOptions: []string{}, 36 want: false, 37 }, 38 { 39 name: "nil options do not skip", 40 pushOptions: nil, 41 want: false, 42 }, 43 { 44 name: "mixed options skip when any skip option appears", 45 pushOptions: []string{"verbose-ci", "skip-ci", "ci-verbose"}, 46 want: true, 47 }, 48 } 49 50 for _, tt := range tests { 51 t.Run(tt.name, func(t *testing.T) { 52 got := kgit.HasSkipCIPushOption(tt.pushOptions) 53 if got != tt.want { 54 t.Fatalf("hasSkipCIPushOption(%v) = %v, want %v", tt.pushOptions, got, tt.want) 55 } 56 }) 57 } 58} 59 60func TestSubscribedDids(t *testing.T) { 61 d, e := newTestSpindleDB(t) 62 63 var ( 64 member = syntax.DID("did:plc:member") 65 owner = syntax.DID("did:plc:owner") 66 collab = syntax.DID("did:plc:collab") 67 repoDid = syntax.DID("did:plc:repo") 68 repo2Did = syntax.DID("did:plc:repo2") 69 ) 70 71 // the repo owner is also a member, so the union has to dedupe 72 for _, did := range []syntax.DID{member, owner} { 73 if err := d.AllowMember(t.Context(), did); err != nil { 74 t.Fatalf("AllowMember(%s): %v", did, err) 75 } 76 } 77 78 for _, r := range []syntax.DID{repoDid, repo2Did} { 79 if err := d.UpsertRepo(db.Repo{ 80 Knot: "knot.test", 81 Owner: owner, 82 Rkey: syntax.RecordKey("rkey-" + r.String()), 83 RepoDid: r, 84 }); err != nil { 85 t.Fatalf("UpsertRepo(%s): %v", r, err) 86 } 87 if err := e.SetRepoOwner(owner, r); err != nil { 88 t.Fatalf("SetRepoOwner(%s): %v", r, err) 89 } 90 } 91 // a collaborator who is not a member - the case the members-only filter dropped 92 if err := e.AddRepoCollaborator(collab, repoDid); err != nil { 93 t.Fatalf("AddRepoCollaborator: %v", err) 94 } 95 96 got, err := subscribedDids(d, e) 97 if err != nil { 98 t.Fatalf("subscribedDids: %v", err) 99 } 100 101 want := []syntax.DID{collab, member, owner} // sorted and deduped 102 if !slices.Equal(got, want) { 103 t.Errorf("subscribedDids() = %v, want %v", got, want) 104 } 105}