2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-01-12 23:26:07 +00:00
|
|
|
package aerospike
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-11-29 19:09:12 +00:00
|
|
|
aero "github.com/aerospike/aerospike-client-go/v5"
|
2021-01-12 23:26:07 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
2023-04-24 18:25:50 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/docker"
|
2021-01-12 23:26:07 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/logging"
|
|
|
|
"github.com/hashicorp/vault/sdk/physical"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAerospikeBackend(t *testing.T) {
|
|
|
|
cleanup, config := prepareAerospikeContainer(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
logger := logging.NewVaultLogger(log.Debug)
|
|
|
|
|
|
|
|
b, err := NewAerospikeBackend(map[string]string{
|
|
|
|
"hostname": config.hostname,
|
|
|
|
"port": config.port,
|
|
|
|
"namespace": config.namespace,
|
|
|
|
"set": config.set,
|
|
|
|
}, logger)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
physical.ExerciseBackend(t, b)
|
|
|
|
physical.ExerciseBackend_ListPrefix(t, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
type aerospikeConfig struct {
|
|
|
|
hostname string
|
|
|
|
port string
|
|
|
|
namespace string
|
|
|
|
set string
|
|
|
|
}
|
|
|
|
|
|
|
|
func prepareAerospikeContainer(t *testing.T) (func(), *aerospikeConfig) {
|
|
|
|
runner, err := docker.NewServiceRunner(docker.RunOptions{
|
2022-11-02 17:33:17 +00:00
|
|
|
ImageRepo: "docker.mirror.hashicorp.services/aerospike/aerospike-server",
|
2021-01-12 23:26:07 +00:00
|
|
|
ContainerName: "aerospikedb",
|
2021-11-29 19:09:12 +00:00
|
|
|
ImageTag: "5.6.0.5",
|
2021-01-12 23:26:07 +00:00
|
|
|
Ports: []string{"3000/tcp", "3001/tcp", "3002/tcp", "3003/tcp"},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Could not start local Aerospike: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
svc, err := runner.StartService(context.Background(),
|
|
|
|
func(ctx context.Context, host string, port int) (docker.ServiceConfig, error) {
|
|
|
|
cfg := docker.NewServiceHostPort(host, port)
|
|
|
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
client, err := aero.NewClient(host, port)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
node, err := client.Cluster().GetRandomNode()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = node.RequestInfo(aero.NewInfoPolicy(), "namespaces")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfg, nil
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Could not start local Aerospike: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return svc.Cleanup, &aerospikeConfig{
|
|
|
|
hostname: svc.Config.URL().Hostname(),
|
|
|
|
port: svc.Config.URL().Port(),
|
|
|
|
namespace: "test",
|
|
|
|
set: "vault",
|
|
|
|
}
|
|
|
|
}
|