internal/store/fork_test.go

4a511e42574ead9c92dc73fd320f296cc4dbea07
gitbay/internal/store/fork_test.go

51 lines · 1503 bytes

2 symbols in this file
 1package store
 2
 3import "testing"
 4
 5// A fork is created with its parent in the same insert; it is never a
 6// plain repository for a moment between two statements (#108).
 7func TestCreateForkSetsParent(t *testing.T) {
 8	s := open(t)
 9	if err := s.MigrateUp(); err != nil {
10		t.Fatal(err)
11	}
12	uid, _ := s.CreateUser("alice", false)
13	bob, _ := s.CreateUser("bob", false)
14	parent, err := s.CreateRepo("user", uid, "app", "public")
15	if err != nil {
16		t.Fatal(err)
17	}
18	id, err := s.CreateFork("user", bob, "app", "public", parent)
19	if err != nil {
20		t.Fatal(err)
21	}
22	r, err := s.RepoByID(id)
23	if err != nil || r.ForkOf != parent {
24		t.Fatalf("fork_of = %d, want %d (err %v)", r.ForkOf, parent, err)
25	}
26	if _, err := s.CreateFork("user", bob, "app", "public", parent); err == nil {
27		t.Fatal("duplicate fork name accepted")
28	}
29}
30
31// A private fork is not counted: the count is shown to anyone who can
32// read the parent.
33func TestPublicForkCountSkipsPrivate(t *testing.T) {
34	s := open(t)
35	if err := s.MigrateUp(); err != nil {
36		t.Fatal(err)
37	}
38	uid, _ := s.CreateUser("alice", false)
39	bob, _ := s.CreateUser("bob", false)
40	carol, _ := s.CreateUser("carol", false)
41	parent, _ := s.CreateRepo("user", uid, "app", "public")
42	if _, err := s.CreateFork("user", bob, "app", "public", parent); err != nil {
43		t.Fatal(err)
44	}
45	if _, err := s.CreateFork("user", carol, "app", "private", parent); err != nil {
46		t.Fatal(err)
47	}
48	if n := s.PublicForkCount(parent); n != 1 {
49		t.Fatalf("PublicForkCount = %d, want 1", n)
50	}
51}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form