MCPcopy
hub / github.com/digitalocean/doctl / TestRunSpacesKeysUpdate

Function TestRunSpacesKeysUpdate

commands/spaces_keys_test.go:195–254  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

193}
194
195func 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 })

Callers

nothing calls this directly

Calls 7

withTestClientFunction · 0.85
spacesKeysUpdateFunction · 0.85
RunMethod · 0.65
UpdateMethod · 0.65
SetMethod · 0.65
EXPECTMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected