Skip to content

Commit

Permalink
add api DeletePodListByLabel
Browse files Browse the repository at this point in the history
Signed-off-by: tao.yang <[email protected]>
  • Loading branch information
ty-dc committed Aug 16, 2024
1 parent 71bf7b1 commit 6e0c3c5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
17 changes: 17 additions & 0 deletions framework/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,20 @@ func (f *Framework) WaitAllPodUntilRunning(ctx context.Context) error {
}
}
}

func (f *Framework) DeletePodListByLabel(label map[string]string) error {
if label == nil {
return ErrWrongInput
}

podList, err := f.GetPodListByLabel(label)
if err != nil {
return err
}

if len(podList.Items) == 0 {
return nil
}

return f.DeletePodList(podList)
}
19 changes: 19 additions & 0 deletions framework/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,23 @@ var _ = Describe("test pod", Label("pod"), func() {
err11 := f.DeletePodUntilFinish(podName, "", ctx4, opts4)
Expect(err11).To(HaveOccurred())
})

Describe("DeletePodListByLabel", func() {

It("label is nil", func() {
err := f.DeletePodListByLabel(nil)
Expect(err).To(MatchError(e2e.ErrWrongInput))
})

It("succeed to delete PodList via label", func() {
pod := generateExamplePodYaml(podName, namespace, label, "Running")

// create pod
err := f.CreatePod(pod)
Expect(err).NotTo(HaveOccurred())

err = f.DeletePodListByLabel(label)
Expect(err).NotTo(HaveOccurred())
})
})
})

0 comments on commit 6e0c3c5

Please sign in to comment.