2017-08-03 17:24:27 +00:00
|
|
|
package cassandra
|
2017-01-07 16:30:25 +00:00
|
|
|
|
|
|
|
import (
|
2021-04-08 16:43:39 +00:00
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
2020-09-15 14:01:26 +00:00
|
|
|
"github.com/hashicorp/vault/helper/testhelpers/cassandra"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/logging"
|
|
|
|
"github.com/hashicorp/vault/sdk/physical"
|
2017-01-07 16:30:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCassandraBackend(t *testing.T) {
|
2017-01-07 17:05:07 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skipf("skipping in short mode")
|
2017-01-07 16:30:25 +00:00
|
|
|
}
|
2020-09-15 14:01:26 +00:00
|
|
|
if os.Getenv("VAULT_CI_GO_TEST_RACE") != "" {
|
|
|
|
t.Skip("skipping race test in CI pending https://github.com/gocql/gocql/pull/1474")
|
|
|
|
}
|
2017-01-07 16:30:25 +00:00
|
|
|
|
2020-09-15 14:01:26 +00:00
|
|
|
cleanup, hosts := cassandra.PrepareTestContainer(t, "")
|
2017-07-31 14:58:38 +00:00
|
|
|
defer cleanup()
|
2017-01-07 17:05:07 +00:00
|
|
|
|
2017-01-07 16:30:25 +00:00
|
|
|
// Run vault tests
|
2018-04-03 00:46:59 +00:00
|
|
|
logger := logging.NewVaultLogger(log.Debug)
|
2017-08-03 17:24:27 +00:00
|
|
|
b, err := NewCassandraBackend(map[string]string{
|
2017-06-09 01:56:46 +00:00
|
|
|
"hosts": hosts,
|
2017-08-03 17:24:27 +00:00
|
|
|
"protocol_version": "3",
|
|
|
|
}, logger)
|
2017-01-07 16:30:25 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create new backend: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-08-03 17:24:27 +00:00
|
|
|
physical.ExerciseBackend(t, b)
|
|
|
|
physical.ExerciseBackend_ListPrefix(t, b)
|
2017-01-07 16:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCassandraBackendBuckets(t *testing.T) {
|
|
|
|
expectations := map[string][]string{
|
|
|
|
"": {"."},
|
|
|
|
"a": {"."},
|
|
|
|
"a/b": {".", "a"},
|
2021-04-08 16:43:39 +00:00
|
|
|
"a/b/c/d/e": {".", "a", "a/b", "a/b/c", "a/b/c/d"},
|
|
|
|
}
|
2017-01-07 16:30:25 +00:00
|
|
|
|
|
|
|
b := &CassandraBackend{}
|
|
|
|
for input, expected := range expectations {
|
|
|
|
actual := b.buckets(input)
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Errorf("bad: %v expected: %v", actual, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|