-
Notifications
You must be signed in to change notification settings - Fork 17
List Resource QueryCheck #533
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
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
954b002
Initial work on Query command for List Resource
rainkwan 99e9c88
Added helper/resource parts for query
rainkwan 870fff0
Moved files
rainkwan ede917c
But what if we comment out print statements?
rainkwan 06d2573
What if we are more specific and say `.tfquery.hcl`
rainkwan 236218d
Updating to version 1.14 for query_test.go
rainkwan 49004cd
Scaffolding for QueryCheck
rainkwan 086d38c
Outlining the marshalling for filling in terraform-json.Query
rainkwan cb0e717
Update testing_new.go
rainkwan f3be28d
Update helper/resource/query/query_test.go
rainkwan b5c37ca
Update internal/plugintest/working_dir.go
rainkwan 896310e
Update internal/teststep/file.go
rainkwan 116911f
Updating branch
rainkwan fef3bb6
Working on using unmarshalled buffer instead of tfjson
rainkwan a8e37e2
Removed tests that get skipped for version
rainkwan f59ae5d
pass reattach info into QueryJSON call
stephybun 280f10b
unmarshal found list result
stephybun 549962f
change tfversion checks to skip below `1.14`
SBGoods a46b2dc
try unmarshalling query results and traversing using `tfjsonpath`
SBGoods 6953c7f
Updated go mod to latest
rainkwan 95081f8
Changes from pairing
rainkwan 884dfff
Updated terraform exec with new draft and initial query test in helpe…
rainkwan d531120
Updated to add error handling for returned terraform exec boolean
rainkwan d1418a8
Pushing for up to dateness
rainkwan 22e003c
updating providerserver.go
rainkwan 53ecea9
Updated the query test to return actual identity and start to impleme…
rainkwan 5cbd9f7
fixed test so expect_identity.go runs
rainkwan b6e6c9c
Refactored expect_identity.go so it works for multiple identity attri…
rainkwan a6c11c2
Changes by sgoods
rainkwan 3d77c5b
Updated error messages
rainkwan fd46aa7
Updated error messages
rainkwan 02d6caa
Updated comment
rainkwan 3331b2b
add contains query check for checking if a given resource exists in t…
stephybun c465a33
update CheckQueryRequest to provide ListResourceFoundData and ListCom…
stephybun 10dd78c
add expect known value check
stephybun 50430ce
Merge branch 'main' into rk/list-resource-query-check
rainkwan 2858c75
Updated comment
rainkwan 9e1d041
Ran make generate
rainkwan 3da6e28
Fixed lintier
rainkwan 695a600
Fixed lintier
rainkwan 0bebb21
update terraform-json and terraform-exec dependencies and update quer…
stephybun e5bd162
remove redundant return statement and skip over nil messages
stephybun cca1521
fix query test
stephybun 79b2189
review comments
stephybun 460e176
update query test
stephybun e7db617
minor fixes
stephybun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package query_test | ||
|
|
||
| import ( | ||
| "github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
| "github.com/hashicorp/terraform-plugin-go/tftypes" | ||
| "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" | ||
| "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/list" | ||
| "github.com/hashicorp/terraform-plugin-testing/internal/teststep" | ||
| ) | ||
|
|
||
| func examplecloudListResource() testprovider.ListResource { | ||
| return testprovider.ListResource{ | ||
| IncludeResource: true, | ||
| SchemaResponse: &list.SchemaResponse{ | ||
| Schema: &tfprotov6.Schema{ | ||
| Block: &tfprotov6.SchemaBlock{ | ||
| Attributes: []*tfprotov6.SchemaAttribute{ | ||
| { | ||
| Name: "id", | ||
| Type: tftypes.String, | ||
| Computed: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ListResultsStream: &list.ListResultsStream{ | ||
| Results: func(push func(list.ListResult) bool) { | ||
| push(list.ListResult{ | ||
| Resource: teststep.Pointer(tftypes.NewValue( | ||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "id": tftypes.String, | ||
| "location": tftypes.String, | ||
| "name": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"), | ||
| "location": tftypes.NewValue(tftypes.String, "westeurope"), | ||
| "name": tftypes.NewValue(tftypes.String, "somevalue"), | ||
| }, | ||
| )), | ||
| Identity: teststep.Pointer(tftypes.NewValue( | ||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "id": tftypes.String, | ||
| "location": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue1"), | ||
| "location": tftypes.NewValue(tftypes.String, "westeurope"), | ||
| }, | ||
| )), | ||
| }) | ||
| push(list.ListResult{ | ||
| Identity: teststep.Pointer(tftypes.NewValue( | ||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "id": tftypes.String, | ||
| "location": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue2"), | ||
| "location": tftypes.NewValue(tftypes.String, "westeurope2"), | ||
| }, | ||
| )), | ||
| }) | ||
| push(list.ListResult{ | ||
| Identity: teststep.Pointer(tftypes.NewValue( | ||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "id": tftypes.String, | ||
| "location": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue3"), | ||
| "location": tftypes.NewValue(tftypes.String, "westeurope3"), | ||
| }, | ||
| )), | ||
| }) | ||
| }, | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package query | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| tfjson "github.com/hashicorp/terraform-json" | ||
| "github.com/mitchellh/go-testing-interface" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/querycheck" | ||
| ) | ||
|
|
||
| func RunQueryChecks(ctx context.Context, t testing.T, query []tfjson.LogMsg, queryChecks []querycheck.QueryResultCheck) error { | ||
| t.Helper() | ||
|
|
||
| var result []error | ||
|
|
||
| if query == nil { | ||
| result = append(result, fmt.Errorf("no query results found")) | ||
| } | ||
|
|
||
| found := make([]tfjson.ListResourceFoundData, 0) | ||
| summary := tfjson.ListCompleteData{} | ||
|
|
||
| for _, msg := range query { | ||
| switch v := msg.(type) { | ||
| case tfjson.ListResourceFoundMessage: | ||
| found = append(found, v.ListResourceFound) | ||
| case tfjson.ListCompleteMessage: | ||
| summary = v.ListComplete | ||
| // TODO diagnostics and errors? | ||
| default: | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| for _, queryCheck := range queryChecks { | ||
| resp := querycheck.CheckQueryResponse{} | ||
| queryCheck.CheckQuery(ctx, querycheck.CheckQueryRequest{ | ||
| Query: found, | ||
| QuerySummary: &summary, | ||
| }, &resp) | ||
|
|
||
| result = append(result, resp.Error) | ||
| } | ||
|
|
||
| return errors.Join(result...) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package query | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/querycheck" | ||
| ) | ||
|
|
||
| var _ querycheck.QueryResultCheck = &queryCheckSpy{} | ||
|
|
||
| type queryCheckSpy struct { | ||
| err error | ||
| called bool | ||
| } | ||
|
|
||
| func (s *queryCheckSpy) CheckQuery(ctx context.Context, req querycheck.CheckQueryRequest, resp *querycheck.CheckQueryResponse) { | ||
| s.called = true | ||
| resp.Error = s.err | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Doesn't look like this is used anywhere, perhaps it will eventually?