Skip to content
Permalink
Browse files
droplet: Add droplet-agent flag. (#1013)
  • Loading branch information
andrewsomething committed Aug 9, 2021
1 parent 0a9be46 commit 567433ea1767cdab9d86342a5af594e360ab5da5
Showing with 67 additions and 0 deletions.
  1. +2 −0 args.go
  2. +10 −0 commands/droplets.go
  3. +55 −0 commands/droplets_test.go
@@ -122,6 +122,8 @@ const (
ArgPrivateNetworking = "enable-private-networking"
// ArgMonitoring is an enable monitoring argument.
ArgMonitoring = "enable-monitoring"
// ArgDropletAgent is an argument for enabling/disbling the Droplet agent.
ArgDropletAgent = "droplet-agent"
// ArgRecordData is a record data argument.
ArgRecordData = "record-data"
// ArgRecordID is a record id argument.
@@ -87,6 +87,7 @@ func Droplet() *Command {
AddStringFlag(cmdDropletCreate, doctl.ArgTagName, "", "", "A tag name to be applied to the Droplet")
AddStringFlag(cmdDropletCreate, doctl.ArgVPCUUID, "", "", "The UUID of a non-default VPC to create the Droplet in")
AddStringSliceFlag(cmdDropletCreate, doctl.ArgTagNames, "", []string{}, "A list of tag names to be applied to the Droplet")
AddBoolFlag(cmdDropletCreate, doctl.ArgDropletAgent, "", false, "By default, the agent is installed on new Droplets but installation errors are ignored. Set to `false` to prevent installation. Set `true` to make installation errors fatal.")

AddStringSliceFlag(cmdDropletCreate, doctl.ArgVolumeList, "", []string{}, "A list of block storage volume IDs to attach to the Droplet")

@@ -199,6 +200,11 @@ func RunDropletCreate(c *CmdConfig) error {
return err
}

agent, err := c.Doit.GetBoolPtr(c.NS, doctl.ArgDropletAgent)
if err != nil {
return err
}

keys, err := c.Doit.GetStringSlice(c.NS, doctl.ArgSSHKeys)
if err != nil {
return err
@@ -284,6 +290,10 @@ func RunDropletCreate(c *CmdConfig) error {
Tags: tagNames,
}

if agent != nil {
dcr.WithDropletAgent = agent
}

wg.Add(1)
go func() {
defer wg.Done()
@@ -502,3 +502,58 @@ func TestDropletOneClickListNoType(t *testing.T) {
assert.NoError(t, err)
})
}

func TestDropletCreateWithAgent(t *testing.T) {
boolF := false
boolT := true
tests := []struct {
name string
agent *bool
}{
{
name: "with droplet-agent true",
agent: &boolT,
},
{
name: "with droplet-agent false",
agent: &boolF,
},
{
name: "with droplet-agent unset",
agent: &boolF,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
dcr := &godo.DropletCreateRequest{
Name: "droplet",
Region: "nyc3",
Size: "s-1gb-1vcpu",
Image: godo.DropletCreateImage{ID: 0, Slug: "image"},
SSHKeys: []godo.DropletCreateSSHKey{},
Backups: false,
IPv6: false,
PrivateNetworking: false,
}
if tt.agent != nil {
dcr.WithDropletAgent = tt.agent
}

tm.droplets.EXPECT().Create(dcr, false).Return(&testDroplet, nil)

config.Args = append(config.Args, "droplet")
config.Doit.Set(config.NS, doctl.ArgRegionSlug, "nyc3")
config.Doit.Set(config.NS, doctl.ArgSizeSlug, "s-1gb-1vcpu")
config.Doit.Set(config.NS, doctl.ArgImage, "image")
if tt.agent != nil {
config.Doit.Set(config.NS, doctl.ArgDropletAgent, tt.agent)
}

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

0 comments on commit 567433e

Please sign in to comment.