Skip to content

Commit

Permalink
postgres: update to new test database harness
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Jul 15, 2021
1 parent 1e26de5 commit a5ae342
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
5 changes: 3 additions & 2 deletions notifier/postgres/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/quay/claircore"
cctest "github.com/quay/claircore/test"
"github.com/quay/claircore/test/integration"
"github.com/quay/zlog"

"github.com/quay/clair/v4/notifier"
)
Expand All @@ -22,7 +23,8 @@ const (
// retreiving, bookkeeping, and deleting of notifications
// and asssociated data works correctly
func TestE2E(t *testing.T) {
integration.Skip(t)
integration.NeedDB(t)
ctx := zlog.Test(nil, t)
digest, _ := claircore.ParseDigest("sha256:35c102085707f703de2d9eaad8752d6fe1b8f02b5d2149f1d8357c9cc7fb7d0a")
notificationID := uuid.New()
// this function puts a single noification undertest
Expand All @@ -35,7 +37,6 @@ func TestE2E(t *testing.T) {
Vulnerability: vsummary,
},
}
ctx := context.Background()
store := TestStore(ctx, t)
e := e2e{
notificaitonID: notificationID,
Expand Down
15 changes: 15 additions & 0 deletions notifier/postgres/postgres_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package postgres

import (
"os"
"testing"

"github.com/quay/claircore/test/integration"
)

func TestMain(m *testing.M) {
var c int
defer func() { os.Exit(c) }()
defer integration.DBSetup()()
c = m.Run()
}
2 changes: 2 additions & 0 deletions notifier/postgres/testdata/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pg*
!.gitignore
21 changes: 2 additions & 19 deletions notifier/postgres/teststore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,19 @@ package postgres

import (
"context"
"database/sql"
"fmt"
"os"
"testing"

"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/log/testingadapter"
"github.com/jackc/pgx/v4/pgxpool"
_ "github.com/jackc/pgx/v4/stdlib" // Needed for sql.Open
"github.com/jackc/pgx/v4/stdlib"
"github.com/quay/claircore/test/integration"
"github.com/remind101/migrate"

"github.com/quay/clair/v4/notifier/migrations"
)

const (
// connection string for our local development. see docker-compose.yaml at root
DefaultDSN = `host=localhost port=5432 user=clair dbname=clair sslmode=disable`
)

func TestStore(ctx context.Context, t testing.TB) *Store {
if os.Getenv(integration.EnvPGConnString) == "" {
os.Setenv(integration.EnvPGConnString, DefaultDSN)
}

db, err := integration.NewDB(ctx, t)
if err != nil {
t.Fatalf("unable to create test database: %v", err)
Expand All @@ -44,13 +32,8 @@ func TestStore(ctx context.Context, t testing.TB) *Store {
}
t.Cleanup(pool.Close)

dsn := fmt.Sprintf("host=%s port=%d database=%s user=%s", cfg.ConnConfig.Host, cfg.ConnConfig.Port, cfg.ConnConfig.Database, cfg.ConnConfig.User)
dbh, err := sql.Open("pgx", dsn)
if err != nil {
t.Fatalf("failed to Open: %v", err)
}
dbh := stdlib.OpenDB(*cfg.ConnConfig)
defer dbh.Close()
t.Log(dsn)

// run migrations
migrator := migrate.NewPostgresMigrator(dbh)
Expand Down

0 comments on commit a5ae342

Please sign in to comment.