BlueGit

timfa bluegit

Files

bluegit / internal / gitrepo / repo_test.go

repo_test.go

feat: eerste basis van BlueGit
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
151aa352 History
repo_test.go 1.3 KiB Download Raw
1package gitrepo
2
3import (
4 "bytes"
5 "os"
6 "path/filepath"
7 "strings"
8 "testing"
9
10 "gitlab.com/Timfa/bluegit/internal/access"
11)
12
13func TestEvaluatePush(t *testing.T) {
14 var buf bytes.Buffer
15 buf.WriteString("0000000000000000000000000000000000000000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa refs/heads/main\n")
16 err := EvaluatePush(access.RoleDeveloper, []string{"main"}, &buf)
17 if err == nil {
18 t.Fatal("ontwikkelaar mag main niet")
19 }
20 buf.Reset()
21 buf.WriteString("0000000000000000000000000000000000000000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa refs/heads/feature\n")
22 if err := EvaluatePush(access.RoleDeveloper, []string{"main"}, &buf); err != nil {
23 t.Fatal(err)
24 }
25 if err := EvaluatePush(access.RoleMaintainer, nil, strings.NewReader("")); err == nil {
26 t.Fatal("lege push")
27 }
28}
29
30func TestInitWritesHook(t *testing.T) {
31 if _, err := os.Stat("/usr/bin/git"); err != nil {
32 t.Skip("git ontbreekt")
33 }
34 dir := filepath.Join(t.TempDir(), "demo.git")
35 if err := Init("git", dir, "main", "/usr/bin/bluegit"); err != nil {
36 t.Fatal(err)
37 }
38 body, err := os.ReadFile(filepath.Join(dir, "hooks", "pre-receive"))
39 if err != nil {
40 t.Fatal(err)
41 }
42 if !strings.Contains(string(body), "hook pre-receive") || !strings.Contains(string(body), "/usr/bin/bluegit") {
43 t.Fatalf("hook: %s", body)
44 }
45}