Skip to content

Commit

Permalink
Merge pull request #545 from bentranter/bug-543-wait-flag-volume-detach
Browse files Browse the repository at this point in the history
Support --wait flag on volume-action commands
  • Loading branch information
hilary authored Aug 7, 2019
2 parents 9f6c3fb + c529cff commit 19dfb47
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
7 changes: 5 additions & 2 deletions commands/volume_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ func VolumeAction() *Command {
},
}

CmdBuilder(cmd, RunVolumeAttach, "attach <volume-id> <droplet-id>", "attach a volume", Writer,
cmdRunVolumeAttach := CmdBuilder(cmd, RunVolumeAttach, "attach <volume-id> <droplet-id>", "attach a volume", Writer,
aliasOpt("a"))
AddBoolFlag(cmdRunVolumeAttach, doctl.ArgCommandWait, "", false, "Wait for volume to attach")

CmdBuilder(cmd, RunVolumeDetach, "detach <volume-id> <droplet-id>", "detach a volume", Writer,
cmdRunVolumeDetach := CmdBuilder(cmd, RunVolumeDetach, "detach <volume-id> <droplet-id>", "detach a volume", Writer,
aliasOpt("d"))
AddBoolFlag(cmdRunVolumeDetach, doctl.ArgCommandWait, "", false, "Wait for volume to detach")

CmdBuilder(cmd, RunVolumeDetach, "detach-by-droplet-id <volume-id> <droplet-id>", "detach a volume (deprecated - use detach instead)",
Writer)
Expand All @@ -74,6 +76,7 @@ func VolumeAction() *Command {
requiredOpt())
AddStringFlag(cmdRunVolumeResize, doctl.ArgRegionSlug, "", "", "Volume region",
requiredOpt())
AddBoolFlag(cmdRunVolumeResize, doctl.ArgCommandWait, "", false, "Wait for volume to resize")

return cmd

Expand Down
38 changes: 38 additions & 0 deletions commands/volume_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ func TestVolumeActionsAttach(t *testing.T) {
err := RunVolumeAttach(config)
assert.NoError(t, err)
})

withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.volumeActions.EXPECT().Attach(testVolume.ID, testDroplet.ID).Return(&testAction, nil)
tm.actions.EXPECT().Get(1).Return(&testAction, nil)

config.Args = append(config.Args, testVolume.ID)
config.Args = append(config.Args, fmt.Sprintf("%d", testDroplet.ID))
config.Doit.Set(config.NS, doctl.ArgCommandWait, true)

err := RunVolumeAttach(config)
assert.NoError(t, err)
})
}

func TestVolumeDetach(t *testing.T) {
Expand All @@ -47,6 +59,18 @@ func TestVolumeDetach(t *testing.T) {
err := RunVolumeDetach(config)
assert.NoError(t, err)
})

withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.volumeActions.EXPECT().Detach(testVolume.ID, testDroplet.ID).Return(&testAction, nil)
tm.actions.EXPECT().Get(1).Return(&testAction, nil)

config.Args = append(config.Args, testVolume.ID)
config.Args = append(config.Args, fmt.Sprintf("%d", testDroplet.ID))
config.Doit.Set(config.NS, doctl.ArgCommandWait, true)

err := RunVolumeDetach(config)
assert.NoError(t, err)
})
}

func TestVolumeResize(t *testing.T) {
Expand All @@ -60,4 +84,18 @@ func TestVolumeResize(t *testing.T) {
err := RunVolumeResize(config)
assert.NoError(t, err)
})

withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.volumeActions.EXPECT().Resize(testVolume.ID, 150, "dev0").Return(&testAction, nil)
tm.actions.EXPECT().Get(1).Return(&testAction, nil)

config.Args = append(config.Args, testVolume.ID)

config.Doit.Set(config.NS, doctl.ArgSizeSlug, 150)
config.Doit.Set(config.NS, doctl.ArgRegionSlug, "dev0")
config.Doit.Set(config.NS, doctl.ArgCommandWait, true)

err := RunVolumeResize(config)
assert.NoError(t, err)
})
}

0 comments on commit 19dfb47

Please sign in to comment.