open-vault/sdk/framework/policy_map_test.go

35 lines
685 B
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
2015-04-01 22:46:13 +00:00
package framework
import (
"context"
2015-04-01 22:46:13 +00:00
"reflect"
"testing"
"github.com/hashicorp/vault/sdk/logical"
2015-04-01 22:46:13 +00:00
)
func TestPolicyMap(t *testing.T) {
p := &PolicyMap{}
p.PathMap.Name = "foo"
2015-04-01 22:46:13 +00:00
s := new(logical.InmemStorage)
ctx := context.Background()
p.Put(ctx, s, "foo", map[string]interface{}{"value": "bar"})
p.Put(ctx, s, "bar", map[string]interface{}{"value": "foo,baz "})
2015-04-01 22:46:13 +00:00
// Read via API
actual, err := p.Policies(ctx, s, "foo", "bar")
2015-04-01 22:46:13 +00:00
if err != nil {
t.Fatalf("bad: %#v", err)
}
expected := []string{"bar", "baz", "foo"}
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}