Skip to content

Conversation

@ytsarev
Copy link
Member

@ytsarev ytsarev commented Jan 6, 2025

Description of your changes

  • Ability to mock out az resource graph query result to enable proper testing on unit level
  • Refactor to smaller internal functions
  • Add associated test case for query result to XR status propagation

Tests

  • Unit
go test -v -cover .
=== RUN   TestRunFunction
=== RUN   TestRunFunction/ResponseIsReturned
=== RUN   TestRunFunction/ResponseIsReturnedWithOptionalManagementGroups
=== RUN   TestRunFunction/ShouldUpdateXRStatus
--- PASS: TestRunFunction (0.00s)
    --- PASS: TestRunFunction/ResponseIsReturned (0.00s)
    --- PASS: TestRunFunction/ResponseIsReturnedWithOptionalManagementGroups (0.00s)
    --- PASS: TestRunFunction/ShouldUpdateXRStatus (0.00s)
PASS
coverage: 44.6% of statements
ok  	github.com/upboundcare/function-azresourcegraph	(cached)	coverage: 44.6% of statements
  • Integration with running function in dev mode
go run . --insecure --debug

crossplane render example/xr.yaml example/composition.yaml example/functions-dev.yaml --function-credentials=example/secrets/azure-creds-real.yaml -r
---
apiVersion: example.crossplane.io/v1
kind: XR
metadata:
  name: example-xr
status:
  azResourceGraphQueryResult:
  - id: /subscriptions/<redacted>/resourceGroups/us-vm-zxqnj-
  conditions:
  - lastTransitionTime: "2024-01-01T00:00:00Z"
    reason: Available
    status: "True"
    type: Ready
---
apiVersion: render.crossplane.io/v1beta1
kind: Result
message: 'Query: "Resources | project name, location, type, id| where type =~ ''Microsoft.Compute/virtualMachines''
  | order by name desc"'
severity: SEVERITY_NORMAL
step: query-azresourcegraph

I have:

@ytsarev ytsarev changed the title Refactor to smaller internal functions, add ability to mock out query result in the unit test suite Add ability to mock out the azure query result in the unit test suite Jan 6, 2025
Copy link

@kaessert kaessert left a comment

Choose a reason for hiding this comment

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

lgtm

@ytsarev ytsarev merged commit f215ad2 into main Jan 6, 2025
5 checks passed
@ytsarev ytsarev deleted the test-suite-mock-api branch January 6, 2025 15:44
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