Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly save role with quoted search path #1

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions postgresql/resource_postgresql_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ func readSearchPath(roleConfig pq.ByteaArray) []string {
config := string(v)
if strings.HasPrefix(config, roleSearchPathAttr) {
var result = strings.Split(strings.TrimPrefix(config, roleSearchPathAttr+"="), ", ")
for i := range result {
result[i] = strings.Trim(result[i], `"`)
}
return result
}
}
Expand Down
7 changes: 5 additions & 2 deletions postgresql/resource_postgresql_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestAccPostgresqlRole_Basic(t *testing.T) {
resource.TestCheckResourceAttr("postgresql_role.sub_role", "name", "sub_role"),
resource.TestCheckResourceAttr("postgresql_role.sub_role", "roles.#", "2"),

testAccCheckPostgresqlRoleExists("role_with_search_path", nil, []string{"bar", "foo"}),
testAccCheckPostgresqlRoleExists("role_with_search_path", nil, []string{"bar", "foo-with-hyphen"}),

// The int part in the attr name is the schema.HashString of the value.
resource.TestCheckResourceAttr("postgresql_role.sub_role", "roles.719783566", "myrole2"),
Expand Down Expand Up @@ -346,6 +346,9 @@ func checkSearchPath(client *Client, roleName string, expectedSearchPath []strin
}

searchPath := strings.Split(searchPathStr, ", ")
for i := range searchPath {
searchPath[i] = strings.Trim(searchPath[i], `"`)
}
sort.Strings(expectedSearchPath)
if !reflect.DeepEqual(searchPath, expectedSearchPath) {
return fmt.Errorf(
Expand Down Expand Up @@ -411,6 +414,6 @@ resource "postgresql_role" "sub_role" {

resource "postgresql_role" "role_with_search_path" {
name = "role_with_search_path"
search_path = ["bar", "foo"]
search_path = ["bar", "foo-with-hyphen"]
}
`