-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add test for SSM GetParameterHistory API #11841
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
base: main
Are you sure you want to change the base?
Add test for SSM GetParameterHistory API #11841
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to LocalStack! Thanks for raising your first Pull Request and landing in your contributions. Our team will reach out with any reviews or feedbacks that we have shortly. We recommend joining our Slack Community and share your PR on the #community channel to share your contributions with us. Please make sure you are following our contributing guidelines and our Code of Conduct.
All contributors have signed the CLA ✍️ ✅ |
try: | ||
aws_client.ssm.delete_parameter(Name=param) | ||
except Exception as e: | ||
LOG.debug("error cleaning up parameter %s: %s", param, e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I used the existing create_parameter
method, I got the following error. Because the test calling create_parameter three times with the Overwrite=True parameter.
ERROR tests/aws/services/ssm/test_ssm.py::TestSSM::test_get_parameter_history - botocore.errorfactory.ParameterNotFound: An error occurred (ParameterNotFound) when calling the DeleteParameter operation: Parameter param-36e2b5a6 not found.
Since the parameter only needs to be deleted once, I added exception handling, referencing the existing implementation😀
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution @kakakakakku !
Sorry for the delay, but I'd love to help you get this PR over the line. Let me know if you have questions regarding the suggest change.
assert len(response["Parameters"]) == 3 | ||
assert response["Parameters"][0]["Value"] == "test" | ||
assert response["Parameters"][0]["Version"] == 1 | ||
assert response["Parameters"][2]["Value"] == "test3" | ||
assert response["Parameters"][2]["Version"] == 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically we'd use our snapshot library in these cases, which will also catch changes to the API if we re-validate the case in the future. You can find more information on this in our contribution guidelines.
Please let me know if you'd like to tackle this yourself, otherwise I can also generate this for you! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I will add snapshot test soon :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: When using snapshots test, are regular assertions like this unnecessary? Or is it better to have both? Looking at the existing tests in the same file, it seems there are tests using assertions. If it’s not needed, I’ll remove it 😀
77a29fb
to
0f0b995
Compare
@@ -159,6 +159,25 @@ def test_get_parameter_by_arn(self, create_parameter, aws_client, snapshot, clea | |||
snapshot.match("Parameter", parameter_by_arn) | |||
snapshot.add_transformer(snapshot.transform.key_value("Name")) | |||
|
|||
@markers.aws.validated | |||
@markers.snapshot.skip_snapshot_verify(paths=["$..Tier", "$..Policies"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that LocalStack does not support the Tier
and Policies
response fields. Therefore, I used the skip_snapshot_verify
marker. Is this correct?
$ awslocal ssm put-parameter --name sandbox --type String --value value1
{
"Version": 1
}
$ awslocal ssm put-parameter --name sandbox --type String --value value2 --overwrite
{
"Version": 2
}
$ awslocal ssm put-parameter --name sandbox --type String --value value3 --overwrite
{
"Version": 3
}
$ awslocal ssm get-parameter --name sandbox
{
"Parameter": {
"Name": "sandbox",
"Type": "String",
"Value": "value3",
"Version": 3,
"LastModifiedDate": "2025-01-28T21:51:59.532000+09:00",
"ARN": "arn:aws:ssm:ap-northeast-1:000000000000:parameter/sandbox",
"DataType": "text"
}
}
assert len(response["Parameters"]) == 3 | ||
assert response["Parameters"][0]["Value"] == "test" | ||
assert response["Parameters"][0]["Version"] == 1 | ||
assert response["Parameters"][2]["Value"] == "test3" | ||
assert response["Parameters"][2]["Version"] == 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: When using snapshots test, are regular assertions like this unnecessary? Or is it better to have both? Looking at the existing tests in the same file, it seems there are tests using assertions. If it’s not needed, I’ll remove it 😀
|
||
snapshot.match("get-parameter-history-response", response) | ||
snapshot.add_transformer(snapshot.transform.key_value("Name")) | ||
snapshot.add_transformer(snapshot.transform.key_value("LastModifiedUser")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your kind support. I captured the snapshot in my personal AWS account 👍
$ export SNAPSHOT_UPDATE=1
$ export TEST_TARGET=AWS_CLOUD
$ make test TEST_PATH=tests/aws/services/ssm
@dominikschubert |
Hi! I regularly use LocalStack, and thank you for such an awesome product😀
Motivation
Recently, while using LocalStack’s SSM Parameter Store, I checked the API coverage and found that some APIs were not marked in the "Internal Test Suite". So I wanted to contribute by adding tests.
Changes
In this Pull Request, I’ve added a test for the SSM
GetParameterHistory
API to improve coverage.Testing
The tests passed in my local environment.
Could you please review? Thanks a lot 👍