open-vault/sdk/framework/wal_test.go

64 lines
1.1 KiB
Go
Raw Normal View History

package framework
2015-03-18 00:03:00 +00:00
import (
"context"
2015-03-18 00:03:00 +00:00
"reflect"
"testing"
"github.com/hashicorp/vault/sdk/logical"
2015-03-18 00:03:00 +00:00
)
func TestWAL(t *testing.T) {
s := new(logical.InmemStorage)
2015-03-18 00:03:00 +00:00
ctx := context.Background()
2015-03-18 00:03:00 +00:00
// WAL should be empty to start
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
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
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
entry, err := GetWAL(ctx, s, id)
2015-03-18 00:03:00 +00:00
if err != nil {
t.Fatalf("err: %s", err)
}
if entry.Kind != "foo" {
t.Fatalf("bad: %#v", entry)
}
if entry.Data != "bar" {
t.Fatalf("bad: %#v", entry)
2015-03-18 00:03:00 +00:00
}
// Should be able to delete the value
if err := DeleteWAL(ctx, s, id); err != nil {
2015-03-18 00:03:00 +00:00
t.Fatalf("err: %s", err)
}
entry, err = GetWAL(ctx, s, id)
2015-03-18 00:03:00 +00:00
if err != nil {
t.Fatalf("err: %s", err)
}
if entry != nil {
t.Fatalf("bad: %#v", entry)
2015-03-18 00:03:00 +00:00
}
}