@@ -70,7 +70,7 @@ var _ = Describe("Client", func() {
7070 BeforeEach (func (done Done ) {
7171 atomic .AddUint64 (& count , 1 )
7272 dep = & appsv1.Deployment {
73- ObjectMeta : metav1.ObjectMeta {Name : fmt .Sprintf ("deployment-name-%v" , count ), Namespace : ns },
73+ ObjectMeta : metav1.ObjectMeta {Name : fmt .Sprintf ("deployment-name-%v" , count ), Namespace : ns , Labels : map [ string ] string { "app" : fmt . Sprintf ( "bar-%v" , count )} },
7474 Spec : appsv1.DeploymentSpec {
7575 Replicas : & replicaCount ,
7676 Selector : & metav1.LabelSelector {
@@ -898,6 +898,37 @@ var _ = Describe("Client", func() {
898898 PIt ("should fail if the GVK cannot be mapped to a Resource" , func () {
899899
900900 })
901+
902+ It ("should delete a collection of objects" , func (done Done ) {
903+ cl , err := client .New (cfg , client.Options {})
904+ Expect (err ).NotTo (HaveOccurred ())
905+ Expect (cl ).NotTo (BeNil ())
906+
907+ By ("initially creating two Deployments" )
908+
909+ dep2 := dep .DeepCopy ()
910+ dep2 .Name = dep2 .Name + "-2"
911+
912+ dep , err = clientset .AppsV1 ().Deployments (ns ).Create (dep )
913+ Expect (err ).NotTo (HaveOccurred ())
914+ dep2 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep2 )
915+ Expect (err ).NotTo (HaveOccurred ())
916+
917+ depName := dep .Name
918+ dep2Name := dep2 .Name
919+
920+ By ("deleting Deployments" )
921+ err = cl .DeleteAllOf (context .TODO (), dep , client .InNamespace (ns ), client .MatchingLabels (dep .ObjectMeta .Labels ))
922+ Expect (err ).NotTo (HaveOccurred ())
923+
924+ By ("validating the Deployment no longer exists" )
925+ _ , err = clientset .AppsV1 ().Deployments (ns ).Get (depName , metav1.GetOptions {})
926+ Expect (err ).To (HaveOccurred ())
927+ _ , err = clientset .AppsV1 ().Deployments (ns ).Get (dep2Name , metav1.GetOptions {})
928+ Expect (err ).To (HaveOccurred ())
929+
930+ close (done )
931+ })
901932 })
902933 Context ("with unstructured objects" , func () {
903934 It ("should delete an existing object from a go struct" , func (done Done ) {
@@ -974,6 +1005,44 @@ var _ = Describe("Client", func() {
9741005
9751006 close (done )
9761007 })
1008+
1009+ It ("should delete a collection of object" , func (done Done ) {
1010+ cl , err := client .New (cfg , client.Options {})
1011+ Expect (err ).NotTo (HaveOccurred ())
1012+ Expect (cl ).NotTo (BeNil ())
1013+
1014+ By ("initially creating two Deployments" )
1015+
1016+ dep2 := dep .DeepCopy ()
1017+ dep2 .Name = dep2 .Name + "-2"
1018+
1019+ dep , err = clientset .AppsV1 ().Deployments (ns ).Create (dep )
1020+ Expect (err ).NotTo (HaveOccurred ())
1021+ dep2 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep2 )
1022+ Expect (err ).NotTo (HaveOccurred ())
1023+
1024+ depName := dep .Name
1025+ dep2Name := dep2 .Name
1026+
1027+ By ("deleting Deployments" )
1028+ u := & unstructured.Unstructured {}
1029+ Expect (scheme .Convert (dep , u , nil )).To (Succeed ())
1030+ u .SetGroupVersionKind (schema.GroupVersionKind {
1031+ Group : "apps" ,
1032+ Kind : "Deployment" ,
1033+ Version : "v1" ,
1034+ })
1035+ err = cl .DeleteAllOf (context .TODO (), u , client .InNamespace (ns ), client .MatchingLabels (dep .ObjectMeta .Labels ))
1036+ Expect (err ).NotTo (HaveOccurred ())
1037+
1038+ By ("validating the Deployment no longer exists" )
1039+ _ , err = clientset .AppsV1 ().Deployments (ns ).Get (depName , metav1.GetOptions {})
1040+ Expect (err ).To (HaveOccurred ())
1041+ _ , err = clientset .AppsV1 ().Deployments (ns ).Get (dep2Name , metav1.GetOptions {})
1042+ Expect (err ).To (HaveOccurred ())
1043+
1044+ close (done )
1045+ })
9771046 })
9781047 })
9791048
@@ -1994,6 +2063,10 @@ var _ = Describe("Client", func() {
19942063 PIt ("should fail if the object doesn't have meta" , func () {
19952064
19962065 })
2066+
2067+ PIt ("should filter results by namespace selector" , func () {
2068+
2069+ })
19972070 })
19982071 })
19992072
@@ -2072,6 +2145,34 @@ var _ = Describe("Client", func() {
20722145 })
20732146 })
20742147
2148+ Describe ("DeleteCollectionOptions" , func () {
2149+ It ("should be convertable to list options" , func () {
2150+ gp := int64 (1 )
2151+ do := & client.DeleteAllOfOptions {}
2152+ do .ApplyOptions ([]client.DeleteAllOfOption {
2153+ client .GracePeriodSeconds (gp ),
2154+ client.MatchingLabels {"foo" : "bar" },
2155+ })
2156+
2157+ listOpts := do .AsListOptions ()
2158+ Expect (listOpts ).NotTo (BeNil ())
2159+ Expect (listOpts .LabelSelector ).To (Equal ("foo=bar" ))
2160+ })
2161+
2162+ It ("should be convertable to delete options" , func () {
2163+ gp := int64 (1 )
2164+ do := & client.DeleteAllOfOptions {}
2165+ do .ApplyOptions ([]client.DeleteAllOfOption {
2166+ client .GracePeriodSeconds (gp ),
2167+ client.MatchingLabels {"foo" : "bar" },
2168+ })
2169+
2170+ deleteOpts := do .AsDeleteOptions ()
2171+ Expect (deleteOpts ).NotTo (BeNil ())
2172+ Expect (deleteOpts .GracePeriodSeconds ).To (Equal (& gp ))
2173+ })
2174+ })
2175+
20752176 Describe ("ListOptions" , func () {
20762177 It ("should be convertable to metav1.ListOptions" , func () {
20772178 lo := (& client.ListOptions {}).ApplyOptions ([]client.ListOption {
@@ -2105,6 +2206,13 @@ var _ = Describe("Client", func() {
21052206 Expect (lo ).NotTo (BeNil ())
21062207 Expect (lo .Namespace ).To (Equal ("test" ))
21072208 })
2209+
2210+ It ("should produce empty metav1.ListOptions if nil" , func () {
2211+ var do * client.ListOptions
2212+ Expect (do .AsListOptions ()).To (Equal (& metav1.ListOptions {}))
2213+ do = & client.ListOptions {}
2214+ Expect (do .AsListOptions ()).To (Equal (& metav1.ListOptions {}))
2215+ })
21082216 })
21092217
21102218 Describe ("UpdateOptions" , func () {
0 commit comments