Skip to content

Commit

Permalink
chore: add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtisvg committed Feb 20, 2021
1 parent 592ac23 commit 3a3dfed
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package tests

import (
"context"
"database/sql"
"flag"
"fmt"
"io/ioutil"
Expand All @@ -35,6 +37,8 @@ var (
postgresPass = flag.String("postgres_pass", os.Getenv("POSTGRES_PASS"), "Password for the database user; be careful when entering a password on the command line (it may go into your terminal's history).")
postgresDb = flag.String("postgres_db", os.Getenv("POSTGRES_DB"), "Name of the database to connect to.")

postgresIAMUser = flag.String("postgres_user_iam", os.Getenv("POSTGRES_USER_IAM"), "Name of database user configured with IAM DB Authentication.")

postgresPort = 5432
)

Expand Down Expand Up @@ -76,3 +80,33 @@ func TestPostgresConnLimit(t *testing.T) {
dsn := fmt.Sprintf("user=%s password=%s database=%s sslmode=disable", *postgresUser, *postgresPass, *postgresDb)
proxyConnLimitTest(t, *postgresConnName, "postgres", dsn, postgresPort)
}

func TestPostgresIAMDBAuthn(t *testing.T) {
requirePostgresVars(t)

ctx := context.Background()

// Start the proxy
p, err := StartProxy(ctx, fmt.Sprintf("-instances=%s=tcp:%d", *postgresConnName, 5432), "-enable_iam_login")
if err != nil {
t.Fatalf("unable to start proxy: %v", err)
}
defer p.Close()
output, err := p.WaitForServe(ctx)
if err != nil {
t.Fatalf("unable to verify proxy was serving: %s \n %s", err, output)
}

dsn := fmt.Sprintf("user=%s database=%s sslmode=disable", "kvg@google.com", *postgresDb)
db, err := sql.Open("postgres", dsn)
if err != nil {
t.Fatalf("unable to connect to db: %s", err)
}
defer db.Close()
_, err = db.Exec("SELECT 1;")
if err != nil {

t.Fatalf("unable to exec on db: %s", err)
}

}

0 comments on commit 3a3dfed

Please sign in to comment.