Skip to content

Commit 8c77dfd

Browse files
committed
test cloning with PAT
1 parent c018c79 commit 8c77dfd

5 files changed

Lines changed: 73 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# default build name
22
professor
33
.DS_Store
4+
.env
5+
.env.*

git/clone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func githubRepoUrl(repoPath string, pat string) string {
99
if pat != "" {
10-
return "https://" + pat + "@://github.com/" + repoPath + ".git"
10+
return "https://" + pat + "@github.com/" + repoPath + ".git"
1111
} else {
1212
return "https://github.com/" + repoPath + ".git"
1313
}

git/clone_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
package git
22

33
import (
4+
"log"
45
"os"
56
"testing"
7+
8+
"github.com/joho/godotenv"
69
)
710

811
func TestCloneRepo(t *testing.T) {
12+
err := godotenv.Load("../.env.test")
13+
14+
if err != nil {
15+
log.Fatal("Could not load test env!")
16+
return
17+
}
18+
919
t.Run("should clone the repo in the dest directory", func(t *testing.T) {
1020
repo := "Hack4Impact-UMD/professor"
1121
dest := t.TempDir()
@@ -33,4 +43,60 @@ func TestCloneRepo(t *testing.T) {
3343
}
3444
})
3545

46+
t.Run("should clone private repo with PAT in the dest directory", func(t *testing.T) {
47+
repo := "rk234/RamyKaddouri-h4i-assessment-Spring25"
48+
dest := t.TempDir()
49+
50+
t.Cleanup(func() {
51+
os.RemoveAll(dest)
52+
})
53+
54+
if err := CloneRepo(repo, dest, os.Getenv("GITHUB_PAT")); err != nil {
55+
t.Error("Error when cloning:", err)
56+
t.Fail()
57+
return
58+
}
59+
60+
files, err := os.ReadDir(dest)
61+
62+
if err != nil {
63+
t.Error("Error when reading dest dir:", err)
64+
t.Fail()
65+
return
66+
} else if len(files) <= 0 {
67+
t.Error("Dest dir is empty")
68+
t.Fail()
69+
return
70+
}
71+
})
72+
73+
t.Run("should error when cloning private repo with bad PAT", func(t *testing.T) {
74+
repo := "rk234/RamyKaddouri-h4i-assessment-Spring25"
75+
dest := t.TempDir()
76+
77+
t.Cleanup(func() {
78+
os.RemoveAll(dest)
79+
})
80+
81+
if err := CloneRepo(repo, dest, "abc:abc"); err != nil {
82+
return
83+
}
84+
85+
t.Fail()
86+
})
87+
88+
t.Run("should error when cloning bad repo path", func(t *testing.T) {
89+
repo := ""
90+
dest := t.TempDir()
91+
92+
t.Cleanup(func() {
93+
os.RemoveAll(dest)
94+
})
95+
96+
if err := CloneRepo(repo, dest, ""); err != nil {
97+
return
98+
}
99+
100+
t.Fail()
101+
})
36102
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/Hack4Impact-UMD/professor
22

33
go 1.26.1
4+
5+
require github.com/joho/godotenv v1.5.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
2+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=

0 commit comments

Comments
 (0)