diff --git a/internal/cmd/base/delete_test.go b/internal/cmd/base/delete_test.go index 6f33f0da..11ba9640 100644 --- a/internal/cmd/base/delete_test.go +++ b/internal/cmd/base/delete_test.go @@ -15,9 +15,9 @@ import ( var fakeDeleteCmd = &base.DeleteCmd{ ResourceNameSingular: "Fake resource", ResourceNamePlural: "Fake resources", - Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { + Delete: func(s state.State, cmd *cobra.Command, resource interface{}) (*hcloud.Action, error) { cmd.Println("Deleting fake resource") - return nil + return nil, nil }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { @@ -44,8 +44,8 @@ func TestDelete(t *testing.T) { }, "no flags multiple": { Args: []string{"delete", "123", "456", "789"}, - ExpOut: "Fetching fake resource\nDeleting fake resource\nFake resource 123 deleted\nFetching fake resource\n" + - "Deleting fake resource\nFake resource 456 deleted\nFetching fake resource\nDeleting fake resource\nFake resource 789 deleted\n", + ExpOut: "Fetching fake resource\nDeleting fake resource\nFetching fake resource\nDeleting fake resource\n" + + "Fetching fake resource\nDeleting fake resource\nFake resources 123, 456, 789 deleted\n", }, "quiet": { Args: []string{"delete", "123", "--quiet"}, diff --git a/internal/cmd/certificate/delete_test.go b/internal/cmd/certificate/delete_test.go index 4fe0056b..b48a2cc0 100644 --- a/internal/cmd/certificate/delete_test.go +++ b/internal/cmd/certificate/delete_test.go @@ -1,8 +1,6 @@ package certificate_test import ( - "fmt" - "strings" "testing" "github.com/golang/mock/gomock" @@ -63,12 +61,9 @@ func TestDeleteMultiple(t *testing.T) { }, } - expOutBuilder := strings.Builder{} - var names []string for _, cert := range certs { names = append(names, cert.Name) - expOutBuilder.WriteString(fmt.Sprintf("certificate %s deleted\n", cert.Name)) fx.Client.CertificateClient.EXPECT(). Get(gomock.Any(), cert.Name). Return(cert, nil, nil) @@ -78,9 +73,8 @@ func TestDeleteMultiple(t *testing.T) { } out, errOut, err := fx.Run(cmd, names) - expOut := expOutBuilder.String() assert.NoError(t, err) assert.Empty(t, errOut) - assert.Equal(t, expOut, out) + assert.Equal(t, "certificates test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/firewall/delete_test.go b/internal/cmd/firewall/delete_test.go index b78450d4..f74c2903 100644 --- a/internal/cmd/firewall/delete_test.go +++ b/internal/cmd/firewall/delete_test.go @@ -1,8 +1,6 @@ package firewall_test import ( - "fmt" - "strings" "testing" "github.com/golang/mock/gomock" @@ -63,12 +61,9 @@ func TestDeleteMultiple(t *testing.T) { }, } - expOutBuilder := strings.Builder{} - var names []string for _, fw := range firewalls { names = append(names, fw.Name) - expOutBuilder.WriteString(fmt.Sprintf("firewall %s deleted\n", fw.Name)) fx.Client.FirewallClient.EXPECT(). Get(gomock.Any(), fw.Name). Return(fw, nil, nil) @@ -78,9 +73,8 @@ func TestDeleteMultiple(t *testing.T) { } out, errOut, err := fx.Run(cmd, names) - expOut := expOutBuilder.String() assert.NoError(t, err) assert.Empty(t, errOut) - assert.Equal(t, expOut, out) + assert.Equal(t, "firewalls test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/floatingip/delete_test.go b/internal/cmd/floatingip/delete_test.go index afca2dcf..c8b84746 100644 --- a/internal/cmd/floatingip/delete_test.go +++ b/internal/cmd/floatingip/delete_test.go @@ -1,8 +1,6 @@ package floatingip_test import ( - "fmt" - "strings" "testing" "github.com/golang/mock/gomock" @@ -63,12 +61,9 @@ func TestDeleteMultiple(t *testing.T) { }, } - expOutBuilder := strings.Builder{} - var names []string for _, ip := range ips { names = append(names, ip.Name) - expOutBuilder.WriteString(fmt.Sprintf("Floating IP %s deleted\n", ip.Name)) fx.Client.FloatingIPClient.EXPECT(). Get(gomock.Any(), ip.Name). Return(ip, nil, nil) @@ -78,9 +73,8 @@ func TestDeleteMultiple(t *testing.T) { } out, errOut, err := fx.Run(cmd, names) - expOut := expOutBuilder.String() assert.NoError(t, err) assert.Empty(t, errOut) - assert.Equal(t, expOut, out) + assert.Equal(t, "Floating IPs test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/image/delete_test.go b/internal/cmd/image/delete_test.go index 70c954e3..59d0a1e7 100644 --- a/internal/cmd/image/delete_test.go +++ b/internal/cmd/image/delete_test.go @@ -1,8 +1,6 @@ package image_test import ( - "fmt" - "strings" "testing" "github.com/golang/mock/gomock" @@ -63,12 +61,9 @@ func TestDeleteMultiple(t *testing.T) { }, } - expOutBuilder := strings.Builder{} - var names []string for _, img := range images { names = append(names, img.Name) - expOutBuilder.WriteString(fmt.Sprintf("image %s deleted\n", img.Name)) fx.Client.ImageClient.EXPECT(). Get(gomock.Any(), img.Name). Return(img, nil, nil) @@ -78,9 +73,8 @@ func TestDeleteMultiple(t *testing.T) { } out, errOut, err := fx.Run(cmd, names) - expOut := expOutBuilder.String() assert.NoError(t, err) assert.Empty(t, errOut) - assert.Equal(t, expOut, out) + assert.Equal(t, "images test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/loadbalancer/delete_test.go b/internal/cmd/loadbalancer/delete_test.go index a770b30f..07695a4b 100644 --- a/internal/cmd/loadbalancer/delete_test.go +++ b/internal/cmd/loadbalancer/delete_test.go @@ -1,8 +1,6 @@ package loadbalancer_test import ( - "fmt" - "strings" "testing" "github.com/golang/mock/gomock" @@ -63,12 +61,9 @@ func TestDeleteMultiple(t *testing.T) { }, } - expOutBuilder := strings.Builder{} - var names []string for _, lb := range loadBalancers { names = append(names, lb.Name) - expOutBuilder.WriteString(fmt.Sprintf("Load Balancer %s deleted\n", lb.Name)) fx.Client.LoadBalancerClient.EXPECT(). Get(gomock.Any(), lb.Name). Return(lb, nil, nil) @@ -78,9 +73,8 @@ func TestDeleteMultiple(t *testing.T) { } out, errOut, err := fx.Run(cmd, names) - expOut := expOutBuilder.String() assert.NoError(t, err) assert.Empty(t, errOut) - assert.Equal(t, expOut, out) + assert.Equal(t, "Load Balancers test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/network/delete_test.go b/internal/cmd/network/delete_test.go index 39dba670..a563538c 100644 --- a/internal/cmd/network/delete_test.go +++ b/internal/cmd/network/delete_test.go @@ -1,8 +1,6 @@ package network_test import ( - "fmt" - "strings" "testing" "github.com/golang/mock/gomock" @@ -63,12 +61,9 @@ func TestDeleteMultiple(t *testing.T) { }, } - expOutBuilder := strings.Builder{} - var names []string for _, net := range networks { names = append(names, net.Name) - expOutBuilder.WriteString(fmt.Sprintf("Network %s deleted\n", net.Name)) fx.Client.NetworkClient.EXPECT(). Get(gomock.Any(), net.Name). Return(net, nil, nil) @@ -78,9 +73,8 @@ func TestDeleteMultiple(t *testing.T) { } out, errOut, err := fx.Run(cmd, names) - expOut := expOutBuilder.String() assert.NoError(t, err) assert.Empty(t, errOut) - assert.Equal(t, expOut, out) + assert.Equal(t, "Networks test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/placementgroup/delete_test.go b/internal/cmd/placementgroup/delete_test.go index ee248b56..647fbb73 100644 --- a/internal/cmd/placementgroup/delete_test.go +++ b/internal/cmd/placementgroup/delete_test.go @@ -1,8 +1,6 @@ package placementgroup_test import ( - "fmt" - "strings" "testing" "time" @@ -67,12 +65,9 @@ func TestDeleteMultiple(t *testing.T) { }, } - expOutBuilder := strings.Builder{} - var names []string for _, pg := range groups { names = append(names, pg.Name) - expOutBuilder.WriteString(fmt.Sprintf("placement group %s deleted\n", pg.Name)) fx.Client.PlacementGroupClient.EXPECT(). Get(gomock.Any(), pg.Name). Return(pg, nil, nil) @@ -82,9 +77,8 @@ func TestDeleteMultiple(t *testing.T) { } out, errOut, err := fx.Run(cmd, names) - expOut := expOutBuilder.String() assert.NoError(t, err) assert.Empty(t, errOut) - assert.Equal(t, expOut, out) + assert.Equal(t, "placement groups test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/primaryip/delete_test.go b/internal/cmd/primaryip/delete_test.go index c7aa31d0..ee19d549 100644 --- a/internal/cmd/primaryip/delete_test.go +++ b/internal/cmd/primaryip/delete_test.go @@ -1,8 +1,6 @@ package primaryip_test import ( - "fmt" - "strings" "testing" "github.com/golang/mock/gomock" @@ -71,12 +69,9 @@ func TestDeleteMultiple(t *testing.T) { }, } - expOutBuilder := strings.Builder{} - var names []string for _, ip := range ips { names = append(names, ip.Name) - expOutBuilder.WriteString(fmt.Sprintf("Primary IP %s deleted\n", ip.Name)) fx.Client.PrimaryIPClient.EXPECT(). Get(gomock.Any(), ip.Name). Return(ip, nil, nil) @@ -86,9 +81,8 @@ func TestDeleteMultiple(t *testing.T) { } out, errOut, err := fx.Run(cmd, names) - expOut := expOutBuilder.String() assert.NoError(t, err) assert.Empty(t, errOut) - assert.Equal(t, expOut, out) + assert.Equal(t, "Primary IPs test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/server/delete_test.go b/internal/cmd/server/delete_test.go index 21349098..f24eed80 100644 --- a/internal/cmd/server/delete_test.go +++ b/internal/cmd/server/delete_test.go @@ -1,8 +1,6 @@ package server_test import ( - "fmt" - "strings" "testing" "github.com/golang/mock/gomock" @@ -67,12 +65,12 @@ func TestDeleteMultiple(t *testing.T) { }, } - expOutBuilder := strings.Builder{} - - var names []string + var ( + names []string + actions []*hcloud.Action + ) for i, srv := range servers { names = append(names, srv.Name) - expOutBuilder.WriteString(fmt.Sprintf("Server %s deleted\n", srv.Name)) fx.Client.ServerClient.EXPECT(). Get(gomock.Any(), srv.Name). Return(srv, nil, nil) @@ -81,14 +79,13 @@ func TestDeleteMultiple(t *testing.T) { Return(&hcloud.ServerDeleteResult{ Action: &hcloud.Action{ID: int64(i)}, }, nil, nil) - fx.ActionWaiter.EXPECT(). - WaitForActions(gomock.Any(), gomock.Any(), &hcloud.Action{ID: int64(i)}) + actions = append(actions, &hcloud.Action{ID: int64(i)}) } + fx.ActionWaiter.EXPECT().WaitForActions(gomock.Any(), gomock.Any(), actions) out, errOut, err := fx.Run(cmd, names) - expOut := expOutBuilder.String() assert.NoError(t, err) assert.Empty(t, errOut) - assert.Equal(t, expOut, out) + assert.Equal(t, "Servers test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/sshkey/delete_test.go b/internal/cmd/sshkey/delete_test.go index 0c557bcf..a5747e9c 100644 --- a/internal/cmd/sshkey/delete_test.go +++ b/internal/cmd/sshkey/delete_test.go @@ -1,8 +1,6 @@ package sshkey_test import ( - "fmt" - "strings" "testing" "github.com/golang/mock/gomock" @@ -63,12 +61,9 @@ func TestDeleteMultiple(t *testing.T) { }, } - expOutBuilder := strings.Builder{} - var names []string for _, key := range keys { names = append(names, key.Name) - expOutBuilder.WriteString(fmt.Sprintf("SSH Key %s deleted\n", key.Name)) fx.Client.SSHKeyClient.EXPECT(). Get(gomock.Any(), key.Name). Return(key, nil, nil) @@ -78,9 +73,8 @@ func TestDeleteMultiple(t *testing.T) { } out, errOut, err := fx.Run(cmd, names) - expOut := expOutBuilder.String() assert.NoError(t, err) assert.Empty(t, errOut) - assert.Equal(t, expOut, out) + assert.Equal(t, "SSH Keys test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/volume/delete_test.go b/internal/cmd/volume/delete_test.go index 30ffdffd..453a5ab4 100644 --- a/internal/cmd/volume/delete_test.go +++ b/internal/cmd/volume/delete_test.go @@ -1,8 +1,6 @@ package volume_test import ( - "fmt" - "strings" "testing" "github.com/golang/mock/gomock" @@ -63,12 +61,9 @@ func TestDeleteMultiple(t *testing.T) { }, } - expOutBuilder := strings.Builder{} - var names []string for _, v := range volumes { names = append(names, v.Name) - expOutBuilder.WriteString(fmt.Sprintf("Volume %s deleted\n", v.Name)) fx.Client.VolumeClient.EXPECT(). Get(gomock.Any(), v.Name). Return(v, nil, nil) @@ -78,9 +73,8 @@ func TestDeleteMultiple(t *testing.T) { } out, errOut, err := fx.Run(cmd, names) - expOut := expOutBuilder.String() assert.NoError(t, err) assert.Empty(t, errOut) - assert.Equal(t, expOut, out) + assert.Equal(t, "Volumes test1, test2, test3 deleted\n", out) }