-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathtest_configs.go
114 lines (90 loc) · 2.49 KB
/
test_configs.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
109
110
111
112
113
114
package fixtures
import (
"io/ioutil"
"os"
)
type TestConfigs struct {
Path string
}
func (c *TestConfigs) TearDown() {
os.Setenv("HUB_CONFIG", "")
os.RemoveAll(c.Path)
}
func SetupTomlTestConfig() *TestConfigs {
file, _ := ioutil.TempFile("", "test-gh-config-")
content := `[[hosts]]
host = "github.com"
user = "jingweno"
access_token = "123"
protocol = "http"`
ioutil.WriteFile(file.Name(), []byte(content), os.ModePerm)
os.Setenv("HUB_CONFIG", file.Name())
return &TestConfigs{file.Name()}
}
func SetupTomlTestConfigWithUnixSocket() *TestConfigs {
file, _ := ioutil.TempFile("", "test-gh-config-")
content := `[[hosts]]
host = "github.com"
user = "jingweno"
access_token = "123"
protocol = "http"
unix_socket = "/tmp/go.sock"`
ioutil.WriteFile(file.Name(), []byte(content), os.ModePerm)
os.Setenv("HUB_CONFIG", file.Name())
return &TestConfigs{file.Name()}
}
func SetupTestConfigs() *TestConfigs {
file, _ := ioutil.TempFile("", "test-gh-config-")
content := `---
github.com:
- user: jingweno
oauth_token: "123"
protocol: http`
ioutil.WriteFile(file.Name(), []byte(content), os.ModePerm)
os.Setenv("HUB_CONFIG", file.Name())
return &TestConfigs{file.Name()}
}
func SetupTestConfigsWithUnixSocket() *TestConfigs {
file, _ := ioutil.TempFile("", "test-gh-config-")
content := `---
github.com:
- user: jingweno
oauth_token: "123"
protocol: http
unix_socket: /tmp/go.sock`
ioutil.WriteFile(file.Name(), []byte(content), os.ModePerm)
os.Setenv("HUB_CONFIG", file.Name())
return &TestConfigs{file.Name()}
}
func SetupTestConfigsInvalidHostName() *TestConfigs {
file, _ := ioutil.TempFile("", "test-gh-config-")
content := `---
123:
- user: jingweno
oauth_token: "123"
protocol: http
unix_socket: /tmp/go.sock`
ioutil.WriteFile(file.Name(), []byte(content), os.ModePerm)
os.Setenv("HUB_CONFIG", file.Name())
return &TestConfigs{file.Name()}
}
func SetupTestConfigsInvalidHostEntry() *TestConfigs {
file, _ := ioutil.TempFile("", "test-gh-config-")
content := `---
github.com: hello`
ioutil.WriteFile(file.Name(), []byte(content), os.ModePerm)
os.Setenv("HUB_CONFIG", file.Name())
return &TestConfigs{file.Name()}
}
func SetupTestConfigsInvalidPropertyValue() *TestConfigs {
file, _ := ioutil.TempFile("", "test-gh-config-")
content := `---
github.com:
- user:
oauth_token: "123"
protocol: http
unix_socket: /tmp/go.sock`
ioutil.WriteFile(file.Name(), []byte(content), os.ModePerm)
os.Setenv("HUB_CONFIG", file.Name())
return &TestConfigs{file.Name()}
}