Pārlūkot izejas kodu

internal/provider: Add compilation based interface assertions (#38)

This is a quick method for compilation errors to be raised should the types not satisfy the expected framework interfaces.
Brian Flad 3 gadi atpakaļ
vecāks
revīzija
51deae2bc7

+ 4 - 0
internal/provider/example_data_source.go

@@ -9,6 +9,10 @@ import (
 	"github.com/hashicorp/terraform-plugin-framework/types"
 )
 
+// Ensure provider defined types fully satisfy framework interfaces
+var _ tfsdk.DataSourceType = exampleDataSourceType{}
+var _ tfsdk.DataSource = exampleDataSource{}
+
 type exampleDataSourceType struct{}
 
 func (t exampleDataSourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {

+ 4 - 0
internal/provider/example_resource.go

@@ -10,6 +10,10 @@ import (
 	"github.com/hashicorp/terraform-plugin-log/tflog"
 )
 
+// Ensure provider defined types fully satisfy framework interfaces
+var _ tfsdk.ResourceType = exampleResourceType{}
+var _ tfsdk.Resource = exampleResource{}
+
 type exampleResourceType struct{}
 
 func (t exampleResourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {

+ 3 - 0
internal/provider/provider.go

@@ -9,6 +9,9 @@ import (
 	"github.com/hashicorp/terraform-plugin-framework/types"
 )
 
+// Ensure provider defined types fully satisfy framework interfaces
+var _ tfsdk.Provider = &provider{}
+
 // provider satisfies the tfsdk.Provider interface and usually is included
 // with all Resource and DataSource implementations.
 type provider struct {