mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-09 01:12:09 +02:00
intermediate garbage
This commit is contained in:
@@ -6,9 +6,11 @@ import (
|
||||
)
|
||||
|
||||
// PostgresTeamMap is the operator's internal representation of all PostgresTeam CRDs
|
||||
type PostgresTeamMap map[string]postgresTeamMembership
|
||||
type PostgresTeamMap map[string]*PostgresTeamMembership
|
||||
|
||||
type postgresTeamMembership struct {
|
||||
var emptyTeamMap = make(PostgresTeamMap, 0)
|
||||
|
||||
type PostgresTeamMembership struct {
|
||||
AdditionalSuperuserTeams []string
|
||||
AdditionalTeams []string
|
||||
AdditionalMembers []string
|
||||
@@ -94,6 +96,10 @@ func (ptm *PostgresTeamMap) GetAdditionalSuperuserTeams(team string, transitive
|
||||
|
||||
// Load function to import data from PostgresTeam CRD
|
||||
func (ptm *PostgresTeamMap) Load(pgTeams *acidv1.PostgresTeamList) {
|
||||
if ptm == nil {
|
||||
ptm = &emptyTeamMap
|
||||
}
|
||||
|
||||
superuserTeamSet := teamHashSet{}
|
||||
teamSet := teamHashSet{}
|
||||
teamMemberSet := teamHashSet{}
|
||||
@@ -109,10 +115,17 @@ func (ptm *PostgresTeamMap) Load(pgTeams *acidv1.PostgresTeamList) {
|
||||
fetchTeams(&teamIDs, teamMemberSet)
|
||||
|
||||
for teamID := range teamIDs {
|
||||
(*ptm)[teamID] = postgresTeamMembership{
|
||||
(*ptm)[teamID] = &PostgresTeamMembership{
|
||||
AdditionalSuperuserTeams: util.CoalesceStrArr(superuserTeamSet.toMap()[teamID], []string{}),
|
||||
AdditionalTeams: util.CoalesceStrArr(teamSet.toMap()[teamID], []string{}),
|
||||
AdditionalMembers: util.CoalesceStrArr(teamMemberSet.toMap()[teamID], []string{}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset a PostgresTeamMap
|
||||
func (ptm *PostgresTeamMap) Reset() {
|
||||
if ptm != nil {
|
||||
*ptm = emptyTeamMap
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package teams
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
|
||||
"github.com/zalando/postgres-operator/pkg/util"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -46,9 +47,36 @@ var (
|
||||
},
|
||||
},
|
||||
}
|
||||
pgTeamMap = PostgresTeamMap{
|
||||
"teamA": {
|
||||
AdditionalSuperuserTeams: []string{"teamB", "team24x7"},
|
||||
AdditionalTeams: []string{"teamC"},
|
||||
AdditionalMembers: []string{},
|
||||
},
|
||||
"teamB": {
|
||||
AdditionalSuperuserTeams: []string{"teamA", "teamC", "team24x7"},
|
||||
AdditionalTeams: []string{},
|
||||
AdditionalMembers: []string{"drno"},
|
||||
},
|
||||
"teamC": {
|
||||
AdditionalSuperuserTeams: []string{"team24x7"},
|
||||
AdditionalTeams: []string{"teamA", "teamB", "acid"},
|
||||
AdditionalMembers: []string{},
|
||||
},
|
||||
"team24x7": {
|
||||
AdditionalSuperuserTeams: []string{},
|
||||
AdditionalTeams: []string{},
|
||||
AdditionalMembers: []string{"optimusprime"},
|
||||
},
|
||||
"acid": {
|
||||
AdditionalSuperuserTeams: []string{},
|
||||
AdditionalTeams: []string{},
|
||||
AdditionalMembers: []string{"batman"},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// PostgresTeamMap is the operator's internal representation of all PostgresTeam CRDs
|
||||
// TestLoadingPostgresTeamCRD PostgresTeamMap is the operator's internal representation of all PostgresTeam CRDs
|
||||
func TestLoadingPostgresTeamCRD(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -59,33 +87,7 @@ func TestLoadingPostgresTeamCRD(t *testing.T) {
|
||||
{
|
||||
"Check that CRD is imported correctly into the internal format",
|
||||
pgTeamList,
|
||||
PostgresTeamMap{
|
||||
"teamA": {
|
||||
AdditionalSuperuserTeams: []string{"teamB", "team24x7"},
|
||||
AdditionalTeams: []string{"teamC"},
|
||||
AdditionalMembers: []string{},
|
||||
},
|
||||
"teamB": {
|
||||
AdditionalSuperuserTeams: []string{"teamA", "teamC", "team24x7"},
|
||||
AdditionalTeams: []string{},
|
||||
AdditionalMembers: []string{"drno"},
|
||||
},
|
||||
"teamC": {
|
||||
AdditionalSuperuserTeams: []string{"team24x7"},
|
||||
AdditionalTeams: []string{"teamA", "teamB", "acid"},
|
||||
AdditionalMembers: []string{},
|
||||
},
|
||||
"team24x7": {
|
||||
AdditionalSuperuserTeams: []string{},
|
||||
AdditionalTeams: []string{},
|
||||
AdditionalMembers: []string{"optimusprime"},
|
||||
},
|
||||
"acid": {
|
||||
AdditionalSuperuserTeams: []string{},
|
||||
AdditionalTeams: []string{},
|
||||
AdditionalMembers: []string{"batman"},
|
||||
},
|
||||
},
|
||||
pgTeamMap,
|
||||
"Mismatch between PostgresTeam CRD and internal map",
|
||||
},
|
||||
}
|
||||
@@ -107,6 +109,14 @@ func TestLoadingPostgresTeamCRD(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestLoadingPostgresTeamCRD PostgresTeamMap is the operator's internal representation of all PostgresTeam CRDs
|
||||
func TestResetPostgresTeamCRD(t *testing.T) {
|
||||
teamMap := &pgTeamMap
|
||||
teamMap.Reset()
|
||||
|
||||
assert.Equal(t, teamMap, &PostgresTeamMap{})
|
||||
}
|
||||
|
||||
// TestGetAdditionalTeams if returns teams with and without transitive dependencies
|
||||
func TestGetAdditionalTeams(t *testing.T) {
|
||||
tests := []struct {
|
||||
|
||||
Reference in New Issue
Block a user