Skip to content

Commit 33b5666

Browse files
committed
found bug when plainClone, add basic tests
1 parent 8315787 commit 33b5666

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,22 @@ type Config struct {
4444
}
4545

4646
func main() {
47+
48+
4749
config, err := initConfig()
4850
if err != nil {
4951
log.Fatalf("initConfig() error: %v", err)
5052
}
5153

54+
//g := *config.GithubLink
55+
//flag.StringVar(&g, "link", "", "")
56+
//TODO: this is for test only, remove when done
57+
flag.Parse()
58+
for _, v := range os.Args {
59+
fmt.Println(v)
60+
}
61+
*config.GithubLink = os.Args[1]
62+
5263
workdir, err := processWorkingDirectory(
5364
*config.GithubLink, *config.GithubBranch, *config.GithubUsername, *config.GithubToken)
5465
if err != nil {
@@ -258,7 +269,7 @@ func processWorkingDirectory(githubLink, githubBranch, githubUsername, githubTok
258269
}
259270
}
260271

261-
if _, err := git.PlainClone(workdir, false, &cloneOptions); err != nil {
272+
if _, err := git.PlainClone(workdir, false, &cloneOptions); err != nil { //TODO: this is where error is
262273
if err := os.RemoveAll(workdir); err != nil {
263274
return "", err
264275
}

main_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,32 @@ func TestProcessWorkingDirectory(t *testing.T) {
5757
)
5858
}
5959

60+
func TestProcessWorkingDirectoryIgnore(t *testing.T) {
61+
// since test is running in cmd/reflexia folder we need to go back
62+
err := os.Chdir("../..")
63+
if err != nil {
64+
t.Fatal(err)
65+
}
66+
t.Run(
67+
"Working directory with github link",
68+
func(t *testing.T) {
69+
workdir, err := processWorkingDirectory("https://github.com/JackBekket/LocalAI", "", "", "")
70+
if err != nil {
71+
t.Fatal(err)
72+
}
73+
if filepath.Base(workdir) != "LocalAI" {
74+
t.Fatalf("workdir != LocalAI")
75+
}
76+
},
77+
)
78+
79+
}
80+
81+
func TestMainApp(t *testing.T) {
82+
os.Args = []string{"-g", "https://github.com/JackBekket/LocalAI"}
83+
main()
84+
}
85+
6086
func TestGetProjectConfig(t *testing.T) {
6187
t.Run(
6288
"Project language .toml config",

0 commit comments

Comments
 (0)