@@ -11,11 +11,10 @@ import (
11
11
12
12
"gotest.tools/v3/assert"
13
13
apierrors "k8s.io/apimachinery/pkg/api/errors"
14
- "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
15
14
"k8s.io/apimachinery/pkg/util/intstr"
16
15
"sigs.k8s.io/controller-runtime/pkg/client"
16
+ "sigs.k8s.io/yaml"
17
17
18
- "github.com/crunchydata/postgres-operator/internal/controller/runtime"
19
18
"github.com/crunchydata/postgres-operator/internal/testing/cmp"
20
19
"github.com/crunchydata/postgres-operator/internal/testing/require"
21
20
v1 "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1"
@@ -271,13 +270,15 @@ func TestPostgresConfigParameters(t *testing.T) {
271
270
key string
272
271
value any
273
272
}{
274
- {"archive_timeout" , int64 ( 100 ) },
273
+ {"archive_timeout" , 100 },
275
274
{"archive_timeout" , "20s" },
276
275
} {
277
276
t .Run (tt .key , func (t * testing.T ) {
278
- cluster := require .Value (runtime .ToUnstructuredObject (base ))
279
- assert .NilError (t , unstructured .SetNestedField (cluster .Object ,
280
- tt .value , "spec" , "config" , "parameters" , tt .key ))
277
+ cluster := base .DeepCopy ()
278
+ require .UnmarshalInto (t , & cluster .Spec .Config ,
279
+ require .Value (yaml .Marshal (map [string ]any {
280
+ "parameters" : map [string ]any {tt .key : tt .value },
281
+ })))
281
282
282
283
assert .NilError (t , cc .Create (ctx , cluster , client .DryRunAll ))
283
284
})
@@ -299,13 +300,15 @@ func TestPostgresConfigParameters(t *testing.T) {
299
300
{key : "listen_addresses" , value : "" },
300
301
{key : "log_file_mode" , value : "" },
301
302
{key : "logging_collector" , value : "off" },
302
- {key : "port" , value : int64 ( 5 ) },
303
+ {key : "port" , value : 5 },
303
304
{key : "wal_log_hints" , value : "off" },
304
305
} {
305
306
t .Run (tt .key , func (t * testing.T ) {
306
- cluster := require .Value (runtime .ToUnstructuredObject (base ))
307
- assert .NilError (t , unstructured .SetNestedField (cluster .Object ,
308
- tt .value , "spec" , "config" , "parameters" , tt .key ))
307
+ cluster := base .DeepCopy ()
308
+ require .UnmarshalInto (t , & cluster .Spec .Config ,
309
+ require .Value (yaml .Marshal (map [string ]any {
310
+ "parameters" : map [string ]any {tt .key : tt .value },
311
+ })))
309
312
310
313
err := cc .Create (ctx , cluster , client .DryRunAll )
311
314
assert .Assert (t , apierrors .IsInvalid (err ))
@@ -332,9 +335,11 @@ func TestPostgresConfigParameters(t *testing.T) {
332
335
{key : "unix_socket_group" , value : "two" },
333
336
} {
334
337
t .Run (tt .key , func (t * testing.T ) {
335
- cluster := require .Value (runtime .ToUnstructuredObject (base ))
336
- assert .NilError (t , unstructured .SetNestedField (cluster .Object ,
337
- tt .value , "spec" , "config" , "parameters" , tt .key ))
338
+ cluster := base .DeepCopy ()
339
+ require .UnmarshalInto (t , & cluster .Spec .Config ,
340
+ require .Value (yaml .Marshal (map [string ]any {
341
+ "parameters" : map [string ]any {tt .key : tt .value },
342
+ })))
338
343
339
344
err := cc .Create (ctx , cluster , client .DryRunAll )
340
345
assert .Assert (t , apierrors .IsInvalid (err ))
@@ -354,9 +359,11 @@ func TestPostgresConfigParameters(t *testing.T) {
354
359
{key : "recovery_target_name" , value : "doot" },
355
360
} {
356
361
t .Run (tt .key , func (t * testing.T ) {
357
- cluster := require .Value (runtime .ToUnstructuredObject (base ))
358
- assert .NilError (t , unstructured .SetNestedField (cluster .Object ,
359
- tt .value , "spec" , "config" , "parameters" , tt .key ))
362
+ cluster := base .DeepCopy ()
363
+ require .UnmarshalInto (t , & cluster .Spec .Config ,
364
+ require .Value (yaml .Marshal (map [string ]any {
365
+ "parameters" : map [string ]any {tt .key : tt .value },
366
+ })))
360
367
361
368
err := cc .Create (ctx , cluster , client .DryRunAll )
362
369
assert .Assert (t , apierrors .IsInvalid (err ))
@@ -408,9 +415,11 @@ func TestPostgresConfigParameters(t *testing.T) {
408
415
{key : "recovery_min_apply_delay" , value : "" },
409
416
} {
410
417
t .Run (tt .key , func (t * testing.T ) {
411
- cluster := require .Value (runtime .ToUnstructuredObject (base ))
412
- assert .NilError (t , unstructured .SetNestedField (cluster .Object ,
413
- tt .value , "spec" , "config" , "parameters" , tt .key ))
418
+ cluster := base .DeepCopy ()
419
+ require .UnmarshalInto (t , & cluster .Spec .Config ,
420
+ require .Value (yaml .Marshal (map [string ]any {
421
+ "parameters" : map [string ]any {tt .key : tt .value },
422
+ })))
414
423
415
424
err := cc .Create (ctx , cluster , client .DryRunAll )
416
425
assert .Assert (t , apierrors .IsInvalid (err ))
0 commit comments