Skip to content

Commit 1bbce10

Browse files
authored
Merge pull request #141 from xmudrii/droplet-actions-tags
droplet_actions: return array of actions instead of action for tagged resources
2 parents ac8e270 + 4b0ca2d commit 1bbce10

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

droplet_actions.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@ type ActionRequest map[string]interface{}
1515
// See: https://developers.digitalocean.com/documentation/v2#droplet-actions
1616
type DropletActionsService interface {
1717
Shutdown(context.Context, int) (*Action, *Response, error)
18-
ShutdownByTag(context.Context, string) (*Action, *Response, error)
18+
ShutdownByTag(context.Context, string) ([]Action, *Response, error)
1919
PowerOff(context.Context, int) (*Action, *Response, error)
20-
PowerOffByTag(context.Context, string) (*Action, *Response, error)
20+
PowerOffByTag(context.Context, string) ([]Action, *Response, error)
2121
PowerOn(context.Context, int) (*Action, *Response, error)
22-
PowerOnByTag(context.Context, string) (*Action, *Response, error)
22+
PowerOnByTag(context.Context, string) ([]Action, *Response, error)
2323
PowerCycle(context.Context, int) (*Action, *Response, error)
24-
PowerCycleByTag(context.Context, string) (*Action, *Response, error)
24+
PowerCycleByTag(context.Context, string) ([]Action, *Response, error)
2525
Reboot(context.Context, int) (*Action, *Response, error)
2626
Restore(context.Context, int, int) (*Action, *Response, error)
2727
Resize(context.Context, int, string, bool) (*Action, *Response, error)
2828
Rename(context.Context, int, string) (*Action, *Response, error)
2929
Snapshot(context.Context, int, string) (*Action, *Response, error)
30-
SnapshotByTag(context.Context, string, string) (*Action, *Response, error)
30+
SnapshotByTag(context.Context, string, string) ([]Action, *Response, error)
3131
EnableBackups(context.Context, int) (*Action, *Response, error)
32-
EnableBackupsByTag(context.Context, string) (*Action, *Response, error)
32+
EnableBackupsByTag(context.Context, string) ([]Action, *Response, error)
3333
DisableBackups(context.Context, int) (*Action, *Response, error)
34-
DisableBackupsByTag(context.Context, string) (*Action, *Response, error)
34+
DisableBackupsByTag(context.Context, string) ([]Action, *Response, error)
3535
PasswordReset(context.Context, int) (*Action, *Response, error)
3636
RebuildByImageID(context.Context, int, int) (*Action, *Response, error)
3737
RebuildByImageSlug(context.Context, int, string) (*Action, *Response, error)
3838
ChangeKernel(context.Context, int, int) (*Action, *Response, error)
3939
EnableIPv6(context.Context, int) (*Action, *Response, error)
40-
EnableIPv6ByTag(context.Context, string) (*Action, *Response, error)
40+
EnableIPv6ByTag(context.Context, string) ([]Action, *Response, error)
4141
EnablePrivateNetworking(context.Context, int) (*Action, *Response, error)
42-
EnablePrivateNetworkingByTag(context.Context, string) (*Action, *Response, error)
42+
EnablePrivateNetworkingByTag(context.Context, string) ([]Action, *Response, error)
4343
Upgrade(context.Context, int) (*Action, *Response, error)
4444
Get(context.Context, int, int) (*Action, *Response, error)
4545
GetByURI(context.Context, string) (*Action, *Response, error)
@@ -60,7 +60,7 @@ func (s *DropletActionsServiceOp) Shutdown(ctx context.Context, id int) (*Action
6060
}
6161

6262
// ShutdownByTag shuts down Droplets matched by a Tag.
63-
func (s *DropletActionsServiceOp) ShutdownByTag(ctx context.Context, tag string) (*Action, *Response, error) {
63+
func (s *DropletActionsServiceOp) ShutdownByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
6464
request := &ActionRequest{"type": "shutdown"}
6565
return s.doActionByTag(ctx, tag, request)
6666
}
@@ -72,7 +72,7 @@ func (s *DropletActionsServiceOp) PowerOff(ctx context.Context, id int) (*Action
7272
}
7373

7474
// PowerOffByTag powers off Droplets matched by a Tag.
75-
func (s *DropletActionsServiceOp) PowerOffByTag(ctx context.Context, tag string) (*Action, *Response, error) {
75+
func (s *DropletActionsServiceOp) PowerOffByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
7676
request := &ActionRequest{"type": "power_off"}
7777
return s.doActionByTag(ctx, tag, request)
7878
}
@@ -84,7 +84,7 @@ func (s *DropletActionsServiceOp) PowerOn(ctx context.Context, id int) (*Action,
8484
}
8585

8686
// PowerOnByTag powers on Droplets matched by a Tag.
87-
func (s *DropletActionsServiceOp) PowerOnByTag(ctx context.Context, tag string) (*Action, *Response, error) {
87+
func (s *DropletActionsServiceOp) PowerOnByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
8888
request := &ActionRequest{"type": "power_on"}
8989
return s.doActionByTag(ctx, tag, request)
9090
}
@@ -96,7 +96,7 @@ func (s *DropletActionsServiceOp) PowerCycle(ctx context.Context, id int) (*Acti
9696
}
9797

9898
// PowerCycleByTag power cycles Droplets matched by a Tag.
99-
func (s *DropletActionsServiceOp) PowerCycleByTag(ctx context.Context, tag string) (*Action, *Response, error) {
99+
func (s *DropletActionsServiceOp) PowerCycleByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
100100
request := &ActionRequest{"type": "power_cycle"}
101101
return s.doActionByTag(ctx, tag, request)
102102
}
@@ -149,7 +149,7 @@ func (s *DropletActionsServiceOp) Snapshot(ctx context.Context, id int, name str
149149
}
150150

151151
// SnapshotByTag snapshots Droplets matched by a Tag.
152-
func (s *DropletActionsServiceOp) SnapshotByTag(ctx context.Context, tag string, name string) (*Action, *Response, error) {
152+
func (s *DropletActionsServiceOp) SnapshotByTag(ctx context.Context, tag string, name string) ([]Action, *Response, error) {
153153
requestType := "snapshot"
154154
request := &ActionRequest{
155155
"type": requestType,
@@ -165,7 +165,7 @@ func (s *DropletActionsServiceOp) EnableBackups(ctx context.Context, id int) (*A
165165
}
166166

167167
// EnableBackupsByTag enables backups for Droplets matched by a Tag.
168-
func (s *DropletActionsServiceOp) EnableBackupsByTag(ctx context.Context, tag string) (*Action, *Response, error) {
168+
func (s *DropletActionsServiceOp) EnableBackupsByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
169169
request := &ActionRequest{"type": "enable_backups"}
170170
return s.doActionByTag(ctx, tag, request)
171171
}
@@ -177,7 +177,7 @@ func (s *DropletActionsServiceOp) DisableBackups(ctx context.Context, id int) (*
177177
}
178178

179179
// DisableBackupsByTag disables backups for Droplet matched by a Tag.
180-
func (s *DropletActionsServiceOp) DisableBackupsByTag(ctx context.Context, tag string) (*Action, *Response, error) {
180+
func (s *DropletActionsServiceOp) DisableBackupsByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
181181
request := &ActionRequest{"type": "disable_backups"}
182182
return s.doActionByTag(ctx, tag, request)
183183
}
@@ -213,7 +213,7 @@ func (s *DropletActionsServiceOp) EnableIPv6(ctx context.Context, id int) (*Acti
213213
}
214214

215215
// EnableIPv6ByTag enables IPv6 for Droplets matched by a Tag.
216-
func (s *DropletActionsServiceOp) EnableIPv6ByTag(ctx context.Context, tag string) (*Action, *Response, error) {
216+
func (s *DropletActionsServiceOp) EnableIPv6ByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
217217
request := &ActionRequest{"type": "enable_ipv6"}
218218
return s.doActionByTag(ctx, tag, request)
219219
}
@@ -225,7 +225,7 @@ func (s *DropletActionsServiceOp) EnablePrivateNetworking(ctx context.Context, i
225225
}
226226

227227
// EnablePrivateNetworkingByTag enables private networking for Droplets matched by a Tag.
228-
func (s *DropletActionsServiceOp) EnablePrivateNetworkingByTag(ctx context.Context, tag string) (*Action, *Response, error) {
228+
func (s *DropletActionsServiceOp) EnablePrivateNetworkingByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
229229
request := &ActionRequest{"type": "enable_private_networking"}
230230
return s.doActionByTag(ctx, tag, request)
231231
}
@@ -261,7 +261,7 @@ func (s *DropletActionsServiceOp) doAction(ctx context.Context, id int, request
261261
return root.Event, resp, err
262262
}
263263

264-
func (s *DropletActionsServiceOp) doActionByTag(ctx context.Context, tag string, request *ActionRequest) (*Action, *Response, error) {
264+
func (s *DropletActionsServiceOp) doActionByTag(ctx context.Context, tag string, request *ActionRequest) ([]Action, *Response, error) {
265265
if tag == "" {
266266
return nil, nil, NewArgError("tag", "cannot be empty")
267267
}
@@ -277,13 +277,13 @@ func (s *DropletActionsServiceOp) doActionByTag(ctx context.Context, tag string,
277277
return nil, nil, err
278278
}
279279

280-
root := new(actionRoot)
280+
root := new(actionsRoot)
281281
resp, err := s.client.Do(ctx, req, root)
282282
if err != nil {
283283
return nil, resp, err
284284
}
285285

286-
return root.Event, resp, err
286+
return root.Actions, resp, err
287287
}
288288

289289
// Get an action for a particular Droplet by id.

droplet_actions_test.go

+18-19
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ func TestDropletActions_ShutdownByTag(t *testing.T) {
6666
t.Errorf("Request body = %+v, expected %+v", v, request)
6767
}
6868

69-
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
69+
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
7070
})
7171

7272
action, _, err := client.DropletActions.ShutdownByTag(ctx, "testing-1")
7373
if err != nil {
7474
t.Errorf("DropletActions.ShutdownByTag returned error: %v", err)
7575
}
7676

77-
expected := &Action{Status: "in-progress"}
77+
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
7878
if !reflect.DeepEqual(action, expected) {
7979
t.Errorf("DropletActions.ShutdownByTag returned %+v, expected %+v", action, expected)
8080
}
@@ -138,15 +138,15 @@ func TestDropletAction_PowerOffByTag(t *testing.T) {
138138
t.Errorf("Request body = %+v, expected %+v", v, request)
139139
}
140140

141-
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
141+
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
142142
})
143143

144144
action, _, err := client.DropletActions.PowerOffByTag(ctx, "testing-1")
145145
if err != nil {
146146
t.Errorf("DropletActions.PowerOffByTag returned error: %v", err)
147147
}
148148

149-
expected := &Action{Status: "in-progress"}
149+
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
150150
if !reflect.DeepEqual(action, expected) {
151151
t.Errorf("DropletActions.PoweroffByTag returned %+v, expected %+v", action, expected)
152152
}
@@ -210,15 +210,15 @@ func TestDropletAction_PowerOnByTag(t *testing.T) {
210210
t.Errorf("Request body = %+v, expected %+v", v, request)
211211
}
212212

213-
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
213+
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
214214
})
215215

