|
| 1 | +/* |
| 2 | +Copyright 2018 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package client_test |
| 18 | + |
| 19 | +import ( |
| 20 | + . "github.com/onsi/ginkgo" |
| 21 | + . "github.com/onsi/gomega" |
| 22 | + |
| 23 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 24 | + "k8s.io/apimachinery/pkg/fields" |
| 25 | + "k8s.io/apimachinery/pkg/labels" |
| 26 | + utilpointer "k8s.io/utils/pointer" |
| 27 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 28 | +) |
| 29 | + |
| 30 | +var _ = Describe("ListOptions", func() { |
| 31 | + It("Should set LabelSelector", func() { |
| 32 | + labelSelector, err := labels.Parse("a=b") |
| 33 | + Expect(err).NotTo(HaveOccurred()) |
| 34 | + o := &client.ListOptions{LabelSelector: labelSelector} |
| 35 | + newListOpts := &client.ListOptions{} |
| 36 | + o.ApplyToList(newListOpts) |
| 37 | + Expect(newListOpts).To(Equal(o)) |
| 38 | + }) |
| 39 | + It("Should set FieldSelector", func() { |
| 40 | + o := &client.ListOptions{FieldSelector: fields.Nothing()} |
| 41 | + newListOpts := &client.ListOptions{} |
| 42 | + o.ApplyToList(newListOpts) |
| 43 | + Expect(newListOpts).To(Equal(o)) |
| 44 | + }) |
| 45 | + It("Should set Namespace", func() { |
| 46 | + o := &client.ListOptions{Namespace: "my-ns"} |
| 47 | + newListOpts := &client.ListOptions{} |
| 48 | + o.ApplyToList(newListOpts) |
| 49 | + Expect(newListOpts).To(Equal(o)) |
| 50 | + }) |
| 51 | + It("Should set Raw", func() { |
| 52 | + o := &client.ListOptions{Raw: &metav1.ListOptions{FieldSelector: "Hans"}} |
| 53 | + newListOpts := &client.ListOptions{} |
| 54 | + o.ApplyToList(newListOpts) |
| 55 | + Expect(newListOpts).To(Equal(o)) |
| 56 | + }) |
| 57 | + It("Should not set anything", func() { |
| 58 | + o := &client.ListOptions{} |
| 59 | + newListOpts := &client.ListOptions{} |
| 60 | + o.ApplyToList(newListOpts) |
| 61 | + Expect(newListOpts).To(Equal(o)) |
| 62 | + }) |
| 63 | +}) |
| 64 | + |
| 65 | +var _ = Describe("CreateOptions", func() { |
| 66 | + It("Should set DryRun", func() { |
| 67 | + o := &client.CreateOptions{DryRun: []string{"Hello", "Theodore"}} |
| 68 | + newCreatOpts := &client.CreateOptions{} |
| 69 | + o.ApplyToCreate(newCreatOpts) |
| 70 | + Expect(newCreatOpts).To(Equal(o)) |
| 71 | + }) |
| 72 | + It("Should set FieldManager", func() { |
| 73 | + o := &client.CreateOptions{FieldManager: "FieldManager"} |
| 74 | + newCreatOpts := &client.CreateOptions{} |
| 75 | + o.ApplyToCreate(newCreatOpts) |
| 76 | + Expect(newCreatOpts).To(Equal(o)) |
| 77 | + }) |
| 78 | + It("Should set Raw", func() { |
| 79 | + o := &client.CreateOptions{Raw: &metav1.CreateOptions{DryRun: []string{"Bye", "Theodore"}}} |
| 80 | + newCreatOpts := &client.CreateOptions{} |
| 81 | + o.ApplyToCreate(newCreatOpts) |
| 82 | + Expect(newCreatOpts).To(Equal(o)) |
| 83 | + }) |
| 84 | + It("Should not set anything", func() { |
| 85 | + o := &client.CreateOptions{} |
| 86 | + newCreatOpts := &client.CreateOptions{} |
| 87 | + o.ApplyToCreate(newCreatOpts) |
| 88 | + Expect(newCreatOpts).To(Equal(o)) |
| 89 | + }) |
| 90 | +}) |
| 91 | + |
| 92 | +var _ = Describe("DeleteOptions", func() { |
| 93 | + It("Should set GracePeriodSeconds", func() { |
| 94 | + o := &client.DeleteOptions{GracePeriodSeconds: utilpointer.Int64Ptr(42)} |
| 95 | + newDeleteOpts := &client.DeleteOptions{} |
| 96 | + o.ApplyToDelete(newDeleteOpts) |
| 97 | + Expect(newDeleteOpts).To(Equal(o)) |
| 98 | + }) |
| 99 | + It("Should set Preconditions", func() { |
| 100 | + o := &client.DeleteOptions{Preconditions: &metav1.Preconditions{}} |
| 101 | + newDeleteOpts := &client.DeleteOptions{} |
| 102 | + o.ApplyToDelete(newDeleteOpts) |
| 103 | + Expect(newDeleteOpts).To(Equal(o)) |
| 104 | + }) |
| 105 | + It("Should set PropagationPolicy", func() { |
| 106 | + policy := metav1.DeletePropagationBackground |
| 107 | + o := &client.DeleteOptions{PropagationPolicy: &policy} |
| 108 | + newDeleteOpts := &client.DeleteOptions{} |
| 109 | + o.ApplyToDelete(newDeleteOpts) |
| 110 | + Expect(newDeleteOpts).To(Equal(o)) |
| 111 | + }) |
| 112 | + It("Should set Raw", func() { |
| 113 | + o := &client.DeleteOptions{Raw: &metav1.DeleteOptions{}} |
| 114 | + newDeleteOpts := &client.DeleteOptions{} |
| 115 | + o.ApplyToDelete(newDeleteOpts) |
| 116 | + Expect(newDeleteOpts).To(Equal(o)) |
| 117 | + }) |
| 118 | + It("Should set DryRun", func() { |
| 119 | + o := &client.DeleteOptions{DryRun: []string{"Hello", "Pippa"}} |
| 120 | + newDeleteOpts := &client.DeleteOptions{} |
| 121 | + o.ApplyToDelete(newDeleteOpts) |
| 122 | + Expect(newDeleteOpts).To(Equal(o)) |
| 123 | + }) |
| 124 | + It("Should not set anything", func() { |
| 125 | + o := &client.DeleteOptions{} |
| 126 | + newDeleteOpts := &client.DeleteOptions{} |
| 127 | + o.ApplyToDelete(newDeleteOpts) |
| 128 | + Expect(newDeleteOpts).To(Equal(o)) |
| 129 | + }) |
| 130 | +}) |
| 131 | + |
| 132 | +var _ = Describe("UpdateOptions", func() { |
| 133 | + It("Should set DryRun", func() { |
| 134 | + o := &client.UpdateOptions{DryRun: []string{"Bye", "Pippa"}} |
| 135 | + newUpdateOpts := &client.UpdateOptions{} |
| 136 | + o.ApplyToUpdate(newUpdateOpts) |
| 137 | + Expect(newUpdateOpts).To(Equal(o)) |
| 138 | + }) |
| 139 | + It("Should set FieldManager", func() { |
| 140 | + o := &client.UpdateOptions{FieldManager: "Hello Boris"} |
| 141 | + newUpdateOpts := &client.UpdateOptions{} |
| 142 | + o.ApplyToUpdate(newUpdateOpts) |
| 143 | + Expect(newUpdateOpts).To(Equal(o)) |
| 144 | + }) |
| 145 | + It("Should set Raw", func() { |
| 146 | + o := &client.UpdateOptions{Raw: &metav1.UpdateOptions{}} |
| 147 | + newUpdateOpts := &client.UpdateOptions{} |
| 148 | + o.ApplyToUpdate(newUpdateOpts) |
| 149 | + Expect(newUpdateOpts).To(Equal(o)) |
| 150 | + }) |
| 151 | + It("Should not set anything", func() { |
| 152 | + o := &client.UpdateOptions{} |
| 153 | + newUpdateOpts := &client.UpdateOptions{} |
| 154 | + o.ApplyToUpdate(newUpdateOpts) |
| 155 | + Expect(newUpdateOpts).To(Equal(o)) |
| 156 | + }) |
| 157 | +}) |
| 158 | + |
| 159 | +var _ = Describe("PatchOptions", func() { |
| 160 | + It("Should set DryRun", func() { |
| 161 | + o := &client.PatchOptions{DryRun: []string{"Bye", "Boris"}} |
| 162 | + newPatchOpts := &client.PatchOptions{} |
| 163 | + o.ApplyToPatch(newPatchOpts) |
| 164 | + Expect(newPatchOpts).To(Equal(o)) |
| 165 | + }) |
| 166 | + It("Should set Force", func() { |
| 167 | + o := &client.PatchOptions{Force: utilpointer.BoolPtr(true)} |
| 168 | + newPatchOpts := &client.PatchOptions{} |
| 169 | + o.ApplyToPatch(newPatchOpts) |
| 170 | + Expect(newPatchOpts).To(Equal(o)) |
| 171 | + }) |
| 172 | + It("Should set FieldManager", func() { |
| 173 | + o := &client.PatchOptions{FieldManager: "Hello Julian"} |
| 174 | + newPatchOpts := &client.PatchOptions{} |
| 175 | + o.ApplyToPatch(newPatchOpts) |
| 176 | + Expect(newPatchOpts).To(Equal(o)) |
| 177 | + }) |
| 178 | + It("Should set Raw", func() { |
| 179 | + o := &client.PatchOptions{Raw: &metav1.PatchOptions{}} |
| 180 | + newPatchOpts := &client.PatchOptions{} |
| 181 | + o.ApplyToPatch(newPatchOpts) |
| 182 | + Expect(newPatchOpts).To(Equal(o)) |
| 183 | + }) |
| 184 | + It("Should not set anything", func() { |
| 185 | + o := &client.PatchOptions{} |
| 186 | + newPatchOpts := &client.PatchOptions{} |
| 187 | + o.ApplyToPatch(newPatchOpts) |
| 188 | + Expect(newPatchOpts).To(Equal(o)) |
| 189 | + }) |
| 190 | +}) |
| 191 | + |
| 192 | +var _ = Describe("DeleteAllOfOptions", func() { |
| 193 | + It("Should set ListOptions", func() { |
| 194 | + o := &client.DeleteAllOfOptions{ListOptions: client.ListOptions{Raw: &metav1.ListOptions{}}} |
| 195 | + newDeleteAllOfOpts := &client.DeleteAllOfOptions{} |
| 196 | + o.ApplyToDeleteAllOf(newDeleteAllOfOpts) |
| 197 | + Expect(newDeleteAllOfOpts).To(Equal(o)) |
| 198 | + }) |
| 199 | + It("Should set DeleleteOptions", func() { |
| 200 | + o := &client.DeleteAllOfOptions{DeleteOptions: client.DeleteOptions{GracePeriodSeconds: utilpointer.Int64Ptr(44)}} |
| 201 | + newDeleteAllOfOpts := &client.DeleteAllOfOptions{} |
| 202 | + o.ApplyToDeleteAllOf(newDeleteAllOfOpts) |
| 203 | + Expect(newDeleteAllOfOpts).To(Equal(o)) |
| 204 | + }) |
| 205 | +}) |
0 commit comments