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"
|
|
|
|
"github.com/hashicorp/vault/helper/logging"
|
2018-02-15 01:31:20 +00:00
|
|
|
"github.com/hashicorp/vault/physical"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHABackend(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")
|
|
|
|
}
|
|
|
|
|
|
|
|
haTable := os.Getenv("GOOGLE_SPANNER_HA_TABLE")
|
|
|
|
if haTable == "" {
|
|
|
|
t.Skip("GOOGLE_SPANNER_HA_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)
|
|
|
|
testCleanup(t, client, haTable)
|
|
|
|
defer testCleanup(t, client, haTable)
|
|
|
|
|
2018-11-01 17:31:09 +00:00
|
|
|
logger := logging.NewVaultLogger(log.Debug)
|
|
|
|
config := map[string]string{
|
2018-02-15 01:31:20 +00:00
|
|
|
"database": database,
|
|
|
|
"table": table,
|
|
|
|
"ha_table": haTable,
|
|
|
|
"ha_enabled": "true",
|
2018-11-01 17:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b, err := NewBackend(config, logger)
|
2018-02-15 01:31:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-11-01 17:31:09 +00:00
|
|
|
b2, err := NewBackend(config, logger)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2018-02-15 01:31:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 17:31:09 +00:00
|
|
|
physical.ExerciseHABackend(t, b.(physical.HABackend), b2.(physical.HABackend))
|
2018-02-15 01:31:20 +00:00
|
|
|
}
|