github.com/hashicorp/vault/sdk@v0.13.0/framework/wal_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package framework 5 6 import ( 7 "context" 8 "reflect" 9 "testing" 10 11 "github.com/hashicorp/vault/sdk/logical" 12 ) 13 14 func TestWAL(t *testing.T) { 15 s := new(logical.InmemStorage) 16 17 ctx := context.Background() 18 19 // WAL should be empty to start 20 keys, err := ListWAL(ctx, s) 21 if err != nil { 22 t.Fatalf("err: %s", err) 23 } 24 if len(keys) > 0 { 25 t.Fatalf("bad: %#v", keys) 26 } 27 28 // Write an entry to the WAL 29 id, err := PutWAL(ctx, s, "foo", "bar") 30 if err != nil { 31 t.Fatalf("err: %s", err) 32 } 33 34 // The key should be in the WAL 35 keys, err = ListWAL(ctx, s) 36 if err != nil { 37 t.Fatalf("err: %s", err) 38 } 39 if !reflect.DeepEqual(keys, []string{id}) { 40 t.Fatalf("bad: %#v", keys) 41 } 42 43 // Should be able to get the value 44 entry, err := GetWAL(ctx, s, id) 45 if err != nil { 46 t.Fatalf("err: %s", err) 47 } 48 if entry.Kind != "foo" { 49 t.Fatalf("bad: %#v", entry) 50 } 51 if entry.Data != "bar" { 52 t.Fatalf("bad: %#v", entry) 53 } 54 55 // Should be able to delete the value 56 if err := DeleteWAL(ctx, s, id); err != nil { 57 t.Fatalf("err: %s", err) 58 } 59 entry, err = GetWAL(ctx, s, id) 60 if err != nil { 61 t.Fatalf("err: %s", err) 62 } 63 if entry != nil { 64 t.Fatalf("bad: %#v", entry) 65 } 66 }