(t *testing.T)
| 193 | } |
| 194 | |
| 195 | func TestRunSpacesKeysUpdate(t *testing.T) { |
| 196 | testCases := []struct { |
| 197 | name string |
| 198 | args []string |
| 199 | grants []string |
| 200 | expectErr bool |
| 201 | }{ |
| 202 | { |
| 203 | name: "success", |
| 204 | args: []string{testValidAccessKey}, |
| 205 | grants: []string{"bucket=my-bucket;permission=readwrite"}, |
| 206 | expectErr: false, |
| 207 | }, |
| 208 | { |
| 209 | name: "missing key id", |
| 210 | args: []string{}, |
| 211 | grants: []string{"bucket=my-bucket;permission=readwrite"}, |
| 212 | expectErr: true, |
| 213 | }, |
| 214 | { |
| 215 | name: "invalid grant format", |
| 216 | args: []string{testValidAccessKey}, |
| 217 | grants: []string{"bucket=my-bucket;permission"}, |
| 218 | expectErr: true, |
| 219 | }, |
| 220 | { |
| 221 | name: "unsupported permission", |
| 222 | args: []string{testValidAccessKey}, |
| 223 | grants: []string{"bucket=my-bucket;permission=invalid"}, |
| 224 | expectErr: true, |
| 225 | }, |
| 226 | } |
| 227 | |
| 228 | for _, tc := range testCases { |
| 229 | t.Run(tc.name, func(t *testing.T) { |
| 230 | withTestClient(t, func(config *CmdConfig, tm *tcMocks) { |
| 231 | if !tc.expectErr { |
| 232 | req := godo.SpacesKeyUpdateRequest{ |
| 233 | Name: testValidName, |
| 234 | Grants: []*godo.Grant{ |
| 235 | {Bucket: testValidBucketName, Permission: godo.SpacesKeyReadWrite}, |
| 236 | }, |
| 237 | } |
| 238 | tm.spacesKeys.EXPECT().Update(testValidAccessKey, &req).Return(&testSpacesKey, nil) |
| 239 | } |
| 240 | |
| 241 | config.Args = tc.args |
| 242 | config.Doit.Set(config.NS, "grants", tc.grants) |
| 243 | config.Doit.Set(config.NS, "name", testValidName) |
| 244 | |
| 245 | err := spacesKeysUpdate(config) |
| 246 | if tc.expectErr { |
| 247 | require.Error(t, err) |
| 248 | } else { |
| 249 | require.NoError(t, err) |
| 250 | } |
| 251 | }) |
| 252 | }) |
nothing calls this directly
no test coverage detected