Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stackId not setable during 'cfn invoke' testing of RESOURCE #999

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/rpdk/core/invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def invoke(args):
request["desiredResourceState"],
request["previousResourceState"],
request.get("typeConfiguration"),
stackId=request.get("stackId")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stack id is not always present, as this is purely CloudFormation concept. Resource Handlers are also used by CloudControl, which does not provide value for this field. I would prefer to left it out of cfn invoke payload.

) # pylint: disable=too-many-function-args

current_invocation = 0
Expand Down
31 changes: 31 additions & 0 deletions tests/contract/test_resource_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,37 @@ def test_make_payload(resource_client):
}


def test_make_payload_with_stack_id(resource_client):
patch_creds = patch(
"rpdk.core.contract.resource_client.get_temporary_credentials",
autospec=True,
return_value={},
)

token = "ecba020e-b2e6-4742-a7d0-8a06ae7c4b2f"
with patch.object(
resource_client, "generate_token", return_value=token
), patch_creds:
payload = resource_client._make_payload("CREATE", {"foo": "bar"}, stackId="test-stack")

assert payload == {
"requestData": {
"callerCredentials": {},
"resourceProperties": {"foo": "bar"},
"previousResourceProperties": None,
"logicalResourceId": token,
"typeConfiguration": None,
},
"region": DEFAULT_REGION,
"awsAccountId": ACCOUNT,
"action": "CREATE",
"bearerToken": token,
"callbackContext": None,
"resourceType": None,
"stackId": "test-stack",
}


@pytest.mark.parametrize("action", [Action.READ, Action.LIST])
def test_call_sync(resource_client, action):
patch_creds = patch(
Expand Down