@@ -137,45 +137,43 @@ func (a Applier) prepareResources(t *testing.T, decoder *yaml.YAMLOrJSONDecoder)
137
137
}
138
138
139
139
func (a Applier ) MustApplyObjectsWithCleanup (t * testing.T , c client.Client , timeoutConfig config.TimeoutConfig , resources []client.Object , cleanup bool ) {
140
- fmt .Print ("heyyy" )
141
- for _ , resource := range resources {
142
- resource := resource
143
-
144
- ctx , cancel := context .WithTimeout (context .Background (), timeoutConfig .CreateTimeout )
145
- defer cancel ()
146
-
147
- t .Logf ("Creating/Updating %s %s" , resource .GetName (), resource .GetObjectKind ().GroupVersionKind ().Kind )
148
-
149
- // Check if the resource exists
150
- existingResource := resource .DeepCopyObject ().(client.Object )
151
- err := c .Get (ctx , types.NamespacedName {Name : resource .GetName (), Namespace : resource .GetNamespace ()}, existingResource )
152
- if err != nil {
153
- if ! apierrors .IsNotFound (err ) {
154
- t .Logf ("error checking resource: %s %s" , resource .GetName (), resource .GetObjectKind ().GroupVersionKind ().Kind )
155
- require .NoError (t , err , "error checking resource" )
156
- }
157
-
158
- // Resource doesn't exist, create it
159
- err = c .Create (ctx , resource )
160
- require .NoError (t , err , "error creating resource" )
161
- } else {
162
- // Resource exists, update it
163
- err = c .Update (ctx , resource )
164
- require .NoError (t , err , "error updating resource" )
165
- }
166
-
167
- if cleanup {
168
- t .Cleanup (func () {
169
- ctx , cancel = context .WithTimeout (context .Background (), timeoutConfig .DeleteTimeout )
170
- defer cancel ()
171
- t .Logf ("Deleting %s %s" , resource .GetName (), resource .GetObjectKind ().GroupVersionKind ().Kind )
172
- err = c .Delete (ctx , resource )
173
- require .NoErrorf (t , err , "error deleting resource" )
174
- })
175
- }
176
- }
177
- }
140
+ for _ , resource := range resources {
141
+ resource := resource
142
+
143
+ ctx , cancel := context .WithTimeout (context .Background (), timeoutConfig .CreateTimeout )
144
+ defer cancel ()
145
+
146
+ t .Logf ("Creating/Updating %s %s" , resource .GetName (), resource .GetObjectKind ().GroupVersionKind ().Kind )
147
+
148
+ // Check if the resource exists
149
+ existingResource := resource .DeepCopyObject ().(client.Object )
150
+ err := c .Get (ctx , types.NamespacedName {Name : resource .GetName (), Namespace : resource .GetNamespace ()}, existingResource )
151
+ if err != nil {
152
+ if ! apierrors .IsNotFound (err ) {
153
+ t .Logf ("error checking resource: %s %s" , resource .GetName (), resource .GetObjectKind ().GroupVersionKind ().Kind )
154
+ require .NoError (t , err , "error checking resource" )
155
+ }
156
+
157
+ // Resource doesn't exist, create it
158
+ err = c .Create (ctx , resource )
159
+ require .NoError (t , err , "error creating resource" )
160
+ } else {
161
+ // Resource exists, update it
162
+ err = c .Update (ctx , resource )
163
+ require .NoError (t , err , "error updating resource" )
164
+ }
178
165
166
+ if cleanup {
167
+ t .Cleanup (func () {
168
+ ctx , cancel = context .WithTimeout (context .Background (), timeoutConfig .DeleteTimeout )
169
+ defer cancel ()
170
+ t .Logf ("Deleting %s %s" , resource .GetName (), resource .GetObjectKind ().GroupVersionKind ().Kind )
171
+ err = c .Delete (ctx , resource )
172
+ require .NoErrorf (t , err , "error deleting resource" )
173
+ })
174
+ }
175
+ }
176
+ }
179
177
180
178
// MustApplyWithCleanup creates or updates Kubernetes resources defined with the
181
179
// provided YAML file and registers a cleanup function for resources it created.
@@ -185,7 +183,7 @@ func (a Applier) MustApplyWithCleanup(t *testing.T, c client.Client, timeoutConf
185
183
require .NoError (t , err )
186
184
187
185
decoder := yaml .NewYAMLOrJSONDecoder (data , 4096 )
188
-
186
+
189
187
resources , err := a .prepareResources (t , decoder )
190
188
if err != nil {
191
189
t .Logf ("manifest: %s" , data .String ())
0 commit comments