Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
postgres-operator
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
zalando
postgres-operator
Commits
d580684a
Commit
d580684a
authored
3 years ago
by
Felix Kunde
Browse files
Options
Downloads
Patches
Plain Diff
fix unit tests and return type for getInfrastructureRoles
parent
4bbf1e9d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/controller/util.go
+3
-3
3 additions, 3 deletions
pkg/controller/util.go
pkg/controller/util_test.go
+13
-47
13 additions, 47 deletions
pkg/controller/util_test.go
with
16 additions
and
50 deletions
pkg/controller/util.go
+
3
−
3
View file @
d580684a
...
...
@@ -200,7 +200,7 @@ func (c *Controller) getInfrastructureRoles(
errors
:=
make
([]
string
,
0
)
noRolesProvided
:=
true
roles
:=
[]
spec
.
PgUser
{}
uniqRoles
:=
map
[
string
]
spec
.
PgUser
{}
uniqRoles
:=
make
(
map
[
string
]
spec
.
PgUser
)
// To be compatible with the legacy implementation we need to return nil if
// the provided secret name is empty. The equivalent situation in the
...
...
@@ -213,7 +213,7 @@ func (c *Controller) getInfrastructureRoles(
}
if
noRolesProvided
{
return
ni
l
,
nil
return
u
ni
qRoles
,
nil
}
for
_
,
secret
:=
range
rolesSecrets
{
...
...
@@ -242,7 +242,7 @@ func (c *Controller) getInfrastructureRoles(
}
if
len
(
errors
)
>
0
{
return
ni
l
,
fmt
.
Errorf
(
strings
.
Join
(
errors
,
`', '`
))
return
u
ni
qRoles
,
fmt
.
Errorf
(
strings
.
Join
(
errors
,
`', '`
))
}
return
uniqRoles
,
nil
...
...
This diff is collapsed.
Click to expand it.
pkg/controller/util_test.go
+
13
−
47
View file @
d580684a
...
...
@@ -7,6 +7,7 @@ import (
b64
"encoding/base64"
"github.com/stretchr/testify/assert"
"github.com/zalando/postgres-operator/pkg/spec"
"github.com/zalando/postgres-operator/pkg/util/config"
"github.com/zalando/postgres-operator/pkg/util/k8sutil"
...
...
@@ -92,19 +93,19 @@ func TestOldInfrastructureRoleFormat(t *testing.T) {
var
testTable
=
[]
struct
{
secretName
spec
.
NamespacedName
expectedRoles
map
[
string
]
spec
.
PgUser
expectedError
s
[]
error
expectedError
error
}{
{
// empty secret name
spec
.
NamespacedName
{},
nil
,
map
[
string
]
spec
.
PgUser
{}
,
nil
,
},
{
// secret does not exist
spec
.
NamespacedName
{
Namespace
:
v1
.
NamespaceDefault
,
Name
:
"null"
},
map
[
string
]
spec
.
PgUser
{},
[]
error
{
fmt
.
Errorf
(
`could not get infrastructure roles secret default/null: NotFound`
)
}
,
fmt
.
Errorf
(
`could not get infrastructure roles secret default/null: NotFound`
),
},
{
spec
.
NamespacedName
{
...
...
@@ -129,7 +130,7 @@ func TestOldInfrastructureRoleFormat(t *testing.T) {
},
}
for
_
,
test
:=
range
testTable
{
roles
,
err
ors
:=
utilTestController
.
getInfrastructureRoles
(
roles
,
err
:=
utilTestController
.
getInfrastructureRoles
(
[]
*
config
.
InfrastructureRole
{
&
config
.
InfrastructureRole
{
SecretName
:
test
.
secretName
,
...
...
@@ -140,22 +141,9 @@ func TestOldInfrastructureRoleFormat(t *testing.T) {
},
})
if
len
(
errors
)
!=
len
(
test
.
expectedErrors
)
{
t
.
Errorf
(
"expected error '%v' does not match the actual error '%v'"
,
test
.
expectedErrors
,
errors
)
}
for
idx
:=
range
errors
{
err
:=
errors
[
idx
]
expectedErr
:=
test
.
expectedErrors
[
idx
]
if
err
!=
expectedErr
{
if
err
!=
nil
&&
expectedErr
!=
nil
&&
err
.
Error
()
==
expectedErr
.
Error
()
{
continue
}
if
err
!=
nil
&&
err
.
Error
()
!=
test
.
expectedError
.
Error
()
{
t
.
Errorf
(
"expected error '%v' does not match the actual error '%v'"
,
expectedErr
,
err
)
}
test
.
expectedError
,
err
)
}
if
!
reflect
.
DeepEqual
(
roles
,
test
.
expectedRoles
)
{
...
...
@@ -171,7 +159,6 @@ func TestNewInfrastructureRoleFormat(t *testing.T) {
var
testTable
=
[]
struct
{
secrets
[]
spec
.
NamespacedName
expectedRoles
map
[
string
]
spec
.
PgUser
expectedErrors
[]
error
}{
// one secret with one configmap
{
...
...
@@ -196,7 +183,6 @@ func TestNewInfrastructureRoleFormat(t *testing.T) {
Flags
:
[]
string
{
"createdb"
},
},
},
nil
,
},
// multiple standalone secrets
{
...
...
@@ -224,7 +210,6 @@ func TestNewInfrastructureRoleFormat(t *testing.T) {
MemberOf
:
[]
string
{
"new-test-inrole2"
},
},
},
nil
,
},
}
for
_
,
test
:=
range
testTable
{
...
...
@@ -239,27 +224,8 @@ func TestNewInfrastructureRoleFormat(t *testing.T) {
})
}
roles
,
errors
:=
utilTestController
.
getInfrastructureRoles
(
definitions
)
if
len
(
errors
)
!=
len
(
test
.
expectedErrors
)
{
t
.
Errorf
(
"expected error does not match the actual error:
\n
%+v
\n
%+v"
,
test
.
expectedErrors
,
errors
)
// Stop and do not do any further checks
return
}
for
idx
:=
range
errors
{
err
:=
errors
[
idx
]
expectedErr
:=
test
.
expectedErrors
[
idx
]
if
err
!=
expectedErr
{
if
err
!=
nil
&&
expectedErr
!=
nil
&&
err
.
Error
()
==
expectedErr
.
Error
()
{
continue
}
t
.
Errorf
(
"expected error '%v' does not match the actual error '%v'"
,
expectedErr
,
err
)
}
}
roles
,
err
:=
utilTestController
.
getInfrastructureRoles
(
definitions
)
assert
.
NoError
(
t
,
err
)
if
!
reflect
.
DeepEqual
(
roles
,
test
.
expectedRoles
)
{
t
.
Errorf
(
"expected roles output/the actual:
\n
%#v
\n
%#v"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment