mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-02 11:16:07 +02:00
Update unit tests
This commit is contained in:
@@ -1099,7 +1099,7 @@ func (c *Cluster) initRobotUsers() error {
|
||||
if strings.Contains(username, ".") {
|
||||
splits := strings.Split(username, ".")
|
||||
name = splits[1]
|
||||
if splits[0] != "" {
|
||||
if len(splits[0]) > 0 {
|
||||
namespace = splits[0]
|
||||
}
|
||||
username = name
|
||||
@@ -1159,7 +1159,6 @@ func (c *Cluster) initTeamMembers(teamID string, isPostgresSuperuserTeam bool) e
|
||||
newRole := spec.PgUser{
|
||||
Origin: spec.RoleOriginTeamsAPI,
|
||||
Name: username,
|
||||
Namespace: c.Namespace,
|
||||
Flags: flags,
|
||||
MemberOf: memberOf,
|
||||
Parameters: c.OpConfig.TeamAPIRoleConfiguration,
|
||||
|
||||
@@ -81,8 +81,8 @@ func TestInitRobotUsers(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
manifestUsers: map[string]acidv1.UserFlags{"foo": {"superuser", "createdb"}},
|
||||
infraRoles: map[string]spec.PgUser{"foo": {Origin: spec.RoleOriginInfrastructure, Name: "foo", Password: "bar"}},
|
||||
result: map[string]spec.PgUser{"foo": {Origin: spec.RoleOriginInfrastructure, Name: "foo", Password: "bar"}},
|
||||
infraRoles: map[string]spec.PgUser{"foo": {Origin: spec.RoleOriginInfrastructure, Name: "foo", Namespace: cl.Namespace, Password: "bar"}},
|
||||
result: map[string]spec.PgUser{"foo": {Origin: spec.RoleOriginInfrastructure, Name: "foo", Namespace: cl.Namespace, Password: "bar"}},
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
@@ -872,6 +872,7 @@ func TestCrossNamespacedSecrets(t *testing.T) {
|
||||
},
|
||||
Users: map[string]acidv1.UserFlags{
|
||||
"appspace.db_user": {},
|
||||
"db_user": {},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -899,12 +900,23 @@ func TestCrossNamespacedSecrets(t *testing.T) {
|
||||
},
|
||||
}, client, pg, logger, eventRecorder)
|
||||
|
||||
userNamespaceMap := map[string]string{
|
||||
cluster.Namespace: "db_user",
|
||||
"appspace": "db_user",
|
||||
}
|
||||
|
||||
err := cluster.initRobotUsers()
|
||||
if err != nil {
|
||||
t.Errorf("%s Could not create namespaced users with error: %s", testName, err)
|
||||
}
|
||||
|
||||
if cluster.pgUsers["db_user"].Namespace == cluster.Namespace {
|
||||
t.Errorf("%s: Could not create namespaced users", testName)
|
||||
for _, u := range cluster.pgUsers {
|
||||
if u.Name != userNamespaceMap[u.Namespace] {
|
||||
t.Errorf("%s: Could not create namespaced user in its correct namespaces", testName)
|
||||
}
|
||||
}
|
||||
err = cluster.syncRoles()
|
||||
if err != nil {
|
||||
t.Errorf("%s Could not create namespaced users with error: %s", testName, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user