Skip to content

Commit

Permalink
try postgres docker service again
Browse files Browse the repository at this point in the history
  • Loading branch information
fairclothjm committed Oct 17, 2024
1 parent 0272ea5 commit ada7a3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ jobs:
- 8200:8200
volumes:
- ${{ github.workspace }}:/vault/plugins
postgres:
image: docker.mirror.hashicorp.services/postgres:latest
env:
POSTGRES_PASSWORD: secret
POSTGRES_DB: database
ports:
- 5432:5432
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
Expand Down Expand Up @@ -129,6 +136,5 @@ jobs:
LDAP_BINDDN: "cn=admin,dc=example,dc=org"
LDAP_BINDPASS: "adminpassword"
LDAP_URL: "ldap://openldap:1389"
VAULT_PLUGIN_COMMAND: ${{ steps.plugin.outputs.command }}
run: |
TF_ACC_ENTERPRISE=1 TF_ACC=1 go test -v -run TestAccDatabaseSecretBackendStaticRole_Rootless ./vault/... -timeout 30m ./...
4 changes: 2 additions & 2 deletions testutil/postgresqlhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func defaultRunOpts(t *testing.T) docker.RunOptions {
}
}

func CheckTestPGUser(t *testing.T, connURL string, username, password string) {
func CheckTestPGUser(t *testing.T, username, connURL string) {
t.Helper()
t.Logf("[TRACE] CheckTestPGUser Querying for test user %q, password %q, connURL %q", username, password, connURL)
t.Logf("[TRACE] CheckTestPGUser Querying for username: %s connURL %q", username, connURL)

db, err := sql.Open("pgx", connURL)
defer db.Close()
Expand Down
33 changes: 15 additions & 18 deletions vault/resource_database_secret_backend_static_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"database/sql"
"fmt"
"net/url"
"os"
"testing"

Expand Down Expand Up @@ -164,23 +165,19 @@ CREATE ROLE "{{name}}" WITH
PASSWORD '{{password}}';
`

cleanup, pgxURL := testutil.PrepareTestContainerSelfManaged(t)
t.Log("pgxURL", pgxURL)
t.Log("pgxURL.Scheme", pgxURL.Scheme)
t.Log("pgxURL.User", pgxURL.User)
t.Log("pgxURL.Host", pgxURL.Host)
t.Log("pgxURL.Path", pgxURL.Path)
t.Log("pgxURL.Path", pgxURL.Path)
t.Cleanup(func() {
t.Log("===> running cleanup")
cleanup()
})

connURL := fmt.Sprintf("postgres://{{username}}:{{password}}@%s/postgres?sslmode=disable", pgxURL.Host)
// connURL := "postgresql://{{username}}:{{password}}@localhost:5432/postgres?sslmode=disable"
values := testutil.SkipTestEnvUnset(t, "POSTGRES_URL")
connURL := values[0]
t.Log("connURL ", connURL)

fmt.Println(testAccDatabaseSecretBackendStaticRoleConfig_rootlessConfig(name, username, dbName, backend, connURL, "testpassword"))
parsedURL, err := url.Parse(connURL)
if err != nil {
t.Fatal(err)
}

connURLTemplate := fmt.Sprintf("postgres://{{username}}:{{password}}@%s/postgres?sslmode=disable", parsedURL.Host)
connURLRootless := fmt.Sprintf("postgres://%s:testpassword@%s/postgres?sslmode=disable", username, parsedURL.Host)

fmt.Println(testAccDatabaseSecretBackendStaticRoleConfig_rootlessConfig(name, username, dbName, backend, connURLTemplate, "testpassword"))
resource.Test(t, resource.TestCase{
ProviderFactories: providerFactories,
PreCheck: func() {
Expand All @@ -192,10 +189,10 @@ CREATE ROLE "{{name}}" WITH
{
PreConfig: func() {
// create static database user
testutil.CreateTestPGUser(t, pgxURL.String(), username, "testpassword", testRoleStaticCreate)
testutil.CheckTestPGUser(t, pgxURL.String(), username, "testpassword")
testutil.CreateTestPGUser(t, connURL, username, "testpassword", testRoleStaticCreate)
testutil.CheckTestPGUser(t, connURLRootless, username)
},
Config: testAccDatabaseSecretBackendStaticRoleConfig_rootlessConfig(name, username, dbName, backend, connURL, "testpassword"),
Config: testAccDatabaseSecretBackendStaticRoleConfig_rootlessConfig(name, username, dbName, backend, connURLTemplate, "testpassword"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "backend", backend),
Expand Down

0 comments on commit ada7a3e

Please sign in to comment.