diff --git a/builtin/credential/approle/path_role_test.go b/builtin/credential/approle/path_role_test.go index 5cd49a024..3b201eefb 100644 --- a/builtin/credential/approle/path_role_test.go +++ b/builtin/credential/approle/path_role_test.go @@ -18,38 +18,36 @@ import ( "github.com/mitchellh/mapstructure" ) -func TestAppRole_LocalSecretIDsRead(t *testing.T) { - var resp *logical.Response - var err error - b, storage := createBackendWithStorage(t) +func (b *backend) requestNoErr(t *testing.T, req *logical.Request) *logical.Response { + t.Helper() + resp, err := b.HandleRequest(context.Background(), req) + if err != nil || (resp != nil && resp.IsError()) { + t.Fatalf("err:%v resp:%#v", err, resp) + } + schema.ValidateResponse(t, schema.GetResponseSchema(t, b.Route(req.Path), req.Operation), resp, true) + return resp +} - paths := rolePaths(b) +func TestAppRole_LocalSecretIDsRead(t *testing.T) { + b, storage := createBackendWithStorage(t) roleData := map[string]interface{}{ "local_secret_ids": true, "bind_secret_id": true, } - resp, err = b.HandleRequest(context.Background(), &logical.Request{ + b.requestNoErr(t, &logical.Request{ Operation: logical.CreateOperation, Path: "role/testrole", Storage: storage, Data: roleData, }) - if err != nil || (resp != nil && resp.IsError()) { - t.Fatalf("err:%v resp:%#v", err, resp) - } - schema.ValidateResponse(t, schema.FindResponseSchema(t, paths, 0, logical.CreateOperation), resp, true) - resp, err = b.HandleRequest(context.Background(), &logical.Request{ + resp := b.requestNoErr(t, &logical.Request{ Operation: logical.ReadOperation, Storage: storage, Path: "role/testrole/local-secret-ids", }) - if err != nil || (resp != nil && resp.IsError()) { - t.Fatalf("err:%v resp:%#v", err, resp) - } - schema.ValidateResponse(t, schema.FindResponseSchema(t, paths, 2, logical.ReadOperation), resp, true) if !resp.Data["local_secret_ids"].(bool) { t.Fatalf("expected local_secret_ids to be returned") diff --git a/sdk/helper/testhelpers/schema/response_validation.go b/sdk/helper/testhelpers/schema/response_validation.go index 8e46fac47..2a2d6b3b5 100644 --- a/sdk/helper/testhelpers/schema/response_validation.go +++ b/sdk/helper/testhelpers/schema/response_validation.go @@ -88,11 +88,17 @@ func FindResponseSchema(t *testing.T, paths []*framework.Path, pathIdx int, oper schemaPath := paths[pathIdx] - schemaOperation, ok := schemaPath.Operations[operation] + return GetResponseSchema(t, schemaPath, operation) +} + +func GetResponseSchema(t *testing.T, path *framework.Path, operation logical.Operation) *framework.Response { + t.Helper() + + schemaOperation, ok := path.Operations[operation] if !ok { t.Fatalf( "could not find response schema: %s: %q operation does not exist", - schemaPath.Pattern, + path.Pattern, operation, ) } @@ -113,7 +119,7 @@ func FindResponseSchema(t *testing.T, paths []*framework.Path, pathIdx int, oper if len(schemaResponses) == 0 { t.Fatalf( "could not find response schema: %s: %q operation: no responses found", - schemaPath.Pattern, + path.Pattern, operation, ) }