216216
action, _, err := client.DropletActions.PowerOnByTag(ctx, "testing-1")
217217
if err != nil {
218218
t.Errorf("DropletActions.PowerOnByTag returned error: %v", err)
219219
}
220220

221-
expected := &Action{Status: "in-progress"}
221+
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
222222
if !reflect.DeepEqual(action, expected) {
223223
t.Errorf("DropletActions.PowerOnByTag returned %+v, expected %+v", action, expected)
224224
}
@@ -428,16 +428,15 @@ func TestDropletAction_PowerCycleByTag(t *testing.T) {
428428
t.Errorf("Request body = %+v, expected %+v", v, request)
429429
}
430430

431-
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
432-
431+
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
433432
})
434433

435434
action, _, err := client.DropletActions.PowerCycleByTag(ctx, "testing-1")
436435
if err != nil {
437436
t.Errorf("DropletActions.PowerCycleByTag returned error: %v", err)
438437
}
439438

440-
expected := &Action{Status: "in-progress"}
439+
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
441440
if !reflect.DeepEqual(action, expected) {
442441
t.Errorf("DropletActions.PowerCycleByTag returned %+v, expected %+v", action, expected)
443442
}
@@ -505,15 +504,15 @@ func TestDropletAction_SnapshotByTag(t *testing.T) {
505504
t.Errorf("Request body = %+v, expected %+v", v, request)
506505
}
507506

