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

feat: Refactor ACR tests (PSKD-1400) #440

Closed
wants to merge 3 commits into from

Conversation

ndickens
Copy link

I wanted to add some functionality to the test cases to:

  • be able to specify the presence or absence of state resources
  • perform element matching for arrays
  • display an error message
  • in general have more control over how information is retrieved from the plan and verified

To that end I refactored TestCase to be an interface. A test could run a collection of test cases that would all implement RunTest and the underlying test type would inform how data is retrieved and verified. If there isn't a test type that suits your need then just create a new one and implement its RunTest. getExpectedFromPlan() can also be modified and extended to be able to look in different sections of the plan struct as needed.

Feedback is welcome.

test/acr_test.go Outdated
return &StringContainsTestCase{
expected: name,
path: []string{"azurerm_container_registry.acr[0]", "{$.name}"},
message: "ACR name does not contain 'acr'",

Choose a reason for hiding this comment

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

Nit: Instead of 'acr', this message should use the value of name.

func getExpectedFromPlan(plan *terraform.PlanStruct, path []string, expectedType string) (any, error) {
valuesMap := plan.ResourcePlannedValuesMap[path[0]]

if expectedType == "string" {

Choose a reason for hiding this comment

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

Non-blocking: Maybe swap to a switch and use an enum for these types.

DCO Remediation Commit for [email protected] <[email protected]>

I, [email protected] <[email protected]>, hereby add my Signed-off-by to this commit: 0b2e1ce

Signed-off-by: [email protected] <[email protected]>
DCO Remediation Commit for [email protected] <[email protected]>

I, [email protected] <[email protected]>, hereby add my Signed-off-by to this commit: 0b2e1ce

Signed-off-by: [email protected] <[email protected]>
@ndickens ndickens closed this Feb 26, 2025
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.

3 participants