open-vault/physical/postgresql/postgresql_test.go

47 lines
899 B
Go
Raw Normal View History

package postgresql
import (
"os"
"testing"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/helper/logging"
"github.com/hashicorp/vault/physical"
2016-08-19 20:45:17 +00:00
_ "github.com/lib/pq"
)
func TestPostgreSQLBackend(t *testing.T) {
connURL := os.Getenv("PGURL")
if connURL == "" {
t.SkipNow()
}
table := os.Getenv("PGTABLE")
if table == "" {
table = "vault_kv_store"
}
// Run vault tests
logger := logging.NewVaultLogger(log.Debug)
2016-08-19 20:45:17 +00:00
b, err := NewPostgreSQLBackend(map[string]string{
"connection_url": connURL,
"table": table,
}, logger)
if err != nil {
t.Fatalf("Failed to create new backend: %v", err)
}
defer func() {
pg := b.(*PostgreSQLBackend)
_, err := pg.client.Exec("TRUNCATE TABLE " + pg.table)
if err != nil {
t.Fatalf("Failed to drop table: %v", err)
}
}()
physical.ExerciseBackend(t, b)
physical.ExerciseBackend_ListPrefix(t, b)
}