Skip to content

Commit 5fc8b1a

Browse files
authored
Merge pull request #820 from scottcrawford03/add-mp-1-click-to-k8s-and-droplet
Add mp 1 click to k8s and droplet
2 parents f1614a2 + 0a96f63 commit 5fc8b1a

File tree

5 files changed

+104
-3
lines changed

5 files changed

+104
-3
lines changed

commands/1_clicks_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func TestOneClickCommand(t *testing.T) {
2828
assertCommandNames(t, cmd, "list")
2929
}
3030

31-
func TesOneClickListNoType(t *testing.T) {
31+
func TestOneClickListNoType(t *testing.T) {
3232
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
33-
tm.oneClick.EXPECT().List("").Return(testOneClickList)
33+
tm.oneClick.EXPECT().List("").Return(testOneClickList, nil)
3434
err := RunOneClickList(config)
3535
assert.NoError(t, err)
3636
})

commands/droplets.go

+31
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ func Droplet() *Command {
120120
cmdRunDropletUntag := CmdBuilder(cmd, RunDropletUntag, "untag <droplet-id|droplet-name>", "Remove a tag from a Droplet", "Use this command to remove a tag from a Droplet, specified with the `--tag-name` flag.", Writer)
121121
AddStringSliceFlag(cmdRunDropletUntag, doctl.ArgTagName, "", []string{}, "Tag name to remove from Droplet")
122122

123+
cmd.AddCommand(dropletOneClicks())
124+
123125
return cmd
124126
}
125127

@@ -735,3 +737,32 @@ func buildDropletSummary(ds do.DropletsService) (*dropletSummary, error) {
735737

736738
return &sum, nil
737739
}
740+
741+
// kubernetesOneClicks creates the 1-click command.
742+
func dropletOneClicks() *Command {
743+
cmd := &Command{
744+
Command: &cobra.Command{
745+
Use: "1-click",
746+
Short: "Display commands that pertain to droplet 1-click applications",
747+
Long: "The commands under `doctl kubernetes 1-click` are for interacting with DigitalOcean Droplet 1-Click applications.",
748+
},
749+
}
750+
751+
CmdBuilder(cmd, RunDropletOneClickList, "list", "Retrieve a list of Droplet 1-Click applications", "Use this command to retrieve a list of Droplet 1-Click applications.", Writer,
752+
aliasOpt("ls"), displayerType(&displayers.OneClick{}))
753+
754+
return cmd
755+
}
756+
757+
// RunDropletOneClickList retrieves a list of 1-clicks for Droplets.
758+
func RunDropletOneClickList(c *CmdConfig) error {
759+
oneClicks := c.OneClicks()
760+
oneClickList, err := oneClicks.List("droplet")
761+
if err != nil {
762+
return err
763+
}
764+
765+
items := &displayers.OneClick{OneClicks: oneClickList}
766+
767+
return c.Display(items)
768+
}

commands/droplets_test.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,23 @@ var (
3838
Regions: []string{"test0"},
3939
}}
4040
testImageList = do.Images{testImage, testImageSecondary}
41+
42+
testDropletOneClick = do.OneClick{
43+
OneClick: &godo.OneClick{
44+
Slug: "test-slug",
45+
Type: "droplet",
46+
},
47+
}
48+
49+
testDropletOneClickList = do.OneClicks{
50+
testOneClick,
51+
}
4152
)
4253

4354
func TestDropletCommand(t *testing.T) {
4455
cmd := Droplet()
4556
assert.NotNil(t, cmd)
46-
assertCommandNames(t, cmd, "actions", "backups", "create", "delete", "get", "kernels", "list", "neighbors", "snapshots", "tag", "untag")
57+
assertCommandNames(t, cmd, "1-click", "actions", "backups", "create", "delete", "get", "kernels", "list", "neighbors", "snapshots", "tag", "untag")
4758
}
4859

4960
func TestDropletActionList(t *testing.T) {
@@ -483,3 +494,11 @@ func Test_extractSSHKey(t *testing.T) {
483494
assert.Equal(t, c.expected, got)
484495
}
485496
}
497+
498+
func TestDropletOneClickListNoType(t *testing.T) {
499+
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
500+
tm.oneClick.EXPECT().List("droplet").Return(testDropletOneClickList, nil)
501+
err := RunDropletOneClickList(config)
502+
assert.NoError(t, err)
503+
})
504+
}

commands/kubernetes.go

+31
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ func Kubernetes() *Command {
109109

110110
cmd.AddCommand(kubernetesCluster())
111111
cmd.AddCommand(kubernetesOptions())
112+
cmd.AddCommand(kubernetesOneClicks())
113+
112114
return cmd
113115
}
114116

@@ -465,6 +467,35 @@ This command deletes the specified node in the specified node pool, and then cre
465467
return cmd
466468
}
467469

470+
// kubernetesOneClicks creates the 1-click command.
471+
func kubernetesOneClicks() *Command {
472+
cmd := &Command{
473+
Command: &cobra.Command{
474+
Use: "1-click",
475+
Short: "Display commands that pertain to kubernetes 1-click applications",
476+
Long: "The commands under `doctl kubernetes 1-click` are for interacting with DigitalOcean Kubernetes 1-Click applications.",
477+
},
478+
}
479+
480+
CmdBuilder(cmd, RunKubernetesOneClickList, "list", "Retrieve a list of Kubernetes 1-Click applications", "Use this command to retrieve a list of Kubernetes 1-Click applications.", Writer,
481+
aliasOpt("ls"), displayerType(&displayers.OneClick{}))
482+
483+
return cmd
484+
}
485+
486+
// RunKubernetesOneClickList retrieves a list of 1-clicks for kubernetes.
487+
func RunKubernetesOneClickList(c *CmdConfig) error {
488+
oneClicks := c.OneClicks()
489+
oneClickList, err := oneClicks.List("kubernetes")
490+
if err != nil {
491+
return err
492+
}
493+
494+
items := &displayers.OneClick{OneClicks: oneClickList}
495+
496+
return c.Display(items)
497+
}
498+
468499
func kubernetesOptions() *Command {
469500
cmd := &Command{
470501
Command: &cobra.Command{

commands/kubernetes_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ var (
8080
},
8181
AuthInfos: make(map[string]*clientcmdapi.AuthInfo),
8282
}
83+
84+
testK8sOneClick = do.OneClick{
85+
OneClick: &godo.OneClick{
86+
Slug: "test-slug",
87+
Type: "droplet",
88+
},
89+
}
90+
91+
testK8sOneClickList = do.OneClicks{
92+
testOneClick,
93+
}
8394
)
8495

8596
type mockKubeconfigProvider struct {
@@ -118,6 +129,7 @@ func TestKubernetesCommand(t *testing.T) {
118129
assertCommandNames(t, cmd,
119130
"cluster",
120131
"options",
132+
"1-click",
121133
)
122134
}
123135

@@ -1102,3 +1114,11 @@ func Test_looksLikeUUID(t *testing.T) {
11021114
})
11031115
}
11041116
}
1117+
1118+
func TestK8sOneClickListNoType(t *testing.T) {
1119+
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
1120+
tm.oneClick.EXPECT().List("kubernetes").Return(testK8sOneClickList, nil)
1121+
err := RunKubernetesOneClickList(config)
1122+
assert.NoError(t, err)
1123+
})
1124+
}

0 commit comments

Comments
 (0)