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

Add pulumi tests #1894

Merged

Conversation

jemrobinson
Copy link
Member

@jemrobinson jemrobinson commented May 16, 2024

✅ Checklist

  • You have given your pull request a meaningful title (e.g. Enable foobar integration rather than 515 foobar).
  • You are targeting the appropriate branch. If you're not certain which one this is, it should be develop.
  • Your branch is up-to-date with the target branch (it probably was when you started, but it may have changed since then).

🚦 Depends on

n/a

⤴️ Summary

Adds some proof-of-concept Pulumi unit tests for the SRE ApplicationGateway component.

Note that much of what is described in the Pulumi documentation about Mocking does not seem to work with inline programs.

Important notes:

  • Pulumi Outputs should be tested within an apply loop with run_with_unknowns enabled, otherwise they will silently succeed on encountering any unknown values
  • Value-based assertions need to be defined separately (currently in resource_assertions.py) as raw assert cannot be used inside an apply loop
  • All tests must be decorated with pulumi.runtime.test or they will silently succeed
  • Any sub-resource that we want to test needs to be exposed as an attribute of the Component class (e.g. SREApplicationGateway now has self.application_gateway = ... in its constructor so that we can test the ApplicationGateway resource.

🌂 Related issues

Closes #1835

🔬 Tests

Copy link

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  data_safe_haven/external/interface
  azure_ipv4_range.py
  data_safe_haven/infrastructure/common
  transformations.py 16, 31, 39, 47, 80, 88, 96, 104, 112
  data_safe_haven/infrastructure/programs/sre
  application_gateway.py
  tests/infrastructure/programs
  resource_assertions.py 9-11
  tests/infrastructure/programs/sre
  conftest.py
  test_application_gateway.py
Project Total  

This report was generated by python-coverage-comment-action

@jemrobinson jemrobinson changed the title WIP: Add pulumi tests Add pulumi tests May 17, 2024
@jemrobinson jemrobinson marked this pull request as ready for review May 17, 2024 12:07
@jemrobinson jemrobinson requested a review from a team as a code owner May 17, 2024 12:07
@jemrobinson jemrobinson requested review from a team, craddm and JimMadge May 17, 2024 12:07
Copy link
Member

@JimMadge JimMadge left a comment

Choose a reason for hiding this comment

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

Looks good.

Helpful as an example when we write more Pulumi tests in the future.

Having to .apply() does make tests a bit untidy but I suppose that is just what happens when working with promises.
If we wanted to do more "abstract" tests like

assert "Internet" not in sre_nsg.rules.allowed

we might have to write bespoke functions or lambdas in test functions.

@jemrobinson
Copy link
Member Author

@JimMadge I think the kind of abstract test you're thinking of could be better covered by property tests on deployed infrastructure.

@jemrobinson jemrobinson merged commit 363329e into alan-turing-institute:develop May 20, 2024
11 checks passed
@jemrobinson jemrobinson deleted the 1835-add-pulumi-tests branch June 3, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Pulumi tests
2 participants