-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
194 lines (176 loc) · 4.1 KB
/
config_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package main
import (
"testing"
)
func TestNewConfigSrcDstValues(t *testing.T) {
// expect no error for default paths
ci := ConfigInput{
target: "https://github.com/mikemilano/seeder.git",
cdir: "/tmp",
proto: "auto",
}
_, err := NewConfig(ci)
if err != nil {
t.Error("Expected no errors with empty src/dst, got error")
}
// expect no error for default paths
ci = ConfigInput{
target: "https://github.com/mikemilano/seeder.git",
src: "README.md",
dst: ".",
cdir: "/tmp",
proto: "auto",
}
_, err = NewConfig(ci)
if err != nil {
t.Error("Expected no errors with default src/dst, got error")
}
}
func TestTarget(t *testing.T) {
// expect error if target is empty
ci := ConfigInput{
src: "./",
dst: "./",
cdir: "/tmp",
proto: "auto",
}
_, err := NewConfig(ci)
if err == nil {
t.Error("Expected error from empty target, got none")
}
// convert short form with https
ci = ConfigInput{
target: "mikemilano/seeder",
src: "./",
dst: "./",
cdir: "/tmp",
proto: "https",
}
config, err := NewConfig(ci)
if config.url.String() != "https://@github.com/" + ci.target + ".git" {
t.Error("Expected short form target with https to get https://@github.com/" + ci.target + ".git, got", config.url.String())
}
// convert short form with ssh
ci = ConfigInput{
target: "mikemilano/seeder",
src: "./",
dst: "./",
cdir: "/tmp",
proto: "ssh",
}
config, err = NewConfig(ci)
if config.url.String() != "ssh://[email protected]/" + ci.target {
t.Error("Expected short form target with ssh url to be ssh://[email protected]/" + ci.target + ", got", config.url.String())
}
// convert short form with auto
ci = ConfigInput{
target: "mikemilano/seeder",
src: "./",
dst: "./",
cdir: "/tmp",
proto: "auto",
}
config, err = NewConfig(ci)
if config.url.String() != "ssh://[email protected]/" + ci.target {
t.Error("Expected short form target with auto url to be ssh://[email protected]/" + ci.target + ", got", config.url.String())
}
}
func TestCloneDir(t *testing.T) {
// expect error if clone dir is empty
ci := ConfigInput{
target: "https://github.com/mikemilano/seeder.git",
src: "./",
dst: "./",
proto: "auto",
}
_, err := NewConfig(ci)
if err == nil {
t.Error("Expected error from empty clone dir, got none")
}
// expect error if clone dir does not exist
ci = ConfigInput{
target: "https://github.com/mikemilano/seeder.git",
src: "./",
dst: "./",
cdir: "/invalid-directory",
proto: "auto",
}
_, err = NewConfig(ci)
if err == nil {
t.Error("Expected error from invalid clone dir, got none")
}
// expect no error if clone dir exists
ci = ConfigInput{
target: "https://github.com/mikemilano/seeder.git",
src: "./",
dst: "./",
cdir: "/tmp",
proto: "auto",
}
_, err = NewConfig(ci)
if err != nil {
t.Error("Expected no error from valid clone dir, got error")
}
}
func TestNewConfigProtocol(t *testing.T) {
// expect error with empty proto
ci := ConfigInput{
target: "mikemilano/seeder",
src: "./",
dst: "./",
cdir: "/tmp",
proto: "",
}
_, err := NewConfig(ci)
if err == nil {
t.Error("Expected error from empty proto, got none")
}
// expect error invalid proto
ci = ConfigInput{
target: "mikemilano/seeder",
src: "./",
dst: "./",
cdir: "/tmp",
proto: "foobar",
}
_, err = NewConfig(ci)
if err == nil {
t.Error("Expected error from invalid proto, got none")
}
// expect no error with auto proto
ci = ConfigInput{
target: "mikemilano/seeder",
src: "./",
dst: "./",
cdir: "/tmp",
proto: "auto",
}
_, err = NewConfig(ci)
if err != nil {
t.Error("Expected no error with auto proto, got error")
}
// expect no error with https proto
ci = ConfigInput{
target: "mikemilano/seeder",
src: "./",
dst: "./",
cdir: "/tmp",
proto: "https",
}
_, err = NewConfig(ci)
if err != nil {
t.Error("Expected no error with https proto, got error")
}
// expect no error with ssh proto
ci = ConfigInput{
target: "mikemilano/seeder",
src: "./",
dst: "./",
cdir: "/tmp",
proto: "ssh",
}
_, err = NewConfig(ci)
if err != nil {
t.Error("Expected no error with ssh proto, got error")
}
}