77
88 b64 "encoding/base64"
99
10+ "github.com/stretchr/testify/assert"
1011 "github.com/zalando/postgres-operator/pkg/spec"
1112 "github.com/zalando/postgres-operator/pkg/util/config"
1213 "github.com/zalando/postgres-operator/pkg/util/k8sutil"
@@ -90,21 +91,21 @@ func TestClusterWorkerID(t *testing.T) {
9091// not exist, or empty) and the old format.
9192func TestOldInfrastructureRoleFormat (t * testing.T ) {
9293 var testTable = []struct {
93- secretName spec.NamespacedName
94- expectedRoles map [string ]spec.PgUser
95- expectedErrors [] error
94+ secretName spec.NamespacedName
95+ expectedRoles map [string ]spec.PgUser
96+ expectedError error
9697 }{
9798 {
9899 // empty secret name
99100 spec.NamespacedName {},
100- nil ,
101+ map [ string ]spec. PgUser {} ,
101102 nil ,
102103 },
103104 {
104105 // secret does not exist
105106 spec.NamespacedName {Namespace : v1 .NamespaceDefault , Name : "null" },
106107 map [string ]spec.PgUser {},
107- [] error { fmt .Errorf (`could not get infrastructure roles secret default/null: NotFound` )} ,
108+ fmt .Errorf (`could not get infrastructure roles secret default/null: NotFound` ),
108109 },
109110 {
110111 spec.NamespacedName {
@@ -129,7 +130,7 @@ func TestOldInfrastructureRoleFormat(t *testing.T) {
129130 },
130131 }
131132 for _ , test := range testTable {
132- roles , errors := utilTestController .getInfrastructureRoles (
133+ roles , err := utilTestController .getInfrastructureRoles (
133134 []* config.InfrastructureRole {
134135 & config.InfrastructureRole {
135136 SecretName : test .secretName ,
@@ -140,22 +141,9 @@ func TestOldInfrastructureRoleFormat(t *testing.T) {
140141 },
141142 })
142143
143- if len ( errors ) != len ( test .expectedErrors ) {
144+ if err != nil && err . Error ( ) != test .expectedError . Error ( ) {
144145 t .Errorf ("expected error '%v' does not match the actual error '%v'" ,
145- test .expectedErrors , errors )
146- }
147-
148- for idx := range errors {
149- err := errors [idx ]
150- expectedErr := test .expectedErrors [idx ]
151-
152- if err != expectedErr {
153- if err != nil && expectedErr != nil && err .Error () == expectedErr .Error () {
154- continue
155- }
156- t .Errorf ("expected error '%v' does not match the actual error '%v'" ,
157- expectedErr , err )
158- }
146+ test .expectedError , err )
159147 }
160148
161149 if ! reflect .DeepEqual (roles , test .expectedRoles ) {
@@ -169,9 +157,8 @@ func TestOldInfrastructureRoleFormat(t *testing.T) {
169157// corresponding secrets. Here we test the new format.
170158func TestNewInfrastructureRoleFormat (t * testing.T ) {
171159 var testTable = []struct {
172- secrets []spec.NamespacedName
173- expectedRoles map [string ]spec.PgUser
174- expectedErrors []error
160+ secrets []spec.NamespacedName
161+ expectedRoles map [string ]spec.PgUser
175162 }{
176163 // one secret with one configmap
177164 {
@@ -196,7 +183,6 @@ func TestNewInfrastructureRoleFormat(t *testing.T) {
196183 Flags : []string {"createdb" },
197184 },
198185 },
199- nil ,
200186 },
201187 // multiple standalone secrets
202188 {
@@ -224,7 +210,6 @@ func TestNewInfrastructureRoleFormat(t *testing.T) {
224210 MemberOf : []string {"new-test-inrole2" },
225211 },
226212 },
227- nil ,
228213 },
229214 }
230215 for _ , test := range testTable {
@@ -239,27 +224,8 @@ func TestNewInfrastructureRoleFormat(t *testing.T) {
239224 })
240225 }
241226
242- roles , errors := utilTestController .getInfrastructureRoles (definitions )
243- if len (errors ) != len (test .expectedErrors ) {
244- t .Errorf ("expected error does not match the actual error:\n %+v\n %+v" ,
245- test .expectedErrors , errors )
246-
247- // Stop and do not do any further checks
248- return
249- }
250-
251- for idx := range errors {
252- err := errors [idx ]
253- expectedErr := test .expectedErrors [idx ]
254-
255- if err != expectedErr {
256- if err != nil && expectedErr != nil && err .Error () == expectedErr .Error () {
257- continue
258- }
259- t .Errorf ("expected error '%v' does not match the actual error '%v'" ,
260- expectedErr , err )
261- }
262- }
227+ roles , err := utilTestController .getInfrastructureRoles (definitions )
228+ assert .NoError (t , err )
263229
264230 if ! reflect .DeepEqual (roles , test .expectedRoles ) {
265231 t .Errorf ("expected roles output/the actual:\n %#v\n %#v" ,
0 commit comments