508-
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
507+
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
509508
})
510509

511510
action, _, err := client.DropletActions.SnapshotByTag(ctx, "testing-1", "Image-Name")
512511
if err != nil {
513512
t.Errorf("DropletActions.SnapshotByTag returned error: %v", err)
514513
}
515514

516-
expected := &Action{Status: "in-progress"}
515+
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
517516
if !reflect.DeepEqual(action, expected) {
518517
t.Errorf("DropletActions.SnapshotByTag returned %+v, expected %+v", action, expected)
519518
}
@@ -579,15 +578,15 @@ func TestDropletAction_EnableBackupsByTag(t *testing.T) {
579578
t.Errorf("Request body = %+v, expected %+v", v, request)
580579
}
581580

582-
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
581+
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
583582
})
584583

585584
action, _, err := client.DropletActions.EnableBackupsByTag(ctx, "testing-1")
586585
if err != nil {
587586
t.Errorf("DropletActions.EnableBackupsByTag returned error: %v", err)
588587
}
589588

590-
expected := &Action{Status: "in-progress"}
589+
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
591590
if !reflect.DeepEqual(action, expected) {
592591
t.Errorf("DropletActions.EnableBackupsByTag returned %+v, expected %+v", action, expected)
593592
}
@@ -653,15 +652,15 @@ func TestDropletAction_DisableBackupsByTag(t *testing.T) {
653652
t.Errorf("Request body = %+v, expected %+v", v, request)
654653
}
655654

