-
Notifications
You must be signed in to change notification settings - Fork 91
/
datasourcetype.go
35 lines (27 loc) · 1 KB
/
datasourcetype.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package testprovider
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)
var _ tfsdk.DataSourceType = &DataSourceType{}
// Declarative tfsdk.DataSourceType for unit testing.
type DataSourceType struct {
// DataSourceType interface methods
GetSchemaMethod func(context.Context) (tfsdk.Schema, diag.Diagnostics)
NewDataSourceMethod func(context.Context, tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics)
}
// GetSchema satisfies the tfsdk.DataSourceType interface.
func (t *DataSourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {
if t.GetSchemaMethod == nil {
return tfsdk.Schema{}, nil
}
return t.GetSchemaMethod(ctx)
}
// NewDataSource satisfies the tfsdk.DataSourceType interface.
func (t *DataSourceType) NewDataSource(ctx context.Context, p tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) {
if t.NewDataSourceMethod == nil {
return nil, nil
}
return t.NewDataSourceMethod(ctx, p)
}