-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_test.go
69 lines (57 loc) · 1.41 KB
/
git_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package git
import (
"fmt"
"os"
"testing"
"github.com/blackmarllboro/create-project-struct/internal/pkg/args/interfaces"
"github.com/blackmarllboro/create-project-struct/internal/pkg/args/mocks"
)
func TestCreateLocalGitRepository(t *testing.T) {
const currentDir = "current_dir"
data := []struct {
name string
mock interfaces.GetProjectName
}{
{
name: currentDir,
mock: mocks.IsCurrentDirIsTrue{},
},
{
name: mocks.ProjName,
mock: mocks.IsCurrentDirIsFalse{},
},
}
for _, dataT := range data {
{
t.Log("create dir for ", dataT.name)
{
if err := os.Mkdir(dataT.name, 0755); err != nil {
t.Fatalf("Failed to create test directory: %v", err)
}
if dataT.name == currentDir {
if err := os.Chdir(fmt.Sprintf("./%s", currentDir)); err != nil {
t.Fatalf("Expected no error, but got: %s", err)
}
}
}
t.Log("create repository in dir: ", dataT.name)
{
if err := CreateLocalGitRepository(dataT.mock); err != nil {
t.Fatalf("Expected no error, but got: %s", err)
}
}
t.Log("check the .git in the directory: ", dataT.name)
{
_, err := os.Stat(".git")
if os.IsNotExist(err) {
t.Fatal(".git directory not found in the expected location")
}
}
if err := os.Chdir(".."); err != nil {
t.Fatalf("Expected no error, but got: %s", err)
}
os.RemoveAll(fmt.Sprintf("./%s", dataT.name))
t.Log("SUCCESS")
}
}
}