Skip to content
Permalink
Browse files
Merge pull request #754 from hilary/cleanup_tag
consolidate logic, droplet create --tagName(s)
  • Loading branch information
hilary committed Mar 5, 2020
2 parents 168528a + af770fd commit cd06cef3dec3ccab7a714f22bf140bca9ffdc75c
Showing 2 changed files with 14 additions and 36 deletions.
@@ -205,6 +205,9 @@ func RunDropletCreate(c *CmdConfig) error {
if err != nil {
return err
}
if len(tagName) > 0 {
tagNames = append(tagNames, tagName)
}

sshKeys := extractSSHKeys(keys)

@@ -247,7 +250,6 @@ func RunDropletCreate(c *CmdConfig) error {
}

ds := c.Droplets()
ts := c.Tags()

var wg sync.WaitGroup
var createdList do.Droplets
@@ -272,38 +274,12 @@ func RunDropletCreate(c *CmdConfig) error {
go func() {
defer wg.Done()

if tagName != "" {
tag, err := ts.Get(tagName)
if err != nil {
errs <- err
return
}
if tag == nil {
errs <- fmt.Errorf("Specified tag does not exist.")
return
}
}

d, err := ds.Create(dcr, wait)
if err != nil {
errs <- err
return
}

if tagName != "" {
trr := &godo.TagResourcesRequest{
Resources: []godo.Resource{
{ID: strconv.Itoa(d.ID), Type: godo.DropletResourceType},
},
}

err := ts.TagResources(tagName, trr)
if err != nil {
errs <- err
}

}

createdList = append(createdList, *d)
}()
}
@@ -106,16 +106,18 @@ func TestDropletCreate(t *testing.T) {

func TestDropletCreateWithTag(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
dcr := &godo.DropletCreateRequest{Name: "droplet", Region: "dev0", Size: "1gb", Image: godo.DropletCreateImage{ID: 0, Slug: "image"}, SSHKeys: []godo.DropletCreateSSHKey{}, Backups: false, IPv6: false, PrivateNetworking: false, UserData: "#cloud-config"}
dcr := &godo.DropletCreateRequest{
Name: "droplet",
Region: "dev0",
Size: "1gb",
Image: godo.DropletCreateImage{ID: 0, Slug: "image"},
SSHKeys: []godo.DropletCreateSSHKey{},
Backups: false,
IPv6: false,
PrivateNetworking: false,
UserData: "#cloud-config",
Tags: []string{"my-tag"}}
tm.droplets.EXPECT().Create(dcr, false).Return(&testDroplet, nil)
tm.tags.EXPECT().Get("my-tag").Return(&testTag, nil)

trr := &godo.TagResourcesRequest{
Resources: []godo.Resource{
{ID: "1", Type: godo.DropletResourceType},
},
}
tm.tags.EXPECT().TagResources("my-tag", trr).Return(nil)

config.Args = append(config.Args, "droplet")

0 comments on commit cd06cef

Please sign in to comment.