From f9752dc752c98362113344f6d7a3e9dc32981a15 Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 2 Dec 2025 09:06:44 +0100 Subject: [PATCH 1/8] update expect known value query check to use query filter --- querycheck/expect_known_value.go | 28 +++++++++++++++++++-------- querycheck/expect_known_value_test.go | 19 +++++++++++------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/querycheck/expect_known_value.go b/querycheck/expect_known_value.go index faa046eb..63c5331b 100644 --- a/querycheck/expect_known_value.go +++ b/querycheck/expect_known_value.go @@ -6,6 +6,7 @@ package querycheck import ( "context" "fmt" + "github.com/hashicorp/terraform-plugin-testing/querycheck/queryfilter" "strings" "github.com/hashicorp/terraform-plugin-testing/knownvalue" @@ -13,19 +14,30 @@ import ( ) var _ QueryResultCheck = expectKnownValue{} +var _ QueryResultCheckWithFilters = expectKnownValue{} type expectKnownValue struct { listResourceAddress string - resourceName string + filter queryfilter.QueryFilter attributePath tfjsonpath.Path knownValue knownvalue.Check } +func (e expectKnownValue) QueryFilters(ctx context.Context) []queryfilter.QueryFilter { + if e.filter == nil { + return []queryfilter.QueryFilter{} + } + + return []queryfilter.QueryFilter{ + e.filter, + } +} + func (e expectKnownValue) CheckQuery(_ context.Context, req CheckQueryRequest, resp *CheckQueryResponse) { for _, res := range req.Query { var diags []error - if e.listResourceAddress == strings.TrimPrefix(res.Address, "list.") && e.resourceName == res.DisplayName { + if e.listResourceAddress == strings.TrimPrefix(res.Address, "list.") { if res.ResourceObject == nil { resp.Error = fmt.Errorf("%s - no resource object was returned, ensure `include_resource` has been set to `true` in the list resource config`", e.listResourceAddress) return @@ -38,7 +50,7 @@ func (e expectKnownValue) CheckQuery(_ context.Context, req CheckQueryRequest, r } if err := e.knownValue.CheckValue(resource); err != nil { - diags = append(diags, fmt.Errorf("error checking value for attribute at path: %s for resource %s, err: %s", e.attributePath.String(), e.resourceName, err)) + diags = append(diags, fmt.Errorf("error checking value for attribute at path: %s for resource with identity %s, err: %s", e.attributePath.String(), e.filter, err)) } if diags == nil { @@ -56,18 +68,18 @@ func (e expectKnownValue) CheckQuery(_ context.Context, req CheckQueryRequest, r } } - resp.Error = fmt.Errorf("%s - the resource %s was not found", e.listResourceAddress, e.resourceName) + resp.Error = fmt.Errorf("%s - the resource %s was not found", e.listResourceAddress, e.filter) } // ExpectKnownValue returns a query check that asserts the specified attribute values are present for a given resource object -// returned by a list query. The resource object can only be identified by providing the list resource address as well as the -// resource name (display name). +// returned by a list query. The resource object can only be identified by providing the list resource address as well as +// a query filter. // // This query check can only be used with managed resources that support resource identity and query. Query is only supported in Terraform v1.14+ -func ExpectKnownValue(listResourceAddress string, resourceName string, attributePath tfjsonpath.Path, knownValue knownvalue.Check) QueryResultCheck { +func ExpectKnownValue(listResourceAddress string, filter queryfilter.QueryFilter, attributePath tfjsonpath.Path, knownValue knownvalue.Check) QueryResultCheck { return expectKnownValue{ listResourceAddress: listResourceAddress, - resourceName: resourceName, + filter: filter, attributePath: attributePath, knownValue: knownValue, } diff --git a/querycheck/expect_known_value_test.go b/querycheck/expect_known_value_test.go index a12ab688..ba6627d6 100644 --- a/querycheck/expect_known_value_test.go +++ b/querycheck/expect_known_value_test.go @@ -4,6 +4,7 @@ package querycheck_test import ( + "github.com/hashicorp/terraform-plugin-testing/querycheck/queryfilter" "math/big" "regexp" "testing" @@ -41,7 +42,7 @@ func TestExpectKnownValue(t *testing.T) { // for simplicity we're only "provisioning" one here Config: ` resource "examplecloud_containerette" "primary" { - name = "banana" + name = "banane" resource_group_name = "foo" location = "westeurope" @@ -68,8 +69,10 @@ func TestExpectKnownValue(t *testing.T) { `, QueryResultChecks: []querycheck.QueryResultCheck{ querycheck.ExpectKnownValue( - "examplecloud_containerette.test", - "banane", + "examplecloud_containerette.test", queryfilter.ByResourceIdentity(map[string]knownvalue.Check{ + "name": knownvalue.StringExact("banane"), + "resource_group_name": knownvalue.StringExact("foo"), + }), tfjsonpath.New("instances"), knownvalue.NumberExact(big.NewFloat(5)), ), @@ -102,7 +105,7 @@ func TestExpectKnownValue_ValueIncorrect(t *testing.T) { // for simplicity we're only "provisioning" one here Config: ` resource "examplecloud_containerette" "primary" { - name = "banana" + name = "banane" resource_group_name = "foo" location = "westeurope" @@ -129,13 +132,15 @@ func TestExpectKnownValue_ValueIncorrect(t *testing.T) { `, QueryResultChecks: []querycheck.QueryResultCheck{ querycheck.ExpectKnownValue( - "examplecloud_containerette.test", - "banane", + "examplecloud_containerette.test", queryfilter.ByResourceIdentity(map[string]knownvalue.Check{ + "name": knownvalue.StringExact("banane"), + "resource_group_name": knownvalue.StringExact("foo"), + }), tfjsonpath.New("instances"), knownvalue.NumberExact(big.NewFloat(4)), ), }, - ExpectError: regexp.MustCompile("the following errors were found while checking values: error checking value for attribute at path: instances for resource banane, err: expected value 4 for NumberExact check, got: 5;"), + ExpectError: regexp.MustCompile("the following errors were found while checking values: error checking value for attribute at path: instances for resource with identity .*, err: expected value 4 for NumberExact check, got: 5;"), }, }, }) From 3019f493c1c3069f30b135f625a09859e1e3611e Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 2 Dec 2025 09:07:30 +0100 Subject: [PATCH 2/8] import order --- querycheck/expect_known_value.go | 2 +- querycheck/expect_known_value_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/querycheck/expect_known_value.go b/querycheck/expect_known_value.go index 63c5331b..17f047a4 100644 --- a/querycheck/expect_known_value.go +++ b/querycheck/expect_known_value.go @@ -6,10 +6,10 @@ package querycheck import ( "context" "fmt" - "github.com/hashicorp/terraform-plugin-testing/querycheck/queryfilter" "strings" "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/querycheck/queryfilter" "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" ) diff --git a/querycheck/expect_known_value_test.go b/querycheck/expect_known_value_test.go index ba6627d6..715e82f2 100644 --- a/querycheck/expect_known_value_test.go +++ b/querycheck/expect_known_value_test.go @@ -4,7 +4,6 @@ package querycheck_test import ( - "github.com/hashicorp/terraform-plugin-testing/querycheck/queryfilter" "math/big" "regexp" "testing" @@ -15,6 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" "github.com/hashicorp/terraform-plugin-testing/knownvalue" "github.com/hashicorp/terraform-plugin-testing/querycheck" + "github.com/hashicorp/terraform-plugin-testing/querycheck/queryfilter" "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) From 01185b6da3543a5edbd96013bd712d5a0e2d3ad0 Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 2 Dec 2025 09:26:06 +0100 Subject: [PATCH 3/8] update expect known value check to accept multiple known value checks --- querycheck/expect_known_value.go | 31 +++++++++++++-------------- querycheck/expect_known_value_test.go | 26 +++++++++++++++------- querycheck/known_value.go | 11 ++++++++++ 3 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 querycheck/known_value.go diff --git a/querycheck/expect_known_value.go b/querycheck/expect_known_value.go index 17f047a4..ba77a31f 100644 --- a/querycheck/expect_known_value.go +++ b/querycheck/expect_known_value.go @@ -8,7 +8,6 @@ import ( "fmt" "strings" - "github.com/hashicorp/terraform-plugin-testing/knownvalue" "github.com/hashicorp/terraform-plugin-testing/querycheck/queryfilter" "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" ) @@ -19,8 +18,7 @@ var _ QueryResultCheckWithFilters = expectKnownValue{} type expectKnownValue struct { listResourceAddress string filter queryfilter.QueryFilter - attributePath tfjsonpath.Path - knownValue knownvalue.Check + knownValues []KnownValueCheck } func (e expectKnownValue) QueryFilters(ctx context.Context) []queryfilter.QueryFilter { @@ -43,18 +41,20 @@ func (e expectKnownValue) CheckQuery(_ context.Context, req CheckQueryRequest, r return } - resource, err := tfjsonpath.Traverse(res.ResourceObject, e.attributePath) - if err != nil { - resp.Error = err - return - } + for _, c := range e.knownValues { + resource, err := tfjsonpath.Traverse(res.ResourceObject, c.Path) + if err != nil { + resp.Error = err + return + } - if err := e.knownValue.CheckValue(resource); err != nil { - diags = append(diags, fmt.Errorf("error checking value for attribute at path: %s for resource with identity %s, err: %s", e.attributePath.String(), e.filter, err)) - } + if err := c.KnownValue.CheckValue(resource); err != nil { + diags = append(diags, fmt.Errorf("error checking value for attribute at path: %s for resource with identity %s, err: %s", c.Path.String(), e.filter, err)) + } - if diags == nil { - return + if diags == nil { + return + } } } @@ -76,11 +76,10 @@ func (e expectKnownValue) CheckQuery(_ context.Context, req CheckQueryRequest, r // a query filter. // // This query check can only be used with managed resources that support resource identity and query. Query is only supported in Terraform v1.14+ -func ExpectKnownValue(listResourceAddress string, filter queryfilter.QueryFilter, attributePath tfjsonpath.Path, knownValue knownvalue.Check) QueryResultCheck { +func ExpectKnownValue(listResourceAddress string, filter queryfilter.QueryFilter, knownValues []KnownValueCheck) QueryResultCheck { return expectKnownValue{ listResourceAddress: listResourceAddress, filter: filter, - attributePath: attributePath, - knownValue: knownValue, + knownValues: knownValues, } } diff --git a/querycheck/expect_known_value_test.go b/querycheck/expect_known_value_test.go index 715e82f2..cf4d6ce2 100644 --- a/querycheck/expect_known_value_test.go +++ b/querycheck/expect_known_value_test.go @@ -42,7 +42,7 @@ func TestExpectKnownValue(t *testing.T) { // for simplicity we're only "provisioning" one here Config: ` resource "examplecloud_containerette" "primary" { - name = "banane" + name = "banana" resource_group_name = "foo" location = "westeurope" @@ -72,9 +72,16 @@ func TestExpectKnownValue(t *testing.T) { "examplecloud_containerette.test", queryfilter.ByResourceIdentity(map[string]knownvalue.Check{ "name": knownvalue.StringExact("banane"), "resource_group_name": knownvalue.StringExact("foo"), - }), - tfjsonpath.New("instances"), - knownvalue.NumberExact(big.NewFloat(5)), + }), []querycheck.KnownValueCheck{ + { + tfjsonpath.New("instances"), + knownvalue.NumberExact(big.NewFloat(5)), + }, + { + tfjsonpath.New("location"), + knownvalue.StringExact("westeurope"), + }, + }, ), }, }, @@ -105,7 +112,7 @@ func TestExpectKnownValue_ValueIncorrect(t *testing.T) { // for simplicity we're only "provisioning" one here Config: ` resource "examplecloud_containerette" "primary" { - name = "banane" + name = "banana" resource_group_name = "foo" location = "westeurope" @@ -135,9 +142,12 @@ func TestExpectKnownValue_ValueIncorrect(t *testing.T) { "examplecloud_containerette.test", queryfilter.ByResourceIdentity(map[string]knownvalue.Check{ "name": knownvalue.StringExact("banane"), "resource_group_name": knownvalue.StringExact("foo"), - }), - tfjsonpath.New("instances"), - knownvalue.NumberExact(big.NewFloat(4)), + }), []querycheck.KnownValueCheck{ + { + tfjsonpath.New("instances"), + knownvalue.NumberExact(big.NewFloat(4)), + }, + }, ), }, ExpectError: regexp.MustCompile("the following errors were found while checking values: error checking value for attribute at path: instances for resource with identity .*, err: expected value 4 for NumberExact check, got: 5;"), diff --git a/querycheck/known_value.go b/querycheck/known_value.go new file mode 100644 index 00000000..d76e896f --- /dev/null +++ b/querycheck/known_value.go @@ -0,0 +1,11 @@ +package querycheck + +import ( + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" +) + +type KnownValueCheck struct { + Path tfjsonpath.Path + KnownValue knownvalue.Check +} From d74b8def28294d94e538e2130ca6b154b6a899b5 Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 2 Dec 2025 09:29:39 +0100 Subject: [PATCH 4/8] update name of querycheck to ExpectResourceKnownValues --- ..._value.go => expect_resource_known_values.go} | 16 ++++++++-------- ...t.go => expect_resource_known_values_test.go} | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) rename querycheck/{expect_known_value.go => expect_resource_known_values.go} (74%) rename querycheck/{expect_known_value_test.go => expect_resource_known_values_test.go} (96%) diff --git a/querycheck/expect_known_value.go b/querycheck/expect_resource_known_values.go similarity index 74% rename from querycheck/expect_known_value.go rename to querycheck/expect_resource_known_values.go index ba77a31f..dbdef219 100644 --- a/querycheck/expect_known_value.go +++ b/querycheck/expect_resource_known_values.go @@ -12,16 +12,16 @@ import ( "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" ) -var _ QueryResultCheck = expectKnownValue{} -var _ QueryResultCheckWithFilters = expectKnownValue{} +var _ QueryResultCheck = expectResourceKnownValues{} +var _ QueryResultCheckWithFilters = expectResourceKnownValues{} -type expectKnownValue struct { +type expectResourceKnownValues struct { listResourceAddress string filter queryfilter.QueryFilter knownValues []KnownValueCheck } -func (e expectKnownValue) QueryFilters(ctx context.Context) []queryfilter.QueryFilter { +func (e expectResourceKnownValues) QueryFilters(ctx context.Context) []queryfilter.QueryFilter { if e.filter == nil { return []queryfilter.QueryFilter{} } @@ -31,7 +31,7 @@ func (e expectKnownValue) QueryFilters(ctx context.Context) []queryfilter.QueryF } } -func (e expectKnownValue) CheckQuery(_ context.Context, req CheckQueryRequest, resp *CheckQueryResponse) { +func (e expectResourceKnownValues) CheckQuery(_ context.Context, req CheckQueryRequest, resp *CheckQueryResponse) { for _, res := range req.Query { var diags []error @@ -71,13 +71,13 @@ func (e expectKnownValue) CheckQuery(_ context.Context, req CheckQueryRequest, r resp.Error = fmt.Errorf("%s - the resource %s was not found", e.listResourceAddress, e.filter) } -// ExpectKnownValue returns a query check that asserts the specified attribute values are present for a given resource object +// ExpectResourceKnownValues returns a query check that asserts the specified attribute values are present for a given resource object // returned by a list query. The resource object can only be identified by providing the list resource address as well as // a query filter. // // This query check can only be used with managed resources that support resource identity and query. Query is only supported in Terraform v1.14+ -func ExpectKnownValue(listResourceAddress string, filter queryfilter.QueryFilter, knownValues []KnownValueCheck) QueryResultCheck { - return expectKnownValue{ +func ExpectResourceKnownValues(listResourceAddress string, filter queryfilter.QueryFilter, knownValues []KnownValueCheck) QueryResultCheck { + return expectResourceKnownValues{ listResourceAddress: listResourceAddress, filter: filter, knownValues: knownValues, diff --git a/querycheck/expect_known_value_test.go b/querycheck/expect_resource_known_values_test.go similarity index 96% rename from querycheck/expect_known_value_test.go rename to querycheck/expect_resource_known_values_test.go index cf4d6ce2..5c4c376d 100644 --- a/querycheck/expect_known_value_test.go +++ b/querycheck/expect_resource_known_values_test.go @@ -19,7 +19,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/tfversion" ) -func TestExpectKnownValue(t *testing.T) { +func TestExpectResourceKnownValues(t *testing.T) { t.Parallel() r.UnitTest(t, r.TestCase{ @@ -68,7 +68,7 @@ func TestExpectKnownValue(t *testing.T) { } `, QueryResultChecks: []querycheck.QueryResultCheck{ - querycheck.ExpectKnownValue( + querycheck.ExpectResourceKnownValues( "examplecloud_containerette.test", queryfilter.ByResourceIdentity(map[string]knownvalue.Check{ "name": knownvalue.StringExact("banane"), "resource_group_name": knownvalue.StringExact("foo"), @@ -89,7 +89,7 @@ func TestExpectKnownValue(t *testing.T) { }) } -func TestExpectKnownValue_ValueIncorrect(t *testing.T) { +func TestExpectResourceKnownValues_ValueIncorrect(t *testing.T) { t.Parallel() r.UnitTest(t, r.TestCase{ @@ -138,7 +138,7 @@ func TestExpectKnownValue_ValueIncorrect(t *testing.T) { } `, QueryResultChecks: []querycheck.QueryResultCheck{ - querycheck.ExpectKnownValue( + querycheck.ExpectResourceKnownValues( "examplecloud_containerette.test", queryfilter.ByResourceIdentity(map[string]knownvalue.Check{ "name": knownvalue.StringExact("banane"), "resource_group_name": knownvalue.StringExact("foo"), From 310a80203c14900adde14f6b72c912eb049b6607 Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 2 Dec 2025 09:39:16 +0100 Subject: [PATCH 5/8] copyright headers --- querycheck/known_value.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/querycheck/known_value.go b/querycheck/known_value.go index d76e896f..002eb4c5 100644 --- a/querycheck/known_value.go +++ b/querycheck/known_value.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package querycheck import ( From 377b8e63aa54335f6fce18b316478e2f4506f3d6 Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 2 Dec 2025 11:34:36 +0100 Subject: [PATCH 6/8] changelog --- .changes/unreleased/FEATURES-20251202-113347.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/unreleased/FEATURES-20251202-113347.yaml diff --git a/.changes/unreleased/FEATURES-20251202-113347.yaml b/.changes/unreleased/FEATURES-20251202-113347.yaml new file mode 100644 index 00000000..675925a5 --- /dev/null +++ b/.changes/unreleased/FEATURES-20251202-113347.yaml @@ -0,0 +1,5 @@ +kind: FEATURES +body: 'querycheck: Adds `ExpectResourceKnownValues` query check to assert resource values on a filtered query result.' +time: 2025-12-02T11:33:47.606282+01:00 +custom: + Issue: "583" From b2d2040f78d8a29c68b11636f86cf2e9d2b3d24a Mon Sep 17 00:00:00 2001 From: Steph Date: Wed, 3 Dec 2025 08:49:45 +0100 Subject: [PATCH 7/8] resolve review comments --- querycheck/expect_resource_known_values.go | 77 +++++++++++-------- .../expect_resource_known_values_test.go | 4 + querycheck/known_value.go | 7 +- 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/querycheck/expect_resource_known_values.go b/querycheck/expect_resource_known_values.go index dbdef219..46e20d10 100644 --- a/querycheck/expect_resource_known_values.go +++ b/querycheck/expect_resource_known_values.go @@ -6,6 +6,7 @@ package querycheck import ( "context" "fmt" + tfjson "github.com/hashicorp/terraform-json" "strings" "github.com/hashicorp/terraform-plugin-testing/querycheck/queryfilter" @@ -18,7 +19,7 @@ var _ QueryResultCheckWithFilters = expectResourceKnownValues{} type expectResourceKnownValues struct { listResourceAddress string filter queryfilter.QueryFilter - knownValues []KnownValueCheck + knownValueChecks []KnownValueCheck } func (e expectResourceKnownValues) QueryFilters(ctx context.Context) []queryfilter.QueryFilter { @@ -32,54 +33,62 @@ func (e expectResourceKnownValues) QueryFilters(ctx context.Context) []queryfilt } func (e expectResourceKnownValues) CheckQuery(_ context.Context, req CheckQueryRequest, resp *CheckQueryResponse) { + listRes := make([]tfjson.ListResourceFoundData, 0) + var diags []error for _, res := range req.Query { - var diags []error - if e.listResourceAddress == strings.TrimPrefix(res.Address, "list.") { - if res.ResourceObject == nil { - resp.Error = fmt.Errorf("%s - no resource object was returned, ensure `include_resource` has been set to `true` in the list resource config`", e.listResourceAddress) - return - } - - for _, c := range e.knownValues { - resource, err := tfjsonpath.Traverse(res.ResourceObject, c.Path) - if err != nil { - resp.Error = err - return - } - - if err := c.KnownValue.CheckValue(resource); err != nil { - diags = append(diags, fmt.Errorf("error checking value for attribute at path: %s for resource with identity %s, err: %s", c.Path.String(), e.filter, err)) - } - - if diags == nil { - return - } - } + listRes = append(listRes, res) } + } + + if len(listRes) == 0 { + resp.Error = fmt.Errorf("%s - no query results found after filtering", e.listResourceAddress) + return + } + + if len(listRes) > 1 { + resp.Error = fmt.Errorf("%s - more than 1 query result found after filtering", e.listResourceAddress) + return + } + + res := listRes[0] - if diags != nil { - var diagsStr string - for _, diag := range diags { - diagsStr += diag.Error() + "; " - } - resp.Error = fmt.Errorf("the following errors were found while checking values: %s", diagsStr) + if res.ResourceObject == nil { + resp.Error = fmt.Errorf("%s - no resource object was returned, ensure `include_resource` has been set to `true` in the list resource config`", e.listResourceAddress) + return + } + + for _, c := range e.knownValueChecks { + resource, err := tfjsonpath.Traverse(res.ResourceObject, c.Path) + if err != nil { + resp.Error = err return } + + if err := c.KnownValue.CheckValue(resource); err != nil { + diags = append(diags, fmt.Errorf("error checking value for attribute at path: %s for resource with identity %s, err: %s", c.Path.String(), e.filter, err)) + } } - resp.Error = fmt.Errorf("%s - the resource %s was not found", e.listResourceAddress, e.filter) + if diags != nil { + var diagsStr string + for _, diag := range diags { + diagsStr += diag.Error() + "; " + } + resp.Error = fmt.Errorf("the following errors were found while checking values: %s", diagsStr) + return + } } -// ExpectResourceKnownValues returns a query check that asserts the specified attribute values are present for a given resource object -// returned by a list query. The resource object can only be identified by providing the list resource address as well as -// a query filter. +// it's asserting that the resource object (identified by the filter) passes the given query checks". +// ExpectResourceKnownValues returns a query check which asserts that a resource object identified by a query filter +// passes the given query checks. // // This query check can only be used with managed resources that support resource identity and query. Query is only supported in Terraform v1.14+ func ExpectResourceKnownValues(listResourceAddress string, filter queryfilter.QueryFilter, knownValues []KnownValueCheck) QueryResultCheck { return expectResourceKnownValues{ listResourceAddress: listResourceAddress, filter: filter, - knownValues: knownValues, + knownValueChecks: knownValues, } } diff --git a/querycheck/expect_resource_known_values_test.go b/querycheck/expect_resource_known_values_test.go index 5c4c376d..b780ef16 100644 --- a/querycheck/expect_resource_known_values_test.go +++ b/querycheck/expect_resource_known_values_test.go @@ -143,6 +143,10 @@ func TestExpectResourceKnownValues_ValueIncorrect(t *testing.T) { "name": knownvalue.StringExact("banane"), "resource_group_name": knownvalue.StringExact("foo"), }), []querycheck.KnownValueCheck{ + { + tfjsonpath.New("location"), + knownvalue.StringExact("westeurope"), + }, { tfjsonpath.New("instances"), knownvalue.NumberExact(big.NewFloat(4)), diff --git a/querycheck/known_value.go b/querycheck/known_value.go index 002eb4c5..67179ec2 100644 --- a/querycheck/known_value.go +++ b/querycheck/known_value.go @@ -8,7 +8,12 @@ import ( "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" ) +// KnownValueCheck represents a check of a known value at a specific JSON path +// and is used to specify multiple known value checks to assert against a +// single resource object returned by a query. type KnownValueCheck struct { - Path tfjsonpath.Path + // Path specifies the JSON path to check within the resource object. + Path tfjsonpath.Path + // KnownValue specifies the expected known value check to perform at the given path. KnownValue knownvalue.Check } From 577c7216185016979b33740bf17fd5c18a8154c2 Mon Sep 17 00:00:00 2001 From: Steph Date: Wed, 3 Dec 2025 10:12:56 +0100 Subject: [PATCH 8/8] remove unnecessary comment --- querycheck/expect_resource_known_values.go | 1 - 1 file changed, 1 deletion(-) diff --git a/querycheck/expect_resource_known_values.go b/querycheck/expect_resource_known_values.go index 46e20d10..8185d8f0 100644 --- a/querycheck/expect_resource_known_values.go +++ b/querycheck/expect_resource_known_values.go @@ -80,7 +80,6 @@ func (e expectResourceKnownValues) CheckQuery(_ context.Context, req CheckQueryR } } -// it's asserting that the resource object (identified by the filter) passes the given query checks". // ExpectResourceKnownValues returns a query check which asserts that a resource object identified by a query filter // passes the given query checks. //