|
| 1 | +package storage |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/arschles/assert" |
| 7 | + "github.com/deis/builder/pkg/sys" |
| 8 | +) |
| 9 | + |
| 10 | +type getEndpointTestCase struct { |
| 11 | + envVars map[string]string |
| 12 | + expectedOut string |
| 13 | + expectedErr error |
| 14 | +} |
| 15 | + |
| 16 | +func TestGetEndpoint(t *testing.T) { |
| 17 | + testCases := []getEndpointTestCase{ |
| 18 | + getEndpointTestCase{ |
| 19 | + envVars: map[string]string{"DEIS_OUTSIDE_STORAGE": "http://outside.storage.com"}, |
| 20 | + expectedOut: "http://outside.storage.com", |
| 21 | + }, |
| 22 | + getEndpointTestCase{ |
| 23 | + envVars: map[string]string{"DEIS_OUTSIDE_STORAGE": "https://outside.com"}, |
| 24 | + expectedOut: "https://outside.com", |
| 25 | + }, |
| 26 | + getEndpointTestCase{ |
| 27 | + envVars: map[string]string{ |
| 28 | + "DEIS_OUTSIDE_STORAGE": "outside.com", |
| 29 | + "DEIS_MINIO_SERVICE_HOST": "minio.com", |
| 30 | + "DEIS_MINIO_SERVICE_PORT": "8888", |
| 31 | + }, |
| 32 | + expectedOut: "outside.com", |
| 33 | + }, |
| 34 | + getEndpointTestCase{ |
| 35 | + envVars: map[string]string{ |
| 36 | + "DEIS_MINIO_SERVICE_HOST": "minio.com", |
| 37 | + "DEIS_MINIO_SERVICE_PORT": "8888", |
| 38 | + }, |
| 39 | + expectedOut: "http://minio.com:8888", |
| 40 | + }, |
| 41 | + getEndpointTestCase{ |
| 42 | + envVars: map[string]string{ |
| 43 | + "DEIS_MINIO_SERVICE_HOST": "minio.com", |
| 44 | + }, |
| 45 | + expectedErr: errNoStorageConfig, |
| 46 | + }, |
| 47 | + getEndpointTestCase{ |
| 48 | + envVars: map[string]string{ |
| 49 | + "DEIS_MINIO_SERVICE_PORT": "9999", |
| 50 | + }, |
| 51 | + expectedErr: errNoStorageConfig, |
| 52 | + }, |
| 53 | + } |
| 54 | + for _, testCase := range testCases { |
| 55 | + fe := sys.NewFakeEnv() |
| 56 | + fe.Envs = testCase.envVars |
| 57 | + str, err := getEndpoint(fe) |
| 58 | + assert.Equal(t, str, testCase.expectedOut, "output") |
| 59 | + if testCase.expectedErr == nil { |
| 60 | + assert.NoErr(t, err) |
| 61 | + } else { |
| 62 | + assert.Equal(t, err, testCase.expectedErr, "error") |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments