Update unit tests
This commit is contained in:
parent
43154baf39
commit
188e812e40
|
|
@ -1099,7 +1099,7 @@ func (c *Cluster) initRobotUsers() error {
|
||||||
if strings.Contains(username, ".") {
|
if strings.Contains(username, ".") {
|
||||||
splits := strings.Split(username, ".")
|
splits := strings.Split(username, ".")
|
||||||
name = splits[1]
|
name = splits[1]
|
||||||
if splits[0] != "" {
|
if len(splits[0]) > 0 {
|
||||||
namespace = splits[0]
|
namespace = splits[0]
|
||||||
}
|
}
|
||||||
username = name
|
username = name
|
||||||
|
|
@ -1159,7 +1159,6 @@ func (c *Cluster) initTeamMembers(teamID string, isPostgresSuperuserTeam bool) e
|
||||||
newRole := spec.PgUser{
|
newRole := spec.PgUser{
|
||||||
Origin: spec.RoleOriginTeamsAPI,
|
Origin: spec.RoleOriginTeamsAPI,
|
||||||
Name: username,
|
Name: username,
|
||||||
Namespace: c.Namespace,
|
|
||||||
Flags: flags,
|
Flags: flags,
|
||||||
MemberOf: memberOf,
|
MemberOf: memberOf,
|
||||||
Parameters: c.OpConfig.TeamAPIRoleConfiguration,
|
Parameters: c.OpConfig.TeamAPIRoleConfiguration,
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,8 @@ func TestInitRobotUsers(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
manifestUsers: map[string]acidv1.UserFlags{"foo": {"superuser", "createdb"}},
|
manifestUsers: map[string]acidv1.UserFlags{"foo": {"superuser", "createdb"}},
|
||||||
infraRoles: 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", Password: "bar"}},
|
result: map[string]spec.PgUser{"foo": {Origin: spec.RoleOriginInfrastructure, Name: "foo", Namespace: cl.Namespace, Password: "bar"}},
|
||||||
err: nil,
|
err: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -872,6 +872,7 @@ func TestCrossNamespacedSecrets(t *testing.T) {
|
||||||
},
|
},
|
||||||
Users: map[string]acidv1.UserFlags{
|
Users: map[string]acidv1.UserFlags{
|
||||||
"appspace.db_user": {},
|
"appspace.db_user": {},
|
||||||
|
"db_user": {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -899,12 +900,23 @@ func TestCrossNamespacedSecrets(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, client, pg, logger, eventRecorder)
|
}, client, pg, logger, eventRecorder)
|
||||||
|
|
||||||
|
userNamespaceMap := map[string]string{
|
||||||
|
cluster.Namespace: "db_user",
|
||||||
|
"appspace": "db_user",
|
||||||
|
}
|
||||||
|
|
||||||
err := cluster.initRobotUsers()
|
err := cluster.initRobotUsers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s Could not create namespaced users with error: %s", testName, err)
|
t.Errorf("%s Could not create namespaced users with error: %s", testName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cluster.pgUsers["db_user"].Namespace == cluster.Namespace {
|
for _, u := range cluster.pgUsers {
|
||||||
t.Errorf("%s: Could not create namespaced users", testName)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue