@@ -9,34 +9,34 @@ import (
99
1010type getEndpointTestCase struct {
1111 envVars map [string ]string
12- expectedOut string
12+ expectedOut * Endpoint
1313 expectedErr error
1414}
1515
1616func TestGetEndpoint (t * testing.T ) {
1717 testCases := []getEndpointTestCase {
1818 getEndpointTestCase {
1919 envVars : map [string ]string {"DEIS_OUTSIDE_STORAGE" : "http://outside.storage.com" },
20- expectedOut : "http:// outside.storage.com" ,
20+ expectedOut : & Endpoint { URLStr : " outside.storage.com", Secure : true } ,
2121 },
2222 getEndpointTestCase {
2323 envVars : map [string ]string {"DEIS_OUTSIDE_STORAGE" : "https://outside.com" },
24- expectedOut : "https:// outside.com" ,
24+ expectedOut : & Endpoint { URLStr : " outside.com", Secure : true } ,
2525 },
2626 getEndpointTestCase {
2727 envVars : map [string ]string {
2828 "DEIS_OUTSIDE_STORAGE" : "outside.com" ,
2929 "DEIS_MINIO_SERVICE_HOST" : "minio.com" ,
3030 "DEIS_MINIO_SERVICE_PORT" : "8888" ,
3131 },
32- expectedOut : "outside.com" ,
32+ expectedOut : & Endpoint { URLStr : "outside.com" , Secure : true } ,
3333 },
3434 getEndpointTestCase {
3535 envVars : map [string ]string {
3636 "DEIS_MINIO_SERVICE_HOST" : "minio.com" ,
3737 "DEIS_MINIO_SERVICE_PORT" : "8888" ,
3838 },
39- expectedOut : "http:// minio.com:8888" ,
39+ expectedOut : & Endpoint { URLStr : " minio.com:8888", Secure : false } ,
4040 },
4141 getEndpointTestCase {
4242 envVars : map [string ]string {
@@ -54,12 +54,36 @@ func TestGetEndpoint(t *testing.T) {
5454 for _ , testCase := range testCases {
5555 fe := sys .NewFakeEnv ()
5656 fe .Envs = testCase .envVars
57- str , err := getEndpoint (fe )
58- assert .Equal (t , str , testCase .expectedOut , "output" )
57+ ep , err := getEndpoint (fe )
58+
59+ if testCase .expectedOut != nil {
60+ assert .Equal (t , ep .URLStr , testCase .expectedOut .URLStr , "url string" )
61+ assert .Equal (t , ep .Secure , testCase .expectedOut .Secure , "secure boolean" )
62+ } else {
63+ assert .True (t , ep == nil , "endpoint was non-nil when it should have been" )
64+ }
65+
5966 if testCase .expectedErr == nil {
6067 assert .NoErr (t , err )
6168 } else {
6269 assert .Equal (t , err , testCase .expectedErr , "error" )
6370 }
6471 }
6572}
73+
74+ type schemeTestCase struct {
75+ before string
76+ after string
77+ }
78+
79+ func TestStripScheme (t * testing.T ) {
80+ schemes := []schemeTestCase {
81+ schemeTestCase {before : "https://deis.com" , after : "deis.com" },
82+ schemeTestCase {before : "http://deis.com" , after : "deis.com" },
83+ schemeTestCase {before : "deis.com" , after : "deis.com" },
84+ schemeTestCase {before : "://deis.com" , after : "://deis.com" },
85+ }
86+ for i , scheme := range schemes {
87+ assert .Equal (t , stripScheme (scheme .before ), scheme .after , fmt .Sprintf ("scheme %s (# %d)" , scheme .before , i ))
88+ }
89+ }
0 commit comments