2017-08-03 17:24:27 +00:00
|
|
|
package postgresql
|
2016-01-20 00:00:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2016-08-19 20:45:17 +00:00
|
|
|
"github.com/hashicorp/vault/helper/logformat"
|
2017-08-03 17:24:27 +00:00
|
|
|
"github.com/hashicorp/vault/physical"
|
2016-08-19 20:45:17 +00:00
|
|
|
log "github.com/mgutz/logxi/v1"
|
|
|
|
|
2016-01-20 00:00:09 +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 == "" {
|
2016-01-28 00:15:48 +00:00
|
|
|
table = "vault_kv_store"
|
2016-01-20 00:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run vault tests
|
2016-08-19 20:45:17 +00:00
|
|
|
logger := logformat.NewVaultLogger(log.LevelTrace)
|
|
|
|
|
2017-08-03 17:24:27 +00:00
|
|
|
b, err := NewPostgreSQLBackend(map[string]string{
|
2016-01-20 00:00:09 +00:00
|
|
|
"connection_url": connURL,
|
|
|
|
"table": table,
|
2017-08-03 17:24:27 +00:00
|
|
|
}, logger)
|
2016-01-20 00:00:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create new backend: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
pg := b.(*PostgreSQLBackend)
|
2016-05-26 23:07:21 +00:00
|
|
|
_, err := pg.client.Exec("TRUNCATE TABLE " + pg.table)
|
2016-01-20 00:00:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to drop table: %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-08-03 17:24:27 +00:00
|
|
|
physical.ExerciseBackend(t, b)
|
|
|
|
physical.ExerciseBackend_ListPrefix(t, b)
|
2016-01-20 00:00:09 +00:00
|
|
|
}
|