logical/testing: helper to test auth

This commit is contained in:
Mitchell Hashimoto
2015-04-01 15:16:42 -07:00
parent 235c10514c
commit c948d9ac66

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"reflect"
"testing"
"github.com/hashicorp/vault/api"
@@ -230,6 +231,21 @@ func Test(t TestT, c TestCase) {
}
}
// TestCheckAuth is a helper to check that a request generated an
// auth token with the proper policies.
func TestCheckAuth(policies []string) TestCheckFunc {
return func(resp *logical.Response) error {
if resp.Auth == nil {
return fmt.Errorf("no auth in response")
}
if !reflect.DeepEqual(resp.Auth.Policies, policies) {
return fmt.Errorf("invalid policies: %#v", resp.Auth.Policies)
}
return nil
}
}
// TestT is the interface used to handle the test lifecycle of a test.
//
// Users should just use a *testing.T object, which implements this.