Skip to content

Commit

Permalink
test: add initial resource schema test
Browse files Browse the repository at this point in the history
  • Loading branch information
dstrates committed Jun 28, 2024
1 parent 562a5eb commit bcd4556
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions internal/provider/resource_schema_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package provider

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccSchemaResource(t *testing.T) {
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read testing
{
Config: providerConfig + `
resource "schemaregistry_schema" "test" {
subject = "test-subject"
schema = "{\"type\":\"record\",\"name\":\"Test\",\"fields\":[{\"name\":\"f1\",\"type\":\"string\"}]}"
schema_type = "avro"
compatibility_level = "FULL"
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
// Verify schema attributes
resource.TestCheckResourceAttr("schemaregistry_schema.test", "subject", "test-subject"),
resource.TestCheckResourceAttr("schemaregistry_schema.test", "schema", "{\"type\":\"record\",\"name\":\"Test\",\"fields\":[{\"name\":\"f1\",\"type\":\"string\"}]}"),
resource.TestCheckResourceAttr("schemaregistry_schema.test", "schema_type", "json"),
resource.TestCheckResourceAttr("schemaregistry_schema.test", "compatibility_level", "FULL"),
resource.TestCheckResourceAttrSet("schemaregistry_schema.test", "schema_id"),
resource.TestCheckResourceAttrSet("schemaregistry_schema.test", "version"),
),
},
// ImportState testing
{
ResourceName: "schemaregistry_schema.test",
ImportState: true,
ImportStateVerify: true,
// No attributes to ignore during import
ImportStateVerifyIgnore: []string{},
},
// Update and Read testing
{
Config: providerConfig + `
resource "schemaregistry_schema" "test" {
subject = "test-subject"
schema = "{\"type\":\"record\",\"name\":\"Test\",\"fields\":[{\"name\":\"f1\",\"type\":\"string\"},{\"name\":\"f2\",\"type\":\"int\"}]}"
schema_type = "avro"
compatibility_level = "BACKWARD"
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
// Verify updated schema attributes
resource.TestCheckResourceAttr("schemaregistry_schema.test", "subject", "test-subject"),
resource.TestCheckResourceAttr("schemaregistry_schema.test", "schema", "{\"type\":\"record\",\"name\":\"Test\",\"fields\":[{\"name\":\"f1\",\"type\":\"string\"},{\"name\":\"f2\",\"type\":\"int\"}]}"),
resource.TestCheckResourceAttr("schemaregistry_schema.test", "schema_type", "avro"),
resource.TestCheckResourceAttr("schemaregistry_schema.test", "compatibility_level", "BACKWARD"),
resource.TestCheckResourceAttrSet("schemaregistry_schema.test", "schema_id"),
resource.TestCheckResourceAttrSet("schemaregistry_schema.test", "version"),
),
},
// Delete testing automatically occurs in TestCase
},
})
}

0 comments on commit bcd4556

Please sign in to comment.