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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# UNRELEASED

## Bug Fixes
* Added a missing field in `PolicyResult` structure by @stefan-kiss. fixes [Issue#790](https://github.com/hashicorp/go-tfe/issues/790)

# v1.40.0

## Bug Fixes
Expand Down
1 change: 1 addition & 0 deletions policy_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

@stefan-kiss stefan-kiss Nov 30, 2023

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

}

// PolicyStatusTimestamps holds the timestamps for individual policy check
Expand Down
1 change: 1 addition & 0 deletions policy_check_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func TestPolicyChecksRead(t *testing.T) {
assert.NotEmpty(t, pc.StatusTimestamps)
assert.Equal(t, 1, pc.Result.Passed)
assert.NotEmpty(t, pc.Run)
assert.NotEmpty(t, pc.Result.Sentinel)
})

t.Run("when the policy check does not exist", func(t *testing.T) {
Expand Down