-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathconflicting_test.go
More file actions
126 lines (117 loc) · 3.28 KB
/
conflicting_test.go
File metadata and controls
126 lines (117 loc) · 3.28 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package datasourcevalidator_test
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
func TestConflicting(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
pathExpressions path.Expressions
req datasource.ValidateConfigRequest
expected *datasource.ValidateConfigResponse
}{
"no-diagnostics": {
pathExpressions: path.Expressions{
path.MatchRoot("test"),
},
req: datasource.ValidateConfigRequest{
Config: tfsdk.Config{
Schema: tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test": {
Optional: true,
Type: types.StringType,
},
"other": {
Optional: true,
Type: types.StringType,
},
},
},
Raw: tftypes.NewValue(
tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"test": tftypes.String,
"other": tftypes.String,
},
},
map[string]tftypes.Value{
"test": tftypes.NewValue(tftypes.String, "test-value"),
"other": tftypes.NewValue(tftypes.String, "test-value"),
},
),
},
},
expected: &datasource.ValidateConfigResponse{},
},
"diagnostics": {
pathExpressions: path.Expressions{
path.MatchRoot("test1"),
path.MatchRoot("test2"),
},
req: datasource.ValidateConfigRequest{
Config: tfsdk.Config{
Schema: tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test1": {
Optional: true,
Type: types.StringType,
},
"test2": {
Optional: true,
Type: types.StringType,
},
"other": {
Optional: true,
Type: types.StringType,
},
},
},
Raw: tftypes.NewValue(
tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"test1": tftypes.String,
"test2": tftypes.String,
"other": tftypes.String,
},
},
map[string]tftypes.Value{
"test1": tftypes.NewValue(tftypes.String, "test-value"),
"test2": tftypes.NewValue(tftypes.String, "test-value"),
"other": tftypes.NewValue(tftypes.String, "test-value"),
},
),
},
},
expected: &datasource.ValidateConfigResponse{
Diagnostics: diag.Diagnostics{
diag.NewAttributeErrorDiagnostic(
path.Root("test1"),
"Invalid Attribute Combination",
"These attributes cannot be configured together: [test1,test2]",
),
},
},
},
}
for name, testCase := range testCases {
name, testCase := name, testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
validator := datasourcevalidator.Conflicting(testCase.pathExpressions...)
got := &datasource.ValidateConfigResponse{}
validator.ValidateDataSource(context.Background(), testCase.req, got)
if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}