-
Notifications
You must be signed in to change notification settings - Fork 90
/
serve_resource_config_validators_test.go
103 lines (88 loc) · 3.35 KB
/
serve_resource_config_validators_test.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package tfsdk
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
type testServeResourceTypeConfigValidators struct{}
func (dt testServeResourceTypeConfigValidators) GetSchema(_ context.Context) (Schema, diag.Diagnostics) {
return Schema{
Attributes: map[string]Attribute{
"string": {
Type: types.StringType,
Optional: true,
},
},
}, nil
}
func (dt testServeResourceTypeConfigValidators) NewResource(_ context.Context, p Provider) (Resource, diag.Diagnostics) {
provider, ok := p.(*testServeProvider)
if !ok {
prov, ok := p.(*testServeProviderWithMetaSchema)
if !ok {
panic(fmt.Sprintf("unexpected provider type %T", p))
}
provider = prov.testServeProvider
}
return testServeResourceConfigValidators{
provider: provider,
}, nil
}
var testServeResourceTypeConfigValidatorsSchema = &tfprotov6.Schema{
Block: &tfprotov6.SchemaBlock{
Attributes: []*tfprotov6.SchemaAttribute{
{
Name: "string",
Optional: true,
Type: tftypes.String,
},
},
},
}
var testServeResourceTypeConfigValidatorsType = tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string": tftypes.String,
},
}
type testServeResourceConfigValidators struct {
provider *testServeProvider
}
func (r testServeResourceConfigValidators) Create(ctx context.Context, req CreateResourceRequest, resp *CreateResourceResponse) {
// Intentionally blank. Not expected to be called during testing.
}
func (r testServeResourceConfigValidators) Read(ctx context.Context, req ReadResourceRequest, resp *ReadResourceResponse) {
// Intentionally blank. Not expected to be called during testing.
}
func (r testServeResourceConfigValidators) Update(ctx context.Context, req UpdateResourceRequest, resp *UpdateResourceResponse) {
// Intentionally blank. Not expected to be called during testing.
}
func (r testServeResourceConfigValidators) Delete(ctx context.Context, req DeleteResourceRequest, resp *DeleteResourceResponse) {
// Intentionally blank. Not expected to be called during testing.
}
func (r testServeResourceConfigValidators) ConfigValidators(ctx context.Context) []ResourceConfigValidator {
r.provider.validateResourceConfigCalledResourceType = "test_config_validators"
return []ResourceConfigValidator{
newTestResourceConfigValidator(r.provider.validateResourceConfigImpl),
// Verify multiple validators
newTestResourceConfigValidator(r.provider.validateResourceConfigImpl),
}
}
type testResourceConfigValidator struct {
ResourceConfigValidator
impl func(context.Context, ValidateResourceConfigRequest, *ValidateResourceConfigResponse)
}
func (v testResourceConfigValidator) Description(ctx context.Context) string {
return "test resource config validator"
}
func (v testResourceConfigValidator) MarkdownDescription(ctx context.Context) string {
return "**test** resource config validator"
}
func (v testResourceConfigValidator) Validate(ctx context.Context, req ValidateResourceConfigRequest, resp *ValidateResourceConfigResponse) {
v.impl(ctx, req, resp)
}
func newTestResourceConfigValidator(impl func(context.Context, ValidateResourceConfigRequest, *ValidateResourceConfigResponse)) testResourceConfigValidator {
return testResourceConfigValidator{impl: impl}
}