11//
22// DISCLAIMER
33//
4- // Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+ // Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55//
66// Licensed under the Apache License, Version 2.0 (the "License");
77// you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ package crd
2222
2323import (
2424 "context"
25+ "encoding/json"
2526 "testing"
2627 "time"
2728
@@ -51,6 +52,11 @@ func dropLogMessages(t *testing.T, s tests.LogScanner) map[string]string {
5152 lines [p ] = m
5253 }
5354
55+ d , err := json .Marshal (lines )
56+ require .NoError (t , err )
57+
58+ t .Logf ("Lines: %s" , string (d ))
59+
5460 return lines
5561}
5662
@@ -133,27 +139,88 @@ func runApply(t *testing.T, crdOpts map[string]crds.CRDOptions) {
133139
134140 t .Run ("Create" , func (t * testing.T ) {
135141 d := crds .AllDefinitions ()[0 ]
142+
136143 q := d .CRD .DeepCopy ()
137144 q .Labels = map [string ]string {
138- Version : string ( d . Version ) ,
145+ Version : "version" ,
139146 }
140147 _ , err := c .KubernetesExtensions ().ApiextensionsV1 ().CustomResourceDefinitions ().Create (context .Background (), q , meta.CreateOptions {})
141148 require .NoError (t , err )
142149 })
143150
144- t .Run ("Ensure" , func (t * testing.T ) {
151+ t .Run ("Ensure without schema" , func (t * testing.T ) {
152+ crdOpts = updateMap (t , crdOpts , func (t * testing.T , key string , el crds.CRDOptions ) crds.CRDOptions {
153+ el .WithSchema = false
154+ return el
155+ })
156+
145157 require .NoError (t , EnsureCRDWithOptions (context .Background (), c , EnsureCRDOptions {IgnoreErrors : false , CRDOptions : crdOpts }))
146158
147159 for k , v := range dropLogMessages (t , s ) {
148160 t .Run (k , func (t * testing.T ) {
149161 if k == crds .AllDefinitions ()[0 ].CRD .GetName () {
150- require .Equal (t , "CRD Update not required " , v )
162+ require .Equal (t , "CRD Updated " , v )
151163 } else {
152164 require .Equal (t , "CRD Created" , v )
153165 }
154166 })
155167 }
156168 })
169+
170+ t .Run ("Rerun without schema" , func (t * testing.T ) {
171+ crdOpts = updateMap (t , crdOpts , func (t * testing.T , key string , el crds.CRDOptions ) crds.CRDOptions {
172+ el .WithSchema = false
173+ return el
174+ })
175+
176+ require .NoError (t , EnsureCRDWithOptions (context .Background (), c , EnsureCRDOptions {IgnoreErrors : false , CRDOptions : crdOpts }))
177+
178+ for k , v := range dropLogMessages (t , s ) {
179+ t .Run (k , func (t * testing.T ) {
180+ require .Equal (t , "CRD Update not required" , v )
181+ })
182+ }
183+ })
184+
185+ t .Run ("Ensure with schema" , func (t * testing.T ) {
186+ crdOpts = updateMap (t , crdOpts , func (t * testing.T , key string , el crds.CRDOptions ) crds.CRDOptions {
187+ el .WithSchema = true
188+ return el
189+ })
190+
191+ require .NoError (t , EnsureCRDWithOptions (context .Background (), c , EnsureCRDOptions {IgnoreErrors : false , CRDOptions : crdOpts }))
192+
193+ for k , v := range dropLogMessages (t , s ) {
194+ t .Run (k , func (t * testing.T ) {
195+ require .Equal (t , "CRD Updated" , v )
196+ })
197+ }
198+ })
199+
200+ t .Run ("Rerun with schema" , func (t * testing.T ) {
201+ crdOpts = updateMap (t , crdOpts , func (t * testing.T , key string , el crds.CRDOptions ) crds.CRDOptions {
202+ el .WithSchema = true
203+ return el
204+ })
205+
206+ require .NoError (t , EnsureCRDWithOptions (context .Background (), c , EnsureCRDOptions {IgnoreErrors : false , CRDOptions : crdOpts }))
207+
208+ for k , v := range dropLogMessages (t , s ) {
209+ t .Run (k , func (t * testing.T ) {
210+ require .Equal (t , "CRD Update not required" , v )
211+ })
212+ }
213+ })
157214 })
158215 })
159216}
217+
218+ func updateMap [T comparable ](t * testing.T , in map [string ]T , f func (t * testing.T , key string , el T ) T ) map [string ]T {
219+ r := make (map [string ]T , len (in ))
220+
221+ for k , v := range in {
222+ r [k ] = f (t , k , v )
223+ }
224+
225+ return r
226+ }
0 commit comments