@@ -22,6 +22,7 @@ import (
22
22
23
23
appsv1 "k8s.io/api/apps/v1"
24
24
corev1 "k8s.io/api/core/v1"
25
+ "k8s.io/apimachinery/pkg/api/errors"
25
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
27
"k8s.io/apimachinery/pkg/runtime"
27
28
"k8s.io/apimachinery/pkg/types"
@@ -154,6 +155,56 @@ var _ = Describe("Fake client", func() {
154
155
Expect (list .Items ).To (HaveLen (1 ))
155
156
Expect (list .Items ).To (ConsistOf (* dep2 ))
156
157
})
158
+
159
+ Context ("with the DryRun option" , func () {
160
+ It ("should not create a new object" , func () {
161
+ By ("Creating a new configmap with DryRun" )
162
+ newcm := & corev1.ConfigMap {
163
+ ObjectMeta : metav1.ObjectMeta {
164
+ Name : "new-test-cm" ,
165
+ Namespace : "ns2" ,
166
+ },
167
+ }
168
+ err := cl .Create (nil , newcm , client .CreateDryRunAll ())
169
+ Expect (err ).To (BeNil ())
170
+
171
+ By ("Getting the new configmap" )
172
+ namespacedName := types.NamespacedName {
173
+ Name : "new-test-cm" ,
174
+ Namespace : "ns2" ,
175
+ }
176
+ obj := & corev1.ConfigMap {}
177
+ err = cl .Get (nil , namespacedName , obj )
178
+ Expect (err ).To (HaveOccurred ())
179
+ Expect (errors .IsNotFound (err )).To (BeTrue ())
180
+ Expect (obj ).NotTo (Equal (newcm ))
181
+ })
182
+
183
+ It ("should not Update the object" , func () {
184
+ By ("Updating a new configmap with DryRun" )
185
+ newcm := & corev1.ConfigMap {
186
+ ObjectMeta : metav1.ObjectMeta {
187
+ Name : "test-cm" ,
188
+ Namespace : "ns2" ,
189
+ },
190
+ Data : map [string ]string {
191
+ "test-key" : "new-value" ,
192
+ },
193
+ }
194
+ err := cl .Update (nil , newcm , client .UpdateDryRunAll ())
195
+ Expect (err ).To (BeNil ())
196
+
197
+ By ("Getting the new configmap" )
198
+ namespacedName := types.NamespacedName {
199
+ Name : "test-cm" ,
200
+ Namespace : "ns2" ,
201
+ }
202
+ obj := & corev1.ConfigMap {}
203
+ err = cl .Get (nil , namespacedName , obj )
204
+ Expect (err ).To (BeNil ())
205
+ Expect (obj ).To (Equal (cm ))
206
+ })
207
+ })
157
208
}
158
209
159
210
Context ("with default scheme.Scheme" , func () {
0 commit comments