Test functionality of getting infrastructure roles from their description in corresponding secrets. Here we test only common stuff (e.g. when a secret do not exist, or empty) and the old format.
(t *testing.T)
| 90 | // corresponding secrets. Here we test only common stuff (e.g. when a secret do |
| 91 | // not exist, or empty) and the old format. |
| 92 | func TestOldInfrastructureRoleFormat(t *testing.T) { |
| 93 | var testTable = []struct { |
| 94 | secretName spec.NamespacedName |
| 95 | expectedRoles map[string]spec.PgUser |
| 96 | expectedError error |
| 97 | }{ |
| 98 | { |
| 99 | // empty secret name |
| 100 | spec.NamespacedName{}, |
| 101 | map[string]spec.PgUser{}, |
| 102 | nil, |
| 103 | }, |
| 104 | { |
| 105 | // secret does not exist |
| 106 | spec.NamespacedName{Namespace: v1.NamespaceDefault, Name: "null"}, |
| 107 | map[string]spec.PgUser{}, |
| 108 | fmt.Errorf(`could not get infrastructure roles secret default/null: NotFound`), |
| 109 | }, |
| 110 | { |
| 111 | spec.NamespacedName{ |
| 112 | Namespace: v1.NamespaceDefault, |
| 113 | Name: testInfrastructureRolesOldSecretName, |
| 114 | }, |
| 115 | map[string]spec.PgUser{ |
| 116 | "testrole": { |
| 117 | Name: "testrole", |
| 118 | Origin: spec.RoleOriginInfrastructure, |
| 119 | Password: "testpassword", |
| 120 | MemberOf: []string{"testinrole"}, |
| 121 | }, |
| 122 | "foobar": { |
| 123 | Name: "foobar", |
| 124 | Origin: spec.RoleOriginInfrastructure, |
| 125 | Password: b64.StdEncoding.EncodeToString([]byte("password")), |
| 126 | MemberOf: nil, |
| 127 | }, |
| 128 | }, |
| 129 | nil, |
| 130 | }, |
| 131 | } |
| 132 | for _, test := range testTable { |
| 133 | roles, err := utilTestController.getInfrastructureRoles( |
| 134 | []*config.InfrastructureRole{ |
| 135 | { |
| 136 | SecretName: test.secretName, |
| 137 | UserKey: "user", |
| 138 | PasswordKey: "password", |
| 139 | RoleKey: "inrole", |
| 140 | Template: true, |
| 141 | }, |
| 142 | }) |
| 143 | |
| 144 | if err != nil && err.Error() != test.expectedError.Error() { |
| 145 | t.Errorf("expected error '%v' does not match the actual error '%v'", |
| 146 | test.expectedError, err) |
| 147 | } |
| 148 | |
| 149 | if !reflect.DeepEqual(roles, test.expectedRoles) { |
nothing calls this directly
no test coverage detected