|
| 1 | +package storage |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/arschles/assert" |
| 8 | + "github.com/deis/builder/pkg/sys" |
| 9 | +) |
| 10 | + |
| 11 | +type getClientTestCase struct { |
| 12 | + fileSystem map[string][]byte |
| 13 | + envs map[string]string |
| 14 | + expectClient bool |
| 15 | + expectErr bool |
| 16 | +} |
| 17 | + |
| 18 | +func TestGetClientEmptyAuth(t *testing.T) { |
| 19 | + testCases := []getClientTestCase{ |
| 20 | + // no auth & outside storage |
| 21 | + getClientTestCase{ |
| 22 | + fileSystem: make(map[string][]byte), |
| 23 | + envs: map[string]string{"DEIS_OUTSIDE_STORAGE": "http://outside.com"}, |
| 24 | + expectClient: true, |
| 25 | + expectErr: false, |
| 26 | + }, |
| 27 | + // invalid auth - missing secret |
| 28 | + getClientTestCase{ |
| 29 | + fileSystem: map[string][]byte{accessKeyIDFile: []byte("access key")}, |
| 30 | + envs: map[string]string{"DEIS_OUTSIDE_STORAGE": "http://outside.com"}, |
| 31 | + expectClient: false, |
| 32 | + expectErr: true, |
| 33 | + }, |
| 34 | + // invalid auth - missing key |
| 35 | + getClientTestCase{ |
| 36 | + fileSystem: map[string][]byte{accessSecretKeyFile: []byte("access secret")}, |
| 37 | + envs: map[string]string{"DEIS_OUTSIDE_STORAGE": "http://outside.com"}, |
| 38 | + expectClient: false, |
| 39 | + expectErr: true, |
| 40 | + }, |
| 41 | + // invalid endpoint |
| 42 | + getClientTestCase{ |
| 43 | + fileSystem: make(map[string][]byte), |
| 44 | + envs: make(map[string]string), |
| 45 | + expectClient: false, |
| 46 | + expectErr: true, |
| 47 | + }, |
| 48 | + // valid auth, outside storage |
| 49 | + getClientTestCase{ |
| 50 | + fileSystem: map[string][]byte{accessKeyIDFile: []byte("access key"), accessSecretKeyFile: []byte("access secret")}, |
| 51 | + envs: map[string]string{"DEIS_OUTSIDE_STORAGE": "http://outside.com"}, |
| 52 | + expectClient: true, |
| 53 | + expectErr: false, |
| 54 | + }, |
| 55 | + } |
| 56 | + for i, testCase := range testCases { |
| 57 | + fs := sys.NewFakeFS() |
| 58 | + fs.Files = testCase.fileSystem |
| 59 | + env := sys.NewFakeEnv() |
| 60 | + env.Envs = testCase.envs |
| 61 | + cl, err := GetClient("myrevion", fs, env) |
| 62 | + assert.Equal(t, testCase.expectClient, cl != nil, fmt.Sprintf("returned client %d", i)) |
| 63 | + assert.Equal(t, testCase.expectErr, err != nil, fmt.Sprintf("returned error %d", i)) |
| 64 | + } |
| 65 | +} |
0 commit comments