BlueGit

timfa bluegit

Files

bluegit / internal / store / reviews_test.go

reviews_test.go

feat: groepseigenaar blijft beheerder en kan eigenaarschap overdragen
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
63e5d53c History
reviews_test.go 1.8 KiB Download Raw
1package store
2
3import (
4 "context"
5 "path/filepath"
6 "testing"
7
8 "gitlab.com/Timfa/bluegit/internal/access"
9)
10
11func TestGroupApprovalOverridesProject(t *testing.T) {
12 s := openStore(t)
13 ctx := context.Background()
14 tim, err := s.UpsertUser(ctx, 1, "tim", "", false)
15 if err != nil {
16 t.Fatal(err)
17 }
18 g, err := s.CreateGroup(ctx, tim.ID, "Team", "team", "", access.RoleDeveloper)
19 if err != nil {
20 t.Fatal(err)
21 }
22 repo, err := s.CreateRepo(ctx, "group", g.ID, "app", "", "master", "private")
23 if err != nil {
24 t.Fatal(err)
25 }
26 if err := s.SaveApproval(ctx, "repo", repo.ID, ApprovalPolicy{MaintainerRequired: true, RequiredCount: 1, DevelopersApprove: true}); err != nil {
27 t.Fatal(err)
28 }
29 pol, path, err := s.EffectiveApproval(ctx, repo)
30 if err != nil || path != "" || !pol.DevelopersApprove {
31 t.Fatalf("projectregel: %+v %s %v", pol, path, err)
32 }
33 if err := s.SaveApproval(ctx, "group", g.ID, ApprovalPolicy{MaintainerRequired: true, RequiredCount: 2}); err != nil {
34 t.Fatal(err)
35 }
36 pol, path, err = s.EffectiveApproval(ctx, repo)
37 if err != nil || path != "team" || pol.RequiredCount != 2 || pol.DevelopersApprove {
38 t.Fatalf("groepsregel wint: %+v %s %v", pol, path, err)
39 }
40 if _, err := s.db.ExecContext(ctx, `UPDATE group_members SET role = 'developer' WHERE group_id = ? AND user_id = ?`, g.ID, tim.ID); err != nil {
41 t.Fatal(err)
42 }
43 n, err := s.GroupMaintainerCount(ctx, g.ID)
44 if err != nil || n != 1 {
45 t.Fatalf("maker telt mee: %d %v", n, err)
46 }
47 pn, err := s.ProjectMaintainerCount(ctx, repo)
48 if err != nil || pn != 1 {
49 t.Fatalf("project telt de maker: %d %v", pn, err)
50 }
51}
52
53func openStore(t *testing.T) *Store {
54 t.Helper()
55 s, err := Open(filepath.Join(t.TempDir(), "bluegit.db"), make([]byte, 32))
56 if err != nil {
57 t.Fatal(err)
58 }
59 t.Cleanup(func() { _ = s.Close() })
60 return s
61}