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

fix: adding missing sentinel field to PolicyCheck #824

Closed
wants to merge 2 commits into from

Conversation

stefan-kiss
Copy link
Contributor

Description

PolicyResult structure is missing an additional field returned by the api

Testing plan

External links

https://developer.hashicorp.com/terraform/cloud-docs/api-docs/policy-checks#sample-response
#790

Output from tests

Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.

/usr/local/opt/go/libexec/bin/go tool test2json -t /Users/skiss/Library/Caches/JetBrains/GoLand2023.2/tmp/GoLand/___TestPolicyChecksRead_in_github_com_hashicorp_go_tfe.test -test.v -test.paniconexit0 -test.run ^\QTestPolicyChecksRead\E$
=== RUN   TestPolicyChecksRead
    helper_test.go:1226: Polling run "run-hGVffWH2vb8cEWp1" for status included in ["policy_checked" "policy_override" "errored"] with deadline of 2023-11-25 20:40:20.339614 +0200 EET m=+124.232394161
    helper_test.go:1232: ...
    helper_test.go:1290: Reading run "run-hGVffWH2vb8cEWp1"
    helper_test.go:1238: Run "run-hGVffWH2vb8cEWp1" had status "plan_queued"
    helper_test.go:1232: ...
    helper_test.go:1290: Reading run "run-hGVffWH2vb8cEWp1"
    helper_test.go:1238: Run "run-hGVffWH2vb8cEWp1" had status "planning"
    helper_test.go:1232: ...
    helper_test.go:1290: Reading run "run-hGVffWH2vb8cEWp1"
    helper_test.go:1238: Run "run-hGVffWH2vb8cEWp1" had status "planning"
    helper_test.go:1232: ...
    helper_test.go:1290: Reading run "run-hGVffWH2vb8cEWp1"
    helper_test.go:1238: Run "run-hGVffWH2vb8cEWp1" had status "policy_checking"
    helper_test.go:1232: ...
    helper_test.go:1290: Reading run "run-hGVffWH2vb8cEWp1"
    helper_test.go:1238: Run "run-hGVffWH2vb8cEWp1" had status "policy_checked"
--- PASS: TestPolicyChecksRead (15.74s)
=== RUN   TestPolicyChecksRead/when_the_policy_check_exists
    --- PASS: TestPolicyChecksRead/when_the_policy_check_exists (0.18s)
=== RUN   TestPolicyChecksRead/when_the_policy_check_does_not_exist
    --- PASS: TestPolicyChecksRead/when_the_policy_check_does_not_exist (0.16s)
=== RUN   TestPolicyChecksRead/without_a_valid_policy_check_ID
    --- PASS: TestPolicyChecksRead/without_a_valid_policy_check_ID (0.00s)
PASS

Process finished with the exit code 0

@stefan-kiss stefan-kiss requested a review from a team as a code owner November 25, 2023 18:41
@@ -101,6 +101,7 @@ type PolicyResult struct {
Result bool `jsonapi:"attr,result"`
SoftFailed int `jsonapi:"attr,soft-failed"`
TotalFailed int `jsonapi:"attr,total-failed"`
Sentinel any `jsonapi:"attr,sentinel"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I should know this but I don't. What will be the value after unmarshaling? map[string]any? I wonder if this can be demonstrated in the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it’s just interface{} afaik. can be type asserted into anything. i think it’s appropriate since the api does not define a type for it. i’ll output and paste some reflection debug later tonight to show how this unmarshalls from the tests

later edit:
with the current test data we unmarshall this to:

map[string]interface {}{"data":map[string]interface {}{"":map[string]interface {}{"error":interface {}(nil), "policies":[]interface {}{map[string]interface {}{"error":interface {}(nil), "policy":map[string]interface {}{"enforcement-level":"soft-mandatory", "name":"5fac59c6-6782-11dd-784c-f0f7d0023d5d"}, "result":true, "trace":map[string]interface {}{"description":"", "error":interface {}(nil), "print":"", "result":true, "rules":map[string]interface {}{"main":map[string]interface {}{"desc":"", "ident":"main", "position":map[string]interface {}{"column":1, "filename":"./5fac59c6-6782-11dd-784c-f0f7d0023d5d.sentinel", "line":1, "offset":0}, "value":true}}}}}, "result":true}}, "schema-version":1}

we can add some tests for the current data if you want. but i would keep the type as any

@brandonc
Copy link
Collaborator

brandonc commented Jan 2, 2024

Moved to a local branch (for CI reasons) on #832

brandonc added a commit that referenced this pull request Jan 2, 2024
@brandonc
Copy link
Collaborator

brandonc commented Jan 2, 2024

Merged as #832 . Thank you!

@brandonc brandonc closed this Jan 2, 2024
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.

None yet

2 participants