Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kakakakakku
Copy link
Contributor

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.

$ make test TEST_PATH=tests/aws/services/ssm
(snip)
tests/aws/services/ssm/test_ssm.py::TestSSM::test_describe_parameters PASSED                                                                                                                                                                                                                                                                                                                   [  7%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_put_parameters PASSED                                                                                                                                                                                                                                                                                                                        [ 14%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_hierarchical_parameter[/<param>//b//c] PASSED                                                                                                                                                                                                                                                                                                [ 21%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_hierarchical_parameter[<param>/b/c] PASSED                                                                                                                                                                                                                                                                                                   [ 28%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_get_secret_parameter PASSED                                                                                                                                                                                                                                                                                                                  [ 35%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_get_inexistent_secret PASSED                                                                                                                                                                                                                                                                                                                 [ 42%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_get_parameters_and_secrets PASSED                                                                                                                                                                                                                                                                                                            [ 50%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_get_parameters_by_path_and_filter_by_labels PASSED                                                                                                                                                                                                                                                                                           [ 57%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_get_parameter_by_arn PASSED                                                                                                                                                                                                                                                                                                                  [ 64%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_get_parameter_history PASSED                                                                                                                                                                                                                                                                                                                 [ 71%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_get_inexistent_maintenance_window PASSED                                                                                                                                                                                                                                                                                                     [ 78%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_trigger_event_on_systems_manager_change[standard] PASSED                                                                                                                                                                                                                                                                                     [ 85%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_trigger_event_on_systems_manager_change[domain] PASSED                                                                                                                                                                                                                                                                                       [ 92%]
tests/aws/services/ssm/test_ssm.py::TestSSM::test_trigger_event_on_systems_manager_change[path] PASSED                                                                                                                                                                                                                                                                                         [100%]

Could you please review? Thanks a lot 👍

Copy link
Contributor

@localstack-bot localstack-bot left a 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.

@localstack-bot
Copy link
Contributor

localstack-bot commented Nov 13, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

try:
aws_client.ssm.delete_parameter(Name=param)
except Exception as e:
LOG.debug("error cleaning up parameter %s: %s", param, e)
Copy link
Contributor Author

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😀

https://github.com/localstack/localstack/blob/master/localstack-core/localstack/testing/pytest/fixtures.py#L163-L164

@kakakakakku
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

localstack-bot added a commit that referenced this pull request Nov 13, 2024
@silv-io silv-io added this to the Playground milestone Jan 24, 2025
@silv-io silv-io added the semver: patch Non-breaking changes which can be included in patch releases label Jan 24, 2025
Copy link
Member

@dominikschubert dominikschubert left a 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.

Comment on lines +170 to +175
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
Copy link
Member

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! 👍

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

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 😀

@kakakakakku kakakakakku force-pushed the add-tests-for-ssm-get-parameter-history branch from 77a29fb to 0f0b995 Compare January 28, 2025 12:53
@@ -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"])
Copy link
Contributor Author

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"
    }
}

Comment on lines +170 to +175
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
Copy link
Contributor Author

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"))
Copy link
Contributor Author

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

@kakakakakku
Copy link
Contributor Author

@dominikschubert
Thank you for your feedback 😀 I rebased onto the latest master branch as some time had passed since this pull request was created. And I added snapshot tests. If there are any other mistakes, I will fix them soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants