mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
Clean up HABackend tests (#5617)
This commit is contained in:
committed by
GitHub
parent
934ec9305b
commit
6d6fbf2f57
@@ -558,22 +558,24 @@ func TestConsulHABackend(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
logger := logging.NewVaultLogger(log.Debug)
|
logger := logging.NewVaultLogger(log.Debug)
|
||||||
|
config := map[string]string{
|
||||||
b, err := NewConsulBackend(map[string]string{
|
|
||||||
"address": conf.Address,
|
"address": conf.Address,
|
||||||
"path": randPath,
|
"path": randPath,
|
||||||
"max_parallel": "-1",
|
"max_parallel": "-1",
|
||||||
"token": conf.Token,
|
"token": conf.Token,
|
||||||
}, logger)
|
}
|
||||||
|
|
||||||
|
b, err := NewConsulBackend(config, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ha, ok := b.(physical.HABackend)
|
b2, err := NewConsulBackend(config, logger)
|
||||||
if !ok {
|
if err != nil {
|
||||||
t.Fatalf("consul does not implement HABackend")
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
physical.ExerciseHABackend(t, ha, ha)
|
|
||||||
|
physical.ExerciseHABackend(t, b.(physical.HABackend), b2.(physical.HABackend))
|
||||||
|
|
||||||
detect, ok := b.(physical.RedirectDetect)
|
detect, ok := b.(physical.RedirectDetect)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -147,24 +147,27 @@ func TestDynamoDBHABackend(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
logger := logging.NewVaultLogger(log.Debug)
|
logger := logging.NewVaultLogger(log.Debug)
|
||||||
b, err := NewDynamoDBBackend(map[string]string{
|
config := map[string]string{
|
||||||
"access_key": creds.AccessKeyID,
|
"access_key": creds.AccessKeyID,
|
||||||
"secret_key": creds.SecretAccessKey,
|
"secret_key": creds.SecretAccessKey,
|
||||||
"session_token": creds.SessionToken,
|
"session_token": creds.SessionToken,
|
||||||
"table": table,
|
"table": table,
|
||||||
"region": region,
|
"region": region,
|
||||||
"endpoint": endpoint,
|
"endpoint": endpoint,
|
||||||
}, logger)
|
}
|
||||||
|
|
||||||
|
b, err := NewDynamoDBBackend(config, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ha, ok := b.(physical.HABackend)
|
b2, err := NewDynamoDBBackend(config, logger)
|
||||||
if !ok {
|
if err != nil {
|
||||||
t.Fatalf("dynamodb does not implement HABackend")
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
physical.ExerciseHABackend(t, ha, ha)
|
|
||||||
testDynamoDBLockTTL(t, ha)
|
physical.ExerciseHABackend(t, b.(physical.HABackend), b2.(physical.HABackend))
|
||||||
|
testDynamoDBLockTTL(t, b.(physical.HABackend))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similar to testHABackend, but using internal implementation details to
|
// Similar to testHABackend, but using internal implementation details to
|
||||||
|
|||||||
@@ -18,21 +18,22 @@ func TestEtcd3Backend(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger := logging.NewVaultLogger(log.Debug)
|
logger := logging.NewVaultLogger(log.Debug)
|
||||||
|
config := map[string]string{
|
||||||
b, err := NewEtcdBackend(map[string]string{
|
|
||||||
"path": fmt.Sprintf("/vault-%d", time.Now().Unix()),
|
"path": fmt.Sprintf("/vault-%d", time.Now().Unix()),
|
||||||
"etcd_api": "3",
|
"etcd_api": "3",
|
||||||
}, logger)
|
}
|
||||||
|
|
||||||
|
b, err := NewEtcdBackend(config, logger)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
b2, err := NewEtcdBackend(config, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
physical.ExerciseBackend(t, b)
|
physical.ExerciseBackend(t, b)
|
||||||
physical.ExerciseBackend_ListPrefix(t, b)
|
physical.ExerciseBackend_ListPrefix(t, b)
|
||||||
|
physical.ExerciseHABackend(t, b.(physical.HABackend), b2.(physical.HABackend))
|
||||||
ha, ok := b.(physical.HABackend)
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("etcd3 does not implement HABackend")
|
|
||||||
}
|
|
||||||
physical.ExerciseHABackend(t, ha, ha)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,20 +52,21 @@ func TestEtcdBackend(t *testing.T) {
|
|||||||
// Generate new etcd backend. The etcd address is read from ETCD_ADDR. No
|
// Generate new etcd backend. The etcd address is read from ETCD_ADDR. No
|
||||||
// need to provide it explicitly.
|
// need to provide it explicitly.
|
||||||
logger := logging.NewVaultLogger(log.Debug)
|
logger := logging.NewVaultLogger(log.Debug)
|
||||||
|
config := map[string]string{
|
||||||
b, err := NewEtcdBackend(map[string]string{
|
|
||||||
"path": randPath,
|
"path": randPath,
|
||||||
}, logger)
|
}
|
||||||
|
|
||||||
|
b, err := NewEtcdBackend(config, logger)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
b2, err := NewEtcdBackend(config, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
physical.ExerciseBackend(t, b)
|
physical.ExerciseBackend(t, b)
|
||||||
physical.ExerciseBackend_ListPrefix(t, b)
|
physical.ExerciseBackend_ListPrefix(t, b)
|
||||||
|
physical.ExerciseHABackend(t, b.(physical.HABackend), b2.(physical.HABackend))
|
||||||
ha, ok := b.(physical.HABackend)
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("etcd does not implement HABackend")
|
|
||||||
}
|
|
||||||
physical.ExerciseHABackend(t, ha, ha)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,39 +110,26 @@ func TestFoundationDBBackend(t *testing.T) {
|
|||||||
|
|
||||||
// Run vault tests
|
// Run vault tests
|
||||||
logger := logging.NewVaultLogger(log.Debug)
|
logger := logging.NewVaultLogger(log.Debug)
|
||||||
b, err := NewFDBBackend(map[string]string{
|
config := map[string]string{
|
||||||
"path": topDir,
|
"path": topDir,
|
||||||
"api_version": "510",
|
"api_version": "510",
|
||||||
"cluster_file": clusterFile,
|
"cluster_file": clusterFile,
|
||||||
}, logger)
|
}
|
||||||
|
|
||||||
|
b, err := NewFDBBackend(config, logger)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("foundationdb: failed to create new backend: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
b2, err := NewFDBBackend(config, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("foundationdb: failed to create new backend: %s", err)
|
t.Fatalf("foundationdb: failed to create new backend: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
physical.ExerciseBackend(t, b)
|
physical.ExerciseBackend(t, b)
|
||||||
physical.ExerciseBackend_ListPrefix(t, b)
|
physical.ExerciseBackend_ListPrefix(t, b)
|
||||||
|
|
||||||
physical.ExerciseTransactionalBackend(t, b)
|
physical.ExerciseTransactionalBackend(t, b)
|
||||||
|
physical.ExerciseHABackend(t, b.(physical.HABackend), b2.(physical.HABackend))
|
||||||
ha1, ok := b.(physical.HABackend)
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("foundationdb does not implement HABackend")
|
|
||||||
}
|
|
||||||
|
|
||||||
b2, err := NewFDBBackend(map[string]string{
|
|
||||||
"path": topDir,
|
|
||||||
"api_version": "510",
|
|
||||||
"cluster_file": clusterFile,
|
|
||||||
}, logger)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("foundationdb: failed to create new backend for HA test: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ha2 := b2.(physical.HABackend)
|
|
||||||
|
|
||||||
physical.ExerciseHABackend(t, ha1, ha2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareFoundationDBTestDirectory(t *testing.T, topDir string) (func(), string) {
|
func prepareFoundationDBTestDirectory(t *testing.T, topDir string) (func(), string) {
|
||||||
|
|||||||
@@ -32,25 +32,28 @@ func TestHABackend(t *testing.T) {
|
|||||||
testCleanup(t, client, bucket)
|
testCleanup(t, client, bucket)
|
||||||
defer testCleanup(t, client, bucket)
|
defer testCleanup(t, client, bucket)
|
||||||
|
|
||||||
b := client.Bucket(bucket)
|
bh := client.Bucket(bucket)
|
||||||
if err := b.Create(context.Background(), projectID, nil); err != nil {
|
if err := bh.Create(context.Background(), projectID, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
backend, err := NewBackend(map[string]string{
|
logger := logging.NewVaultLogger(log.Trace)
|
||||||
|
config := map[string]string{
|
||||||
"bucket": bucket,
|
"bucket": bucket,
|
||||||
"ha_enabled": "true",
|
"ha_enabled": "true",
|
||||||
}, logging.NewVaultLogger(log.Trace))
|
}
|
||||||
|
|
||||||
|
b, err := NewBackend(config, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ha, ok := backend.(physical.HABackend)
|
b2, err := NewBackend(config, logger)
|
||||||
if !ok {
|
if err != nil {
|
||||||
t.Fatalf("does not implement")
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
physical.ExerciseBackend(t, backend)
|
physical.ExerciseBackend(t, b)
|
||||||
physical.ExerciseBackend_ListPrefix(t, backend)
|
physical.ExerciseBackend_ListPrefix(t, b)
|
||||||
physical.ExerciseHABackend(t, ha, ha)
|
physical.ExerciseHABackend(t, b.(physical.HABackend), b2.(physical.HABackend))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,5 +15,7 @@ func TestInmemHA(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use the same inmem backend to acquire the same set of locks
|
||||||
physical.ExerciseHABackend(t, inm.(physical.HABackend), inm.(physical.HABackend))
|
physical.ExerciseHABackend(t, inm.(physical.HABackend), inm.(physical.HABackend))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,16 +78,16 @@ func TestMySQLHABackend(t *testing.T) {
|
|||||||
|
|
||||||
// Run vault tests
|
// Run vault tests
|
||||||
logger := logging.NewVaultLogger(log.Debug)
|
logger := logging.NewVaultLogger(log.Debug)
|
||||||
|
config := map[string]string{
|
||||||
b, err := NewMySQLBackend(map[string]string{
|
|
||||||
"address": address,
|
"address": address,
|
||||||
"database": database,
|
"database": database,
|
||||||
"table": table,
|
"table": table,
|
||||||
"username": username,
|
"username": username,
|
||||||
"password": password,
|
"password": password,
|
||||||
"ha_enabled": "true",
|
"ha_enabled": "true",
|
||||||
}, logger)
|
}
|
||||||
|
|
||||||
|
b, err := NewMySQLBackend(config, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create new backend: %v", err)
|
t.Fatalf("Failed to create new backend: %v", err)
|
||||||
}
|
}
|
||||||
@@ -100,9 +100,10 @@ func TestMySQLHABackend(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ha, ok := b.(physical.HABackend)
|
b2, err := NewMySQLBackend(config, logger)
|
||||||
if !ok {
|
if err != nil {
|
||||||
t.Fatalf("MySQL does not implement HABackend")
|
t.Fatalf("Failed to create new backend: %v", err)
|
||||||
}
|
}
|
||||||
physical.ExerciseHABackend(t, ha, ha)
|
|
||||||
|
physical.ExerciseHABackend(t, b.(physical.HABackend), b2.(physical.HABackend))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,20 +38,23 @@ func TestHABackend(t *testing.T) {
|
|||||||
testCleanup(t, client, haTable)
|
testCleanup(t, client, haTable)
|
||||||
defer testCleanup(t, client, haTable)
|
defer testCleanup(t, client, haTable)
|
||||||
|
|
||||||
backend, err := NewBackend(map[string]string{
|
logger := logging.NewVaultLogger(log.Debug)
|
||||||
|
config := map[string]string{
|
||||||
"database": database,
|
"database": database,
|
||||||
"table": table,
|
"table": table,
|
||||||
"ha_table": haTable,
|
"ha_table": haTable,
|
||||||
"ha_enabled": "true",
|
"ha_enabled": "true",
|
||||||
}, logging.NewVaultLogger(log.Debug))
|
}
|
||||||
|
|
||||||
|
b, err := NewBackend(config, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ha, ok := backend.(physical.HABackend)
|
b2, err := NewBackend(config, logger)
|
||||||
if !ok {
|
if err != nil {
|
||||||
t.Fatalf("does not implement")
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
physical.ExerciseHABackend(t, ha, ha)
|
physical.ExerciseHABackend(t, b.(physical.HABackend), b2.(physical.HABackend))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ func ExerciseHABackend(t testing.TB, b HABackend, b2 HABackend) {
|
|||||||
t.Fatalf("stop lock 2: %v", err)
|
t.Fatalf("stop lock 2: %v", err)
|
||||||
}
|
}
|
||||||
if leaderCh2 != nil {
|
if leaderCh2 != nil {
|
||||||
t.Errorf("should not have gotten leaderCh: %v", leaderCh)
|
t.Errorf("should not have gotten leaderCh: %v", leaderCh2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release the first lock
|
// Release the first lock
|
||||||
@@ -352,7 +352,7 @@ func ExerciseHABackend(t testing.TB, b HABackend, b2 HABackend) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check the value
|
// Check the value
|
||||||
held, val, err = lock.Value()
|
held, val, err = lock2.Value()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("value: %v", err)
|
t.Fatalf("value: %v", err)
|
||||||
}
|
}
|
||||||
@@ -360,7 +360,7 @@ func ExerciseHABackend(t testing.TB, b HABackend, b2 HABackend) {
|
|||||||
t.Errorf("should still be held")
|
t.Errorf("should still be held")
|
||||||
}
|
}
|
||||||
if val != "baz" {
|
if val != "baz" {
|
||||||
t.Errorf("expected value baz: %v", err)
|
t.Errorf("expected: baz, got: %v", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
|||||||
@@ -85,18 +85,20 @@ func TestZooKeeperHABackend(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
logger := logging.NewVaultLogger(log.Debug)
|
logger := logging.NewVaultLogger(log.Debug)
|
||||||
|
config := map[string]string{
|
||||||
b, err := NewZooKeeperBackend(map[string]string{
|
|
||||||
"address": addr + "," + addr,
|
"address": addr + "," + addr,
|
||||||
"path": randPath,
|
"path": randPath,
|
||||||
}, logger)
|
}
|
||||||
|
|
||||||
|
b, err := NewZooKeeperBackend(config, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ha, ok := b.(physical.HABackend)
|
b2, err := NewZooKeeperBackend(config, logger)
|
||||||
if !ok {
|
if err != nil {
|
||||||
t.Fatalf("zookeeper does not implement HABackend")
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
physical.ExerciseHABackend(t, ha, ha)
|
|
||||||
|
physical.ExerciseHABackend(t, b.(physical.HABackend), b2.(physical.HABackend))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user