| 49 | } |
| 50 | |
| 51 | func TestValidateOCIKeyPair(t *testing.T) { |
| 52 | assert := assert.New(t) |
| 53 | |
| 54 | testCases := []struct { |
| 55 | name string |
| 56 | input *credentials.OCIKeypair |
| 57 | wantError bool |
| 58 | }{ |
| 59 | {"empty secret", &credentials.OCIKeypair{}, true}, |
| 60 | {"missing repo", &credentials.OCIKeypair{Username: "un", Password: "p"}, true}, |
| 61 | {"missing username", &credentials.OCIKeypair{Username: "", Password: "p", Repo: "repo"}, true}, |
| 62 | {"missing password", &credentials.OCIKeypair{Username: "u", Password: "", Repo: "repo"}, true}, |
| 63 | {"valid creds", &credentials.OCIKeypair{Username: "u", Password: "p", Repo: "repo"}, false}, |
| 64 | } |
| 65 | |
| 66 | for _, tc := range testCases { |
| 67 | t.Run(tc.name, func(t *testing.T) { |
| 68 | err := tc.input.Validate() |
| 69 | if tc.wantError { |
| 70 | assert.Error(err) |
| 71 | } else { |
| 72 | assert.NoError(err) |
| 73 | } |
| 74 | }) |
| 75 | } |
| 76 | } |