2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-03-18 00:05:18 +00:00
|
|
|
package framework
|
2015-03-18 00:03:00 +00:00
|
|
|
|
|
|
|
import (
|
2018-01-19 06:44:44 +00:00
|
|
|
"context"
|
2015-03-18 00:03:00 +00:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
2015-03-18 00:05:18 +00:00
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2015-03-18 00:03:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestWAL(t *testing.T) {
|
2015-03-18 00:05:18 +00:00
|
|
|
s := new(logical.InmemStorage)
|
2015-03-18 00:03:00 +00:00
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2015-03-18 00:03:00 +00:00
|
|
|
// WAL should be empty to start
|
2018-01-19 06:44:44 +00:00
|
|
|
keys, err := ListWAL(ctx, s)
|
2015-03-18 00:03:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if len(keys) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", keys)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write an entry to the WAL
|
2018-01-19 06:44:44 +00:00
|
|
|
id, err := PutWAL(ctx, s, "foo", "bar")
|
2015-03-18 00:03:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// The key should be in the WAL
|
2018-01-19 06:44:44 +00:00
|
|
|
keys, err = ListWAL(ctx, s)
|
2015-03-18 00:03:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(keys, []string{id}) {
|
|
|
|
t.Fatalf("bad: %#v", keys)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should be able to get the value
|
2018-01-19 06:44:44 +00:00
|
|
|
entry, err := GetWAL(ctx, s, id)
|
2015-03-18 00:03:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
2015-03-18 00:58:05 +00:00
|
|
|
if entry.Kind != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", entry)
|
2015-03-18 00:23:18 +00:00
|
|
|
}
|
2015-03-18 00:58:05 +00:00
|
|
|
if entry.Data != "bar" {
|
|
|
|
t.Fatalf("bad: %#v", entry)
|
2015-03-18 00:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should be able to delete the value
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := DeleteWAL(ctx, s, id); err != nil {
|
2015-03-18 00:03:00 +00:00
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
entry, err = GetWAL(ctx, s, id)
|
2015-03-18 00:03:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
2015-03-18 00:58:05 +00:00
|
|
|
if entry != nil {
|
|
|
|
t.Fatalf("bad: %#v", entry)
|
2015-03-18 00:03:00 +00:00
|
|
|
}
|
|
|
|
}
|