Skip to content
Open
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
108 changes: 108 additions & 0 deletions querycheck/expect_no_identity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package querycheck_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-go/tfprotov6"
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
"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/tfversion"
)

func TestExpectNoIdentity(t *testing.T) {
t.Parallel()

r.UnitTest(t, r.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(tfversion.Version1_14_0),
},
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
ListResources: map[string]testprovider.ListResource{
"examplecloud_containerette": examplecloudListResource(),
},
Resources: map[string]testprovider.Resource{
"examplecloud_containerette": examplecloudResource(),
},
}),
},
Steps: []r.TestStep{
{
Query: true,
Config: `
provider "examplecloud" {}

list "examplecloud_containerette" "test" {
provider = examplecloud

config {
resource_group_name = "foo"
}
}
`,
QueryResultChecks: []querycheck.QueryResultCheck{
querycheck.ExpectNoIdentity("examplecloud_containerette.test", map[string]knownvalue.Check{
"name": knownvalue.StringExact("owo"),
"resource_group_name": knownvalue.StringExact("uwu"),
}),
},
},
},
})
}

func TestExpectNoIdentity_Found(t *testing.T) {
t.Parallel()

r.UnitTest(t, r.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(tfversion.Version1_14_0),
},
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
ListResources: map[string]testprovider.ListResource{
"examplecloud_containerette": examplecloudListResource(),
},
Resources: map[string]testprovider.Resource{
"examplecloud_containerette": examplecloudResource(),
},
}),
},
Steps: []r.TestStep{
{
Query: true,
Config: `
provider "examplecloud" {}

list "examplecloud_containerette" "test" {
provider = examplecloud

config {
resource_group_name = "foo"
}
}

list "examplecloud_containerette" "test2" {
provider = examplecloud

config {
resource_group_name = "bar"
}
}
`,
QueryResultChecks: []querycheck.QueryResultCheck{
Copy link
Member

Choose a reason for hiding this comment

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

Should this test be expecting an error here?

querycheck.ExpectNoIdentity("examplecloud_containerette.test", map[string]knownvalue.Check{
"name": knownvalue.StringExact("banane"),
"resource_group_name": knownvalue.StringExact("foo"),
}),
},
},
},
})
}