fix(postgresflex): User role should be updatable (#733)

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
This commit is contained in:
Alexander Dahmen 2025-03-24 14:47:45 +01:00 committed by GitHub
parent 3dc4fedba1
commit 1444376f35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 164 additions and 7 deletions

View file

@ -385,3 +385,86 @@ func TestToCreatePayload(t *testing.T) {
})
}
}
func TestToUpdatePayload(t *testing.T) {
tests := []struct {
description string
input *Model
inputRoles []string
expected *postgresflex.UpdateUserPayload
isValid bool
}{
{
"default_values",
&Model{},
[]string{},
&postgresflex.UpdateUserPayload{
Roles: &[]string{},
},
true,
},
{
"default_values",
&Model{
Username: types.StringValue("username"),
},
[]string{
"role_1",
"role_2",
},
&postgresflex.UpdateUserPayload{
Roles: &[]string{
"role_1",
"role_2",
},
},
true,
},
{
"null_fields_and_int_conversions",
&Model{
Username: types.StringNull(),
},
[]string{
"",
},
&postgresflex.UpdateUserPayload{
Roles: &[]string{
"",
},
},
true,
},
{
"nil_model",
nil,
[]string{},
nil,
false,
},
{
"nil_roles",
&Model{},
nil,
nil,
false,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
output, err := toUpdatePayload(tt.input, tt.inputRoles)
if !tt.isValid && err == nil {
t.Fatalf("Should have failed")
}
if tt.isValid && err != nil {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(output, tt.expected)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
}
})
}
}