@@ -60,8 +60,7 @@ func TestPostgresConfigParameters(t *testing.T) {
6060 {"archive_timeout" , "20s" },
6161 } {
6262 t .Run (tt .key , func (t * testing.T ) {
63- cluster , err := runtime .ToUnstructuredObject (base )
64- assert .NilError (t , err )
63+ cluster := require .Value (runtime .ToUnstructuredObject (base ))
6564 assert .NilError (t , unstructured .SetNestedField (cluster .Object ,
6665 tt .value , "spec" , "config" , "parameters" , tt .key ))
6766
@@ -89,16 +88,14 @@ func TestPostgresConfigParameters(t *testing.T) {
8988 {key : "wal_log_hints" , value : "off" },
9089 } {
9190 t .Run (tt .key , func (t * testing.T ) {
92- cluster , err := runtime .ToUnstructuredObject (base )
93- assert .NilError (t , err )
91+ cluster := require .Value (runtime .ToUnstructuredObject (base ))
9492 assert .NilError (t , unstructured .SetNestedField (cluster .Object ,
9593 tt .value , "spec" , "config" , "parameters" , tt .key ))
9694
97- err = cc .Create (ctx , cluster , client .DryRunAll )
95+ err : = cc .Create (ctx , cluster , client .DryRunAll )
9896 assert .Assert (t , apierrors .IsInvalid (err ))
9997
100- //nolint:errorlint // This is a test, and a panic is unlikely.
101- status := err .(apierrors.APIStatus ).Status ()
98+ status := require .StatusError (t , err )
10299 assert .Assert (t , status .Details != nil )
103100 assert .Assert (t , cmp .Len (status .Details .Causes , 1 ))
104101
@@ -112,18 +109,17 @@ func TestPostgresConfigParameters(t *testing.T) {
112109 t .Run ("NoConnections" , func (t * testing.T ) {
113110 for _ , tt := range []struct {
114111 key string
115- value intstr. IntOrString
112+ value any
116113 }{
117- {key : "ssl" , value : intstr . FromString ( "off" ) },
118- {key : "ssl_ca_file" , value : intstr . FromString ( "" ) },
119- {key : "unix_socket_directories" , value : intstr . FromString ( "one" ) },
120- {key : "unix_socket_group" , value : intstr . FromString ( "two" ) },
114+ {key : "ssl" , value : "off" },
115+ {key : "ssl_ca_file" , value : "" },
116+ {key : "unix_socket_directories" , value : "one" },
117+ {key : "unix_socket_group" , value : "two" },
121118 } {
122119 t .Run (tt .key , func (t * testing.T ) {
123- cluster := base .DeepCopy ()
124- cluster .Spec .Config .Parameters = map [string ]intstr.IntOrString {
125- tt .key : tt .value ,
126- }
120+ cluster := require .Value (runtime .ToUnstructuredObject (base ))
121+ assert .NilError (t , unstructured .SetNestedField (cluster .Object ,
122+ tt .value , "spec" , "config" , "parameters" , tt .key ))
127123
128124 err := cc .Create (ctx , cluster , client .DryRunAll )
129125 assert .Assert (t , apierrors .IsInvalid (err ))
@@ -134,19 +130,18 @@ func TestPostgresConfigParameters(t *testing.T) {
134130 t .Run ("NoWriteAheadLog" , func (t * testing.T ) {
135131 for _ , tt := range []struct {
136132 key string
137- value intstr. IntOrString
133+ value any
138134 }{
139- {key : "archive_mode" , value : intstr . FromString ( "off" ) },
140- {key : "archive_command" , value : intstr . FromString ( "true" ) },
141- {key : "restore_command" , value : intstr . FromString ( "true" ) },
142- {key : "recovery_target" , value : intstr . FromString ( "immediate" ) },
143- {key : "recovery_target_name" , value : intstr . FromString ( "doot" ) },
135+ {key : "archive_mode" , value : "off" },
136+ {key : "archive_command" , value : "true" },
137+ {key : "restore_command" , value : "true" },
138+ {key : "recovery_target" , value : "immediate" },
139+ {key : "recovery_target_name" , value : "doot" },
144140 } {
145141 t .Run (tt .key , func (t * testing.T ) {
146- cluster := base .DeepCopy ()
147- cluster .Spec .Config .Parameters = map [string ]intstr.IntOrString {
148- tt .key : tt .value ,
149- }
142+ cluster := require .Value (runtime .ToUnstructuredObject (base ))
143+ assert .NilError (t , unstructured .SetNestedField (cluster .Object ,
144+ tt .value , "spec" , "config" , "parameters" , tt .key ))
150145
151146 err := cc .Create (ctx , cluster , client .DryRunAll )
152147 assert .Assert (t , apierrors .IsInvalid (err ))
@@ -158,25 +153,28 @@ func TestPostgresConfigParameters(t *testing.T) {
158153 t .Run ("Valid" , func (t * testing.T ) {
159154 cluster := base .DeepCopy ()
160155
161- cluster .Spec .Config .Parameters = map [string ]intstr.IntOrString {
162- "wal_level" : intstr .FromString ("logical" ),
156+ cluster .Spec .Config = & v1beta1.PostgresConfig {
157+ Parameters : map [string ]intstr.IntOrString {
158+ "wal_level" : intstr .FromString ("logical" ),
159+ },
163160 }
164161 assert .NilError (t , cc .Create (ctx , cluster , client .DryRunAll ))
165162 })
166163
167164 t .Run ("Invalid" , func (t * testing.T ) {
168165 cluster := base .DeepCopy ()
169166
170- cluster .Spec .Config .Parameters = map [string ]intstr.IntOrString {
171- "wal_level" : intstr .FromString ("minimal" ),
167+ cluster .Spec .Config = & v1beta1.PostgresConfig {
168+ Parameters : map [string ]intstr.IntOrString {
169+ "wal_level" : intstr .FromString ("minimal" ),
170+ },
172171 }
173172
174173 err := cc .Create (ctx , cluster , client .DryRunAll )
175174 assert .Assert (t , apierrors .IsInvalid (err ))
176175 assert .ErrorContains (t , err , `"replica" or higher` )
177176
178- //nolint:errorlint // This is a test, and a panic is unlikely.
179- status := err .(apierrors.APIStatus ).Status ()
177+ status := require .StatusError (t , err )
180178 assert .Assert (t , status .Details != nil )
181179 assert .Assert (t , cmp .Len (status .Details .Causes , 1 ))
182180 assert .Equal (t , status .Details .Causes [0 ].Field , "spec.config.parameters" )
@@ -187,18 +185,17 @@ func TestPostgresConfigParameters(t *testing.T) {
187185 t .Run ("NoReplication" , func (t * testing.T ) {
188186 for _ , tt := range []struct {
189187 key string
190- value intstr. IntOrString
188+ value any
191189 }{
192- {key : "synchronous_standby_names" , value : intstr . FromString ( "" ) },
193- {key : "primary_conninfo" , value : intstr . FromString ( "" ) },
194- {key : "primary_slot_name" , value : intstr . FromString ( "" ) },
195- {key : "recovery_min_apply_delay" , value : intstr . FromString ( "" ) },
190+ {key : "synchronous_standby_names" , value : "" },
191+ {key : "primary_conninfo" , value : "" },
192+ {key : "primary_slot_name" , value : "" },
193+ {key : "recovery_min_apply_delay" , value : "" },
196194 } {
197195 t .Run (tt .key , func (t * testing.T ) {
198- cluster := base .DeepCopy ()
199- cluster .Spec .Config .Parameters = map [string ]intstr.IntOrString {
200- tt .key : tt .value ,
201- }
196+ cluster := require .Value (runtime .ToUnstructuredObject (base ))
197+ assert .NilError (t , unstructured .SetNestedField (cluster .Object ,
198+ tt .value , "spec" , "config" , "parameters" , tt .key ))
202199
203200 err := cc .Create (ctx , cluster , client .DryRunAll )
204201 assert .Assert (t , apierrors .IsInvalid (err ))
@@ -251,8 +248,7 @@ func TestPostgresUserOptions(t *testing.T) {
251248 assert .Assert (t , apierrors .IsInvalid (err ))
252249 assert .ErrorContains (t , err , "cannot contain comments" )
253250
254- //nolint:errorlint // This is a test, and a panic is unlikely.
255- status := err .(apierrors.APIStatus ).Status ()
251+ status := require .StatusError (t , err )
256252 assert .Assert (t , status .Details != nil )
257253 assert .Assert (t , cmp .Len (status .Details .Causes , 3 ))
258254
@@ -273,8 +269,7 @@ func TestPostgresUserOptions(t *testing.T) {
273269 assert .Assert (t , apierrors .IsInvalid (err ))
274270 assert .ErrorContains (t , err , "cannot assign password" )
275271
276- //nolint:errorlint // This is a test, and a panic is unlikely.
277- status := err .(apierrors.APIStatus ).Status ()
272+ status := require .StatusError (t , err )
278273 assert .Assert (t , status .Details != nil )
279274 assert .Assert (t , cmp .Len (status .Details .Causes , 2 ))
280275
@@ -294,8 +289,7 @@ func TestPostgresUserOptions(t *testing.T) {
294289 assert .Assert (t , apierrors .IsInvalid (err ))
295290 assert .ErrorContains (t , err , "should match" )
296291
297- //nolint:errorlint // This is a test, and a panic is unlikely.
298- status := err .(apierrors.APIStatus ).Status ()
292+ status := require .StatusError (t , err )
299293 assert .Assert (t , status .Details != nil )
300294 assert .Assert (t , cmp .Len (status .Details .Causes , 1 ))
301295 assert .Equal (t , status .Details .Causes [0 ].Field , "spec.users[0].options" )
0 commit comments