-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
198 lines (154 loc) · 4.2 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
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
195
196
197
198
package main
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSetup(t *testing.T) {
baseDir = "testdata"
ctx, err := setup()
assert.NotNil(t, ctx)
assert.NoError(t, err)
assert.NotNil(t, ctx.config)
assert.NotNil(t, ctx.tempdir)
}
func TestSetupNone(t *testing.T) {
baseDir = "testx"
ctx, err := setup()
assert.NotNil(t, ctx)
assert.NoError(t, err)
assert.Empty(t, ctx.config)
assert.NotNil(t, ctx.tempdir)
}
func TestSetupNoneDebug(t *testing.T) {
baseDir = "testx"
fDebug = true
ctx, err := setup()
assert.NotNil(t, ctx)
assert.NoError(t, err)
assert.Empty(t, ctx.config)
assert.NotNil(t, ctx.tempdir)
assert.True(t, fVerbose)
fDebug = false
}
func TestSetupNoneDebugSandboxInvalid(t *testing.T) {
baseDir = "testdata"
prev := os.Getenv("TMPDIR")
if prev == "" {
prev = "/tmp"
}
require.NoError(t, os.Setenv("TMPDIR", "/nonexistent"))
fDebug = true
ctx, err := setup()
assert.Nil(t, ctx)
assert.Error(t, err)
require.NoError(t, os.Setenv("TMPDIR", prev))
fDebug = false
}
func setvars(t *testing.T) {
// Insert our values
require.NoError(t, os.Setenv("HTTP_PROXY", "http://proxy:8080/"))
require.NoError(t, os.Setenv("HTTPS_PROXY", "http://proxy:8080/"))
require.NoError(t, os.Setenv("http_proxy", "http://proxy:8080/"))
require.NoError(t, os.Setenv("https_proxy", "http://proxy:8080/"))
}
func unsetvars(t *testing.T) {
// Remove our values
require.NoError(t, os.Unsetenv("HTTP_PROXY"))
require.NoError(t, os.Unsetenv("HTTPS_PROXY"))
require.NoError(t, os.Unsetenv("http_proxy"))
require.NoError(t, os.Unsetenv("https_proxy"))
}
func TestSetupProxyError(t *testing.T) {
setvars(t)
baseDir = "testdata"
netrc := filepath.Join(".", "testdata", "test-netrc")
require.NoError(t, os.Chmod(netrc, 0600))
require.NoError(t, os.Setenv("NETRC", netrc))
ctx, err := setup()
assert.NotNil(t, ctx)
assert.NoError(t, err)
assert.NotNil(t, ctx.config)
assert.NotNil(t, ctx.tempdir)
unsetvars(t)
}
func TestSetupProxyAuth(t *testing.T) {
setvars(t)
baseDir = "testdata"
netrc := filepath.Join(".", "testdata", "test-netrc")
require.NoError(t, os.Chmod(netrc, 0600))
require.NoError(t, os.Setenv("NETRC", netrc))
ctx, err := setup()
assert.NotNil(t, ctx)
assert.NoError(t, err)
assert.NotNil(t, ctx.config)
assert.NotNil(t, ctx.tempdir)
unsetvars(t)
}
func TestSetupServer(t *testing.T) {
baseDir = "testdata"
configName = "config-smtp.toml"
require.NoError(t, os.Setenv("NETRC", filepath.Join(".", "test", "test-netrc")))
fDebug = true
ctx, err := setup()
assert.NotNil(t, ctx)
assert.NoError(t, err)
assert.NotNil(t, ctx.config)
assert.NotNil(t, ctx.tempdir)
assert.NotEmpty(t, ctx.config.Server)
require.NoError(t, os.Unsetenv("NETRC"))
fDebug = false
}
func TestRealMain_Noarg(t *testing.T) {
err := realmain([]string{})
assert.NoError(t, err)
}
func TestRealMain_InvalidFile(t *testing.T) {
err := realmain([]string{"testdata/bad.csv"})
assert.NoError(t, err)
}
func TestRealMain_Badtemp(t *testing.T) {
old := os.Getenv("TMPDIR")
require.NoError(t, os.Setenv("TMPDIR", "/nonexistent"))
err := realmain([]string{})
assert.Error(t, err)
require.NoError(t, os.Setenv("TMPDIR", old))
}
func TestRealMain_Onebadarg(t *testing.T) {
err := realmain([]string{"/foo.bar"})
assert.NoError(t, err)
}
func TestRealMain_Onearg_Empty(t *testing.T) {
err := realmain([]string{"testdata/CIMBL-0667-CERTS.csv"})
assert.NoError(t, err)
}
func TestRealMain_Onearg_EmptySkipped(t *testing.T) {
fSkipped = true
err := realmain([]string{"testdata/CIMBL-0667-CERTS.csv"})
assert.NoError(t, err)
fSkipped = false
}
func TestRealMain_Onearg_EmptySkipped2(t *testing.T) {
fSkipped = true
skipped = append(skipped, "https://example.net/")
err := realmain([]string{"testdata/CIMBL-0667-CERTS.csv"})
assert.NoError(t, err)
fSkipped = false
skipped = []string{}
}
func TestRealMain_Onearg_Good(t *testing.T) {
err := realmain([]string{"testdata/CIMBL-0666-CERTS.csv"})
assert.NoError(t, err)
}
func TestRealMain_Onearg_GoodZip(t *testing.T) {
err := realmain([]string{"testdata/CIMBL-0666-CERTS.zip"})
assert.NoError(t, err)
}
func TestUsage(t *testing.T) {
Usage()
}
func TestMain1(t *testing.T) {
main()
}