99 "testing"
1010
1111 "gotest.tools/v3/assert"
12- "sigs.k8s.io/yaml"
1312
13+ "github.com/crunchydata/postgres-operator/internal/testing/require"
1414 "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
1515)
1616
@@ -54,7 +54,7 @@ func TestFetchKeyCommand(t *testing.T) {
5454
5555 t .Run ("blank" , func (t * testing.T ) {
5656 var spec1 v1beta1.PostgresClusterSpec
57- assert . NilError (t , yaml . Unmarshal ([] byte ( `{
57+ require . UnmarshalInto (t , & spec1 , `{
5858 patroni: {
5959 dynamicConfiguration: {
6060 postgresql: {
@@ -64,23 +64,23 @@ func TestFetchKeyCommand(t *testing.T) {
6464 },
6565 },
6666 },
67- }` ), & spec1 ))
67+ }` )
6868 assert .Equal (t , "" , FetchKeyCommand (& spec1 ))
6969
7070 var spec2 v1beta1.PostgresClusterSpec
71- assert . NilError (t , yaml . Unmarshal ([] byte ( `{
71+ require . UnmarshalInto (t , & spec2 , `{
7272 config: {
7373 parameters: {
7474 encryption_key_command: "",
7575 },
7676 },
77- }` ), & spec2 ))
77+ }` )
7878 assert .Equal (t , "" , FetchKeyCommand (& spec2 ))
7979 })
8080
8181 t .Run ("exists" , func (t * testing.T ) {
8282 var spec1 v1beta1.PostgresClusterSpec
83- assert . NilError (t , yaml . Unmarshal ([] byte ( `{
83+ require . UnmarshalInto (t , & spec1 , `{
8484 patroni: {
8585 dynamicConfiguration: {
8686 postgresql: {
@@ -90,23 +90,23 @@ func TestFetchKeyCommand(t *testing.T) {
9090 },
9191 },
9292 },
93- }` ), & spec1 ))
93+ }` )
9494 assert .Equal (t , "echo mykey" , FetchKeyCommand (& spec1 ))
9595
9696 var spec2 v1beta1.PostgresClusterSpec
97- assert . NilError (t , yaml . Unmarshal ([] byte ( `{
97+ require . UnmarshalInto (t , & spec2 , `{
9898 config: {
9999 parameters: {
100100 encryption_key_command: "cat somefile",
101101 },
102102 },
103- }` ), & spec2 ))
103+ }` )
104104 assert .Equal (t , "cat somefile" , FetchKeyCommand (& spec2 ))
105105 })
106106
107107 t .Run ("config.parameters takes precedence" , func (t * testing.T ) {
108108 var spec v1beta1.PostgresClusterSpec
109- assert . NilError (t , yaml . Unmarshal ([] byte ( `{
109+ require . UnmarshalInto (t , & spec , `{
110110 config: {
111111 parameters: {
112112 encryption_key_command: "cat somefile",
@@ -121,7 +121,7 @@ func TestFetchKeyCommand(t *testing.T) {
121121 },
122122 },
123123 },
124- }` ), & spec ))
124+ }` )
125125 assert .Equal (t , "cat somefile" , FetchKeyCommand (& spec ))
126126 })
127127}
@@ -139,9 +139,9 @@ func TestPGAdminContainerImage(t *testing.T) {
139139 t .Setenv ("RELATED_IMAGE_PGADMIN" , "env-var-pgadmin" )
140140 assert .Equal (t , PGAdminContainerImage (cluster ), "env-var-pgadmin" )
141141
142- assert . NilError (t , yaml . Unmarshal ([] byte ( `{
142+ require . UnmarshalInto (t , & cluster . Spec , `{
143143 userInterface: { pgAdmin: { image: spec-image } },
144- }` ), & cluster . Spec ))
144+ }` )
145145 assert .Equal (t , PGAdminContainerImage (cluster ), "spec-image" )
146146}
147147
@@ -158,9 +158,9 @@ func TestPGBackRestContainerImage(t *testing.T) {
158158 t .Setenv ("RELATED_IMAGE_PGBACKREST" , "env-var-pgbackrest" )
159159 assert .Equal (t , PGBackRestContainerImage (cluster ), "env-var-pgbackrest" )
160160
161- assert . NilError (t , yaml . Unmarshal ([] byte ( `{
162- backups: { pgBackRest : { image: spec-image } },
163- }` ), & cluster . Spec ))
161+ require . UnmarshalInto (t , & cluster . Spec , `{
162+ backups: { pgbackrest : { image: spec-image } },
163+ }` )
164164 assert .Equal (t , PGBackRestContainerImage (cluster ), "spec-image" )
165165}
166166
@@ -177,9 +177,9 @@ func TestPGBouncerContainerImage(t *testing.T) {
177177 t .Setenv ("RELATED_IMAGE_PGBOUNCER" , "env-var-pgbouncer" )
178178 assert .Equal (t , PGBouncerContainerImage (cluster ), "env-var-pgbouncer" )
179179
180- assert . NilError (t , yaml . Unmarshal ([] byte ( `{
180+ require . UnmarshalInto (t , & cluster . Spec , `{
181181 proxy: { pgBouncer: { image: spec-image } },
182- }` ), & cluster . Spec ))
182+ }` )
183183 assert .Equal (t , PGBouncerContainerImage (cluster ), "spec-image" )
184184}
185185
@@ -196,9 +196,9 @@ func TestPGExporterContainerImage(t *testing.T) {
196196 t .Setenv ("RELATED_IMAGE_PGEXPORTER" , "env-var-pgexporter" )
197197 assert .Equal (t , PGExporterContainerImage (cluster ), "env-var-pgexporter" )
198198
199- assert . NilError (t , yaml . Unmarshal ([] byte ( `{
200- monitoring: { pgMonitor : { exporter: { image: spec-image } } },
201- }` ), & cluster . Spec ))
199+ require . UnmarshalInto (t , & cluster . Spec , `{
200+ monitoring: { pgmonitor : { exporter: { image: spec-image } } },
201+ }` )
202202 assert .Equal (t , PGExporterContainerImage (cluster ), "spec-image" )
203203}
204204
@@ -215,9 +215,9 @@ func TestStandalonePGAdminContainerImage(t *testing.T) {
215215 t .Setenv ("RELATED_IMAGE_STANDALONE_PGADMIN" , "env-var-pgadmin" )
216216 assert .Equal (t , StandalonePGAdminContainerImage (pgadmin ), "env-var-pgadmin" )
217217
218- assert . NilError (t , yaml . Unmarshal ([] byte ( `{
218+ require . UnmarshalInto (t , & pgadmin . Spec , `{
219219 image: spec-image
220- }` ), & pgadmin . Spec ))
220+ }` )
221221 assert .Equal (t , StandalonePGAdminContainerImage (pgadmin ), "spec-image" )
222222}
223223
0 commit comments