-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
77 lines (65 loc) · 1.78 KB
/
main_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
70
71
72
73
74
75
76
77
package main
import (
"flag"
"os"
"path/filepath"
"testing"
)
func TestGetUsers(t *testing.T) {
expectedResult := "claudionts,joaothallis"
result := getUsers()
if result != expectedResult {
t.Errorf("Expected %s, but got %s", expectedResult, result)
}
}
func TestGetProjectName(t *testing.T) {
t.Run("No Argument Provided", func(t *testing.T) {
projectName, err := getProjectName()
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
cwd, _ := os.Getwd()
expectedName := filepath.Base(cwd)
if projectName != expectedName {
t.Errorf("Expected project name %s, but got %s", expectedName, projectName)
}
})
t.Run("Argument Provided", func(t *testing.T) {
os.Args = []string{"cmd", "myproject"}
flag.CommandLine = flag.NewFlagSet(os.Args[1], flag.ExitOnError)
flag.Parse()
projectName, err := getProjectName()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
expectedName := "myproject"
if projectName != expectedName {
t.Errorf("Expected project name %s, but got %s", expectedName, projectName)
}
})
}
func TestGetPrarFilePath(t *testing.T) {
t.Run("Global Flag False", func(t *testing.T) {
path, err := getPrarFilePath()
if err != nil {
t.Errorf("error: %v", err)
}
expectedPath := "./.prar.json"
if path != expectedPath {
t.Errorf("Expected path %s, but got %s", expectedPath, path)
}
})
t.Run("Global Flag True", func(t *testing.T) {
os.Args = []string{"cmd", "-global"}
flag.CommandLine = flag.NewFlagSet(os.Args[1], flag.ExitOnError)
path, err := getPrarFilePath()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
homeDir, _ := os.UserHomeDir()
expectedPath := homeDir + "/.config/prar.json"
if path != expectedPath {
t.Errorf("Expected path %s, but got %s", expectedPath, path)
}
})
}