logical/framework: rollback support

This commit is contained in:
Mitchell Hashimoto
2015-03-17 17:15:23 -07:00
parent 79af0e5d9e
commit e77f79b317
2 changed files with 80 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package framework
import (
"reflect"
"sync/atomic"
"testing"
"github.com/hashicorp/vault/logical"
@@ -135,6 +136,38 @@ func TestBackendHandleRequest_help(t *testing.T) {
}
}
func TestBackendHandleRequest_rollback(t *testing.T) {
var called uint32
callback := func(data interface{}) bool {
if data == "foo" {
atomic.AddUint32(&called, 1)
}
return true
}
b := &Backend{
Rollback: callback,
}
storage := new(logical.InmemStorage)
if _, err := PutWAL(storage, "foo"); err != nil {
t.Fatalf("err: %s", err)
}
_, err := b.HandleRequest(&logical.Request{
Operation: logical.RollbackOperation,
Path: "",
Storage: storage,
})
if err != nil {
t.Fatalf("err: %s", err)
}
if v := atomic.LoadUint32(&called); v != 1 {
t.Fatalf("bad: %#v", v)
}
}
func TestBackendHandleRequest_unsupportedOperation(t *testing.T) {
callback := func(req *logical.Request, data *FieldData) (*logical.Response, error) {
return &logical.Response{