Skip to content

Commit c3af367

Browse files
committed
update delete tests
1 parent 5b0855c commit c3af367

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

cmd/kops/delete_instancegroup_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ func TestRunDeleteInstanceGroup(t *testing.T) {
6969

7070
ig := testutils.BuildMinimalNodeInstanceGroup("test-ig")
7171

72-
instanceName := "a-test-ig-test-k8s-io"
7372
igm := &compute.InstanceGroupManager{
74-
Name: instanceName,
73+
Name: "a-test-ig-test-k8s-io",
7574
Zone: "us-test1-a",
7675
InstanceTemplate: template.SelfLink,
7776
}
@@ -90,6 +89,10 @@ func TestRunDeleteInstanceGroup(t *testing.T) {
9089
Force: false,
9190
}
9291

92+
// Simulate missing Instance
93+
_, err = cloud.Compute().Instances().Delete(cloud.Project(), igm.Zone, igm.Name)
94+
assert.NoError(t, err, "error deleting Instance")
95+
9396
assert.ErrorContains(t, RunDeleteInstanceGroup(ctx, f, &stdout, options), "error getting Instance")
9497

9598
// Verify that the instance group was not deleted

pkg/instancegroups/delete_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import (
2525
"k8s.io/apimachinery/pkg/api/errors"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/kops/cmd/kops/util"
28+
api "k8s.io/kops/pkg/apis/kops"
2829
"k8s.io/kops/pkg/testutils"
30+
"k8s.io/kops/upup/pkg/fi"
2931
)
3032

3133
func TestDeleteInstanceGroup(t *testing.T) {
@@ -85,6 +87,10 @@ func TestDeleteInstanceGroup(t *testing.T) {
8587
Clientset: clientset,
8688
}
8789

90+
// Simulate missing Instance
91+
_, err = cloud.Compute().Instances().Delete(cloud.Project(), igm.Zone, igm.Name)
92+
assert.NoError(t, err, "error deleting Instance")
93+
8894
assert.ErrorContains(t, deleteIG.DeleteInstanceGroup(&ig, false /*force*/), "error getting Instance")
8995
// Verify that the instance group was not deleted
9096
_, err = clientset.InstanceGroupsFor(cluster).Get(ctx, ig.Name, metav1.GetOptions{})
@@ -95,4 +101,9 @@ func TestDeleteInstanceGroup(t *testing.T) {
95101
_, err = clientset.InstanceGroupsFor(cluster).Get(ctx, ig.Name, metav1.GetOptions{})
96102
assert.Error(t, err)
97103
assert.True(t, errors.IsNotFound(err), "unexpected error when getting deleted instance group: %v", err)
104+
105+
// Verify that the cloud resources for the InstanceGroup are also deleted
106+
groups, err := cloud.GetCloudGroups(cluster, []*api.InstanceGroup{&ig}, &fi.GetCloudGroupsOptions{}, nil)
107+
assert.NoError(t, err)
108+
assert.Len(t, groups, 0)
98109
}

0 commit comments

Comments
 (0)