-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
108 lines (99 loc) · 2.46 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"runtime"
"testing"
)
func TestExecute(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip()
}
if _, exit := execute("true"); exit != 0 {
t.Fatal(exit)
}
if _, exit := execute("false"); exit != 1 {
t.Fatal(exit)
}
if _, exit := execute("sh", "-c", "exit 42"); exit != 42 {
t.Fatal(exit)
}
}
func Test_extractBranchMaster(t *testing.T) {
output := `* remote origin
Fetch URL: [email protected]:foo/bar.git
Push URL: [email protected]:foo/bar.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
`
branch := extractBranch(output)
if branch != "master" {
t.Fatal("failed extracting branch")
}
}
func Test_extractBranchMain(t *testing.T) {
output := `* remote origin
Fetch URL: [email protected]:foo/bar.git
Push URL: [email protected]:foo/bar.git
HEAD branch: main
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
`
branch := extractBranch(output)
fmt.Println("branch is ", branch)
if branch != "main" {
t.Fatal("failed extracting branch")
}
}
func Test_extractBranchDefaultMasterBranch(t *testing.T) {
output := `* remote origin
Fetch URL: [email protected]:foo/bar.git
Push URL: [email protected]:foo/bar.git
HEAD branch:
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
`
branch := extractBranch(output)
if branch != "master" {
t.Fatal("failed extracting branch")
}
}
func Test_copyIncludesToCache(t *testing.T) {
// given
// check if the includes are present in the project
checkIfDirIsNotEmpty(t, includesDir)
tempDir, err := ioutil.TempDir("", "")
assert.NoError(t, err)
defer os.RemoveAll(tempDir)
os.Setenv("PROTOC_CACHE_DIR", tempDir)
defer os.Unsetenv("PROTOC_CACHE_DIR")
// when
err = copyIncludesToCache(includesDir)
// then
assert.NoError(t, err)
checkIfDirIsNotEmpty(t, tempDir)
}
func checkIfDirIsNotEmpty(t *testing.T, path string) {
dirs, err := os.ReadDir(path)
assert.NoError(t, err)
for _, d := range dirs {
f, err := d.Info()
assert.NoError(t, err)
assert.True(t, f.Size() != 0)
}
}