Add some tests for TypeFloat

This commit is contained in:
Dave Cunningham 2015-01-28 15:22:47 -05:00
parent 18c26cb2eb
commit 319933f551
1 changed files with 121 additions and 0 deletions

View File

@ -615,6 +615,81 @@ func TestResourceDataGet(t *testing.T) {
Value: []interface{}{},
},
// #20 Float zero
{
Schema: map[string]*Schema{
"ratio": &Schema{
Type: TypeFloat,
Optional: true,
Computed: true,
},
},
State: nil,
Diff: nil,
Key: "ratio",
Value: []interface{}{0.0},
},
// #21 Float given
{
Schema: map[string]*Schema{
"ratio": &Schema{
Type: TypeFloat,
Optional: true,
Computed: true,
},
},
State: &terraform.InstanceState{
Attributes: map[string]string{
"ratio": "0.5",
},
},
Diff: nil,
Key: "ratio",
Value: []interface{}{0.5},
},
// #22 Float diff
{
Schema: map[string]*Schema{
"ratio": &Schema{
Type: TypeFloat,
Optional: true,
Computed: true,
},
},
State: &terraform.InstanceState{
Attributes: map[string]string{
"ratio": "-0.5",
},
},
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ratio": &terraform.ResourceAttrDiff{
Old: "-0.5",
New: "33.0",
},
},
},
Key: "ratio",
Value: []interface{}{33.0},
},
}
for i, tc := range cases {
@ -1412,6 +1487,52 @@ func TestResourceDataSet(t *testing.T) {
return v
},
},
// #12: List of floats, set list
{
Schema: map[string]*Schema{
"ratios": &Schema{
Type: TypeList,
Computed: true,
Elem: &Schema{Type: TypeFloat},
},
},
State: nil,
Diff: nil,
Key: "ratios",
Value: []float64{1.0, 2.2, 5.5},
GetKey: "ratios",
GetValue: []interface{}{1.0, 2.2, 5.5},
},
// #12: Set of floats, set list
{
Schema: map[string]*Schema{
"ratios": &Schema{
Type: TypeSet,
Computed: true,
Elem: &Schema{Type: TypeFloat},
Set: func(a interface{}) int {
return int(math.Float64bits(a.(float64)))
},
},
},
State: nil,
Diff: nil,
Key: "ratios",
Value: []float64{1.0, 2.2, 5.5},
GetKey: "ratios",
GetValue: []interface{}{1.0, 2.2, 5.5},
},
}
for i, tc := range cases {