-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbetween_test.go
More file actions
87 lines (80 loc) · 2 KB
/
between_test.go
File metadata and controls
87 lines (80 loc) · 2 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
package int64validator_test
import (
"context"
"testing"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func TestBetweenValidator(t *testing.T) {
t.Parallel()
type testCase struct {
val attr.Value
min int64
max int64
expectError bool
}
tests := map[string]testCase{
"not an Int64": {
val: types.Bool{Value: true},
expectError: true,
},
"unknown Int64": {
val: types.Int64{Unknown: true},
min: 1,
max: 3,
},
"null Int64": {
val: types.Int64{Null: true},
min: 1,
max: 3,
},
"valid integer as Int64": {
val: types.Int64{Value: 2},
min: 1,
max: 3,
},
"valid integer as Int64 min": {
val: types.Int64{Value: 1},
min: 1,
max: 3,
},
"valid integer as Int64 max": {
val: types.Int64{Value: 3},
min: 1,
max: 3,
},
"too small integer as Int64": {
val: types.Int64{Value: -1},
min: 1,
max: 3,
expectError: true,
},
"too large integer as Int64": {
val: types.Int64{Value: 42},
min: 1,
max: 3,
expectError: true,
},
}
for name, test := range tests {
name, test := name, test
t.Run(name, func(t *testing.T) {
request := tfsdk.ValidateAttributeRequest{
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
AttributeConfig: test.val,
}
response := tfsdk.ValidateAttributeResponse{}
int64validator.Between(test.min, test.max).Validate(context.TODO(), request, &response)
if !response.Diagnostics.HasError() && test.expectError {
t.Fatal("expected error, got no error")
}
if response.Diagnostics.HasError() && !test.expectError {
t.Fatalf("got unexpected error: %s", response.Diagnostics)
}
})
}
}