2018-02-15 01:31:20 +00:00
|
|
|
package spanner
|
|
|
|
|
|
|
|
import (
|
2018-07-13 15:00:38 +00:00
|
|
|
"context"
|
2018-02-15 01:31:20 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"cloud.google.com/go/spanner"
|
2018-04-03 00:46:59 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/logging"
|
|
|
|
"github.com/hashicorp/vault/sdk/physical"
|
2018-02-15 01:31:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func testCleanup(t testing.TB, client *spanner.Client, table string) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
// Delete all data in the table
|
|
|
|
ctx := context.Background()
|
|
|
|
m := spanner.Delete(table, spanner.AllKeys())
|
|
|
|
if _, err := client.Apply(ctx, []*spanner.Mutation{m}); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBackend(t *testing.T) {
|
|
|
|
database := os.Getenv("GOOGLE_SPANNER_DATABASE")
|
|
|
|
if database == "" {
|
|
|
|
t.Skip("GOOGLE_SPANNER_DATABASE not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
table := os.Getenv("GOOGLE_SPANNER_TABLE")
|
|
|
|
if table == "" {
|
|
|
|
t.Skip("GOOGLE_SPANNER_TABLE not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
client, err := spanner.NewClient(ctx, database)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCleanup(t, client, table)
|
|
|
|
defer testCleanup(t, client, table)
|
|
|
|
|
|
|
|
backend, err := NewBackend(map[string]string{
|
|
|
|
"database": database,
|
|
|
|
"table": table,
|
|
|
|
"ha_enabled": "false",
|
2018-04-03 00:46:59 +00:00
|
|
|
}, logging.NewVaultLogger(log.Debug))
|
2018-02-15 01:31:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
physical.ExerciseBackend(t, backend)
|
|
|
|
physical.ExerciseBackend_ListPrefix(t, backend)
|
|
|
|
physical.ExerciseTransactionalBackend(t, backend)
|
|
|
|
}
|