-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathendpoint_test.go
More file actions
90 lines (82 loc) · 2.43 KB
/
endpoint_test.go
File metadata and controls
90 lines (82 loc) · 2.43 KB
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
package storage
import (
"fmt"
"testing"
"github.com/arschles/assert"
"github.com/deis/builder/pkg/sys"
)
type getEndpointTestCase struct {
envVars map[string]string
expectedOut *Endpoint
expectedErr error
}
func TestGetEndpoint(t *testing.T) {
testCases := []getEndpointTestCase{
getEndpointTestCase{
envVars: map[string]string{"DEIS_OUTSIDE_STORAGE": "http://outside.storage.com"},
expectedOut: &Endpoint{URLStr: "outside.storage.com", Secure: true},
},
getEndpointTestCase{
envVars: map[string]string{"DEIS_OUTSIDE_STORAGE": "https://outside.com"},
expectedOut: &Endpoint{URLStr: "outside.com", Secure: true},
},
getEndpointTestCase{
envVars: map[string]string{
"DEIS_OUTSIDE_STORAGE": "outside.com",
"DEIS_MINIO_SERVICE_HOST": "minio.com",
"DEIS_MINIO_SERVICE_PORT": "8888",
},
expectedOut: &Endpoint{URLStr: "outside.com", Secure: true},
},
getEndpointTestCase{
envVars: map[string]string{
"DEIS_MINIO_SERVICE_HOST": "minio.com",
"DEIS_MINIO_SERVICE_PORT": "8888",
},
expectedOut: &Endpoint{URLStr: "minio.com:8888", Secure: false},
},
getEndpointTestCase{
envVars: map[string]string{
"DEIS_MINIO_SERVICE_HOST": "minio.com",
},
expectedErr: errNoStorageConfig,
},
getEndpointTestCase{
envVars: map[string]string{
"DEIS_MINIO_SERVICE_PORT": "9999",
},
expectedErr: errNoStorageConfig,
},
}
for _, testCase := range testCases {
fe := sys.NewFakeEnv()
fe.Envs = testCase.envVars
ep, err := getEndpoint(fe)
if testCase.expectedOut != nil {
assert.Equal(t, ep.URLStr, testCase.expectedOut.URLStr, "url string")
assert.Equal(t, ep.Secure, testCase.expectedOut.Secure, "secure boolean")
} else {
assert.True(t, ep == nil, "endpoint was non-nil when it should have been")
}
if testCase.expectedErr == nil {
assert.NoErr(t, err)
} else {
assert.Equal(t, err, testCase.expectedErr, "error")
}
}
}
type schemeTestCase struct {
before string
after string
}
func TestStripScheme(t *testing.T) {
schemes := []schemeTestCase{
schemeTestCase{before: "https://deis.com", after: "deis.com"},
schemeTestCase{before: "http://deis.com", after: "deis.com"},
schemeTestCase{before: "deis.com", after: "deis.com"},
schemeTestCase{before: "://deis.com", after: "://deis.com"},
}
for i, scheme := range schemes {
assert.Equal(t, stripScheme(scheme.before), scheme.after, fmt.Sprintf("scheme %s (# %d)", scheme.before, i))
}
}