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.
This commit is contained in:
Brian Flad 2022-04-22 06:46:40 -04:00 committed by GitHub
parent 3c30204856
commit 51deae2bc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View File

@ -9,6 +9,10 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types" "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{} type exampleDataSourceType struct{}
func (t exampleDataSourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { func (t exampleDataSourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {

View File

@ -10,6 +10,10 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog" "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{} type exampleResourceType struct{}
func (t exampleResourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { func (t exampleResourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {

View File

@ -9,6 +9,9 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types" "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 // provider satisfies the tfsdk.Provider interface and usually is included
// with all Resource and DataSource implementations. // with all Resource and DataSource implementations.
type provider struct { type provider struct {