|
| 1 | +package querycheck_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-go/tfprotov6" |
| 7 | + r "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 8 | + "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" |
| 9 | + "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" |
| 10 | + "github.com/hashicorp/terraform-plugin-testing/knownvalue" |
| 11 | + "github.com/hashicorp/terraform-plugin-testing/querycheck" |
| 12 | + "github.com/hashicorp/terraform-plugin-testing/tfversion" |
| 13 | +) |
| 14 | + |
| 15 | +func TestExpectNoIdentity(t *testing.T) { |
| 16 | + t.Parallel() |
| 17 | + |
| 18 | + r.UnitTest(t, r.TestCase{ |
| 19 | + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ |
| 20 | + tfversion.SkipBelow(tfversion.Version1_14_0), |
| 21 | + }, |
| 22 | + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ |
| 23 | + "examplecloud": providerserver.NewProviderServer(testprovider.Provider{ |
| 24 | + ListResources: map[string]testprovider.ListResource{ |
| 25 | + "examplecloud_containerette": examplecloudListResource(), |
| 26 | + }, |
| 27 | + Resources: map[string]testprovider.Resource{ |
| 28 | + "examplecloud_containerette": examplecloudResource(), |
| 29 | + }, |
| 30 | + }), |
| 31 | + }, |
| 32 | + Steps: []r.TestStep{ |
| 33 | + { |
| 34 | + Query: true, |
| 35 | + Config: ` |
| 36 | + provider "examplecloud" {} |
| 37 | +
|
| 38 | + list "examplecloud_containerette" "test" { |
| 39 | + provider = examplecloud |
| 40 | +
|
| 41 | + config { |
| 42 | + resource_group_name = "foo" |
| 43 | + } |
| 44 | + } |
| 45 | + `, |
| 46 | + QueryResultChecks: []querycheck.QueryResultCheck{ |
| 47 | + querycheck.ExpectNoIdentity("examplecloud_containerette.test", map[string]knownvalue.Check{ |
| 48 | + "name": knownvalue.StringExact("owo"), |
| 49 | + "resource_group_name": knownvalue.StringExact("uwu"), |
| 50 | + }), |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }) |
| 55 | +} |
| 56 | + |
| 57 | +func TestExpectNoIdentity_Found(t *testing.T) { |
| 58 | + t.Parallel() |
| 59 | + |
| 60 | + r.UnitTest(t, r.TestCase{ |
| 61 | + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ |
| 62 | + tfversion.SkipBelow(tfversion.Version1_14_0), |
| 63 | + }, |
| 64 | + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ |
| 65 | + "examplecloud": providerserver.NewProviderServer(testprovider.Provider{ |
| 66 | + ListResources: map[string]testprovider.ListResource{ |
| 67 | + "examplecloud_containerette": examplecloudListResource(), |
| 68 | + }, |
| 69 | + Resources: map[string]testprovider.Resource{ |
| 70 | + "examplecloud_containerette": examplecloudResource(), |
| 71 | + }, |
| 72 | + }), |
| 73 | + }, |
| 74 | + Steps: []r.TestStep{ |
| 75 | + { |
| 76 | + Query: true, |
| 77 | + Config: ` |
| 78 | + provider "examplecloud" {} |
| 79 | +
|
| 80 | + list "examplecloud_containerette" "test" { |
| 81 | + provider = examplecloud |
| 82 | +
|
| 83 | + config { |
| 84 | + resource_group_name = "foo" |
| 85 | + } |
| 86 | + } |
| 87 | +
|
| 88 | + list "examplecloud_containerette" "test2" { |
| 89 | + provider = examplecloud |
| 90 | +
|
| 91 | + config { |
| 92 | + resource_group_name = "bar" |
| 93 | + } |
| 94 | + } |
| 95 | + `, |
| 96 | + QueryResultChecks: []querycheck.QueryResultCheck{ |
| 97 | + querycheck.ExpectNoIdentity("examplecloud_containerette.test", map[string]knownvalue.Check{ |
| 98 | + "name": knownvalue.StringExact("banane"), |
| 99 | + "resource_group_name": knownvalue.StringExact("foo"), |
| 100 | + }), |
| 101 | + }, |
| 102 | + }, |
| 103 | + }, |
| 104 | + }) |
| 105 | +} |
0 commit comments