Skip to content

Commit

Permalink
AJ-1451: Fix pact provider state (#409)
Browse files Browse the repository at this point in the history
1. Use provider state to generate resource ID

By using the FromProviderState helpers, this lets the provider generate a resource ID for us, and draw our expectations around that, rather than having the client specify the IDs up front.

Since the resourceId is something WDS learns about by querying the enumerateResources endpoint, it doesn't make sense for WDS to specify it up front.

This is in contrast to the workspace ID, which we have to know about to initiate the interaction.

2. Undo variable name change in pact given: This was mistakenly left in an upstream PR where I was experimenting with a new convention to clearly mark parameters in the givens.  This wasn't intended to be merged.
  • Loading branch information
jladieu authored Nov 14, 2023
1 parent 86b9591 commit 5b66479
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class WsmPactTest {
@Pact(consumer = "wds")
RequestResponsePact linkSnapshotForPolicySuccess(PactDslWithProvider builder) {
return builder
.given("a workspace with the given {id} exists", Map.of("id", WORKSPACE_UUID.toString()))
.given("a workspace with the given id exists", Map.of("id", WORKSPACE_UUID.toString()))
.given("authenticated with the given email", Map.of("email", SNAPSHOT_CREATOR_EMAIL))
.given("policies allowing snapshot reference creation")
.uponReceiving("a request to create a snapshot reference")
Expand Down Expand Up @@ -222,6 +222,10 @@ RequestResponsePact enumerateStorageContainersWhenOneExists(PactDslWithProvider
"metadata",
m -> {
m.uuid("workspaceId", WORKSPACE_UUID);
m.valueFromProviderState(
"resourceId",
"storageContainerResourceId",
RESOURCE_UUID.toString());
m.uuid("resourceId");
m.stringMatcher(
"name",
Expand Down Expand Up @@ -337,14 +341,17 @@ RequestResponsePact createAzureStorageContainerSasTokenSuccess(PactDslWithProvid
return builder
.given("a workspace with the given id exists", Map.of("id", WORKSPACE_UUID.toString()))
.given(
"a storage container with the given id exists for the given workspace_id",
Map.of("id", RESOURCE_UUID.toString(), "workspace_id", WORKSPACE_UUID.toString()))
"a storage container resource exists for the given workspace_id",
Map.of("workspace_id", WORKSPACE_UUID.toString()))
.given("permission to create an azure storage container sas token")
.uponReceiving("a request to create an azure storage container sas token")
.method("POST")
.matchPath(
sasTokenPath(UUID_REGEX_PATTERN, UUID_REGEX_PATTERN),
sasTokenPath(WORKSPACE_UUID.toString(), RESOURCE_UUID.toString()))
.pathFromProviderState(
sasTokenPath(WORKSPACE_UUID.toString(), "${storageContainerResourceId}"),
sasTokenPath(WORKSPACE_UUID.toString(), RESOURCE_UUID.toString()))
.headers(contentTypeJson())
.willRespondWith()
.status(200) // success
Expand Down Expand Up @@ -380,14 +387,17 @@ RequestResponsePact createAzureStorageContainerSasTokenForbidden(PactDslWithProv
return builder
.given("a workspace with the given id exists", Map.of("id", WORKSPACE_UUID.toString()))
.given(
"a storage container with the given id exists for the given workspace_id",
Map.of("id", RESOURCE_UUID.toString(), "workspace_id", WORKSPACE_UUID.toString()))
"a storage container resource exists for the given workspace_id",
Map.of("workspace_id", WORKSPACE_UUID.toString()))
.given("no permission to create an azure storage container sas token")
.uponReceiving("a request to create an azure storage container sas token")
.method("POST")
.matchPath(
sasTokenPath(UUID_REGEX_PATTERN, UUID_REGEX_PATTERN),
sasTokenPath(WORKSPACE_UUID.toString(), RESOURCE_UUID.toString()))
.pathFromProviderState(
sasTokenPath(WORKSPACE_UUID.toString(), "${storageContainerResourceId}"),
sasTokenPath(WORKSPACE_UUID.toString(), RESOURCE_UUID.toString()))
.headers(contentTypeJson())
.willRespondWith()
.status(403)
Expand Down

0 comments on commit 5b66479

Please sign in to comment.