-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbetween_test.go
More file actions
92 lines (85 loc) · 2.18 KB
/
between_test.go
File metadata and controls
92 lines (85 loc) · 2.18 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
package float64validator_test
import (
"context"
"testing"
"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
"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 float64
max float64
expectError bool
}
tests := map[string]testCase{
"not a Float64": {
val: types.Bool{Value: true},
expectError: true,
},
"unknown Float64": {
val: types.Float64{Unknown: true},
min: 0.90,
max: 3.10,
},
"null Float64": {
val: types.Float64{Null: true},
min: 0.90,
max: 3.10,
},
"valid integer as Float64": {
val: types.Float64{Value: 2},
min: 0.90,
max: 3.10,
},
"valid float as Float64": {
val: types.Float64{Value: 2.2},
min: 0.90,
max: 3.10,
},
"valid float as Float64 min": {
val: types.Float64{Value: 0.9},
min: 0.90,
max: 3.10,
},
"valid float as Float64 max": {
val: types.Float64{Value: 3.1},
min: 0.90,
max: 3.10,
},
"too small float as Float64": {
val: types.Float64{Value: -1.1111},
min: 0.90,
max: 3.10,
expectError: true,
},
"too large float as Float64": {
val: types.Float64{Value: 4.2},
min: 0.90,
max: 3.10,
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{}
float64validator.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)
}
})
}
}