656-
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
655+
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
657656
})
658657

659658
action, _, err := client.DropletActions.DisableBackupsByTag(ctx, "testing-1")
660659
if err != nil {
661660
t.Errorf("DropletActions.DisableBackupsByTag returned error: %v", err)
662661
}
663662

664-
expected := &Action{Status: "in-progress"}
663+
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
665664
if !reflect.DeepEqual(action, expected) {
666665
t.Errorf("DropletActions.DisableBackupsByTag returned %+v, expected %+v", action, expected)
667666
}
@@ -870,15 +869,15 @@ func TestDropletAction_EnableIPv6ByTag(t *testing.T) {
870869
t.Errorf("Request body = %+v, expected %+v", v, request)
871870
}
872871

873-
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
872+
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
874873
})
875874

876875
action, _, err := client.DropletActions.EnableIPv6ByTag(ctx, "testing-1")
877876
if err != nil {
878877
t.Errorf("DropletActions.EnableIPv6ByTag returned error: %v", err)
879878
}
880879

881-
expected := &Action{Status: "in-progress"}
880+
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
882881
if !reflect.DeepEqual(action, expected) {
883882
t.Errorf("DropletActions.EnableIPv6byTag returned %+v, expected %+v", action, expected)
884883
}
@@ -944,15 +943,15 @@ func TestDropletAction_EnablePrivateNetworkingByTag(t *testing.T) {
944943
t.Errorf("Request body = %+v, expected %+v", v, request)
945944
}
946945

947-
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
946+
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
948947
})
949948

950949
action, _, err := client.DropletActions.EnablePrivateNetworkingByTag(ctx, "testing-1")
951950
if err != nil {
952951
t.Errorf("DropletActions.EnablePrivateNetworkingByTag returned error: %v", err)
953952
}
954953

955-
expected := &Action{Status: "in-progress"}
954+
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
956955
if !reflect.DeepEqual(action, expected) {
957956
t.Errorf("DropletActions.EnablePrivateNetworkingByTag returned %+v, expected %+v", action, expected)
958957
}

0 commit comments

Comments
 (0)