瀏覽代碼

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 年之前
父節點
當前提交
51deae2bc7
共有 3 個文件被更改,包括 11 次插入0 次删除
  1. 4 0
      internal/provider/example_data_source.go
  2. 4 0
      internal/provider/example_resource.go
  3. 3 0
      internal/provider/provider.go

+ 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 {