1package repository
2
3import (
4 "io/ioutil"
5 "log"
6
7 "github.com/99designs/keyring"
8)
9
10const namespace = "git-bug"
11
12// This is intended for testing only
13
14func CreateGoGitTestRepo(bare bool) TestedRepo {
15 dir, err := ioutil.TempDir("", "")
16 if err != nil {
17 log.Fatal(err)
18 }
19
20 var creator func(string, string) (*GoGitRepo, error)
21
22 if bare {
23 creator = InitBareGoGitRepo
24 } else {
25 creator = InitGoGitRepo
26 }
27
28 repo, err := creator(dir, namespace)
29 if err != nil {
30 log.Fatal(err)
31 }
32
33 config := repo.LocalConfig()
34 if err := config.StoreString("user.name", "testuser"); err != nil {
35 log.Fatal("failed to set user.name for test repository: ", err)
36 }
37 if err := config.StoreString("user.email", "testuser@example.com"); err != nil {
38 log.Fatal("failed to set user.email for test repository: ", err)
39 }
40
41 // make sure we use a mock keyring for testing to not interact with the global system
42 return &replaceKeyring{
43 TestedRepo: repo,
44 keyring: keyring.NewArrayKeyring(nil),
45 }
46}
47
48func SetupGoGitReposAndRemote() (repoA, repoB, remote TestedRepo) {
49 repoA = CreateGoGitTestRepo(false)
50 repoB = CreateGoGitTestRepo(false)
51 remote = CreateGoGitTestRepo(true)
52
53 err := repoA.AddRemote("origin", remote.GetLocalRemote())
54 if err != nil {
55 log.Fatal(err)
56 }
57
58 err = repoB.AddRemote("origin", remote.GetLocalRemote())
59 if err != nil {
60 log.Fatal(err)
61 }
62
63 return repoA, repoB, remote
64}