github.com/quay/claircore@v1.5.28/test/integration/persistent_db.go (about)

     1  package integration
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"testing"
     7  )
     8  
     9  // NewPersistentDB creates a database for use in integration tests.
    10  //
    11  // Unlike the NewDB function, this function uses a deterministic role and
    12  // database name, and does not drop the database during cleanup.
    13  // The "uuid-ossp" extension is already loaded.
    14  //
    15  // DBSetup and NeedDB are expected to have been called correctly.
    16  func NewPersistentDB(ctx context.Context, t testing.TB, id string) *DB {
    17  	database := fmt.Sprintf("db_%s", id)
    18  	role := fmt.Sprintf("role_%s", id)
    19  	cfg := configureDatabase(ctx, t, pkgConfig, database, role)
    20  	if cfg == nil {
    21  		t.FailNow()
    22  	}
    23  	db := DB{
    24  		cfg:    cfg,
    25  		noDrop: true,
    26  	}
    27  	return &db
    28  }