Skip to content

Commit c650534

Browse files
committed
Add tests for numbers.
Relies on hashicorp/terraform-plugin-go#85, which fixes a bug in using `tftypes.Value.As` to convert to a *big.Float.
1 parent bd6559a commit c650534

File tree

4 files changed

+426
-8
lines changed

4 files changed

+426
-8
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ go 1.16
44

55
require (
66
github.com/google/go-cmp v0.5.6
7-
github.com/hashicorp/terraform-plugin-go v0.3.0
7+
github.com/hashicorp/terraform-plugin-go v0.3.1-0.20210531205937-808fead526fc
88
)

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
3131
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
3232
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
3333
github.com/hashicorp/go-plugin v1.3.0/go.mod h1:F9eH4LrE/ZsRdbwhfjs9k9HoDUwAHnYtXdgmf1AVNs0=
34-
github.com/hashicorp/terraform-plugin-go v0.3.0 h1:AJqYzP52JFYl9NABRI7smXI1pNjgR5Q/y2WyVJ/BOZA=
35-
github.com/hashicorp/terraform-plugin-go v0.3.0/go.mod h1:dFHsQMaTLpON2gWhVWT96fvtlc/MF1vSy3OdMhWBzdM=
34+
github.com/hashicorp/terraform-plugin-go v0.3.1-0.20210531205937-808fead526fc h1:GOc748rJrcq68Zolqu8dJKREKl5n9nAj12mR38/pFrs=
35+
github.com/hashicorp/terraform-plugin-go v0.3.1-0.20210531205937-808fead526fc/go.mod h1:dFHsQMaTLpON2gWhVWT96fvtlc/MF1vSy3OdMhWBzdM=
3636
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
3737
github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
3838
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=

types/number.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,29 @@ func (n *Number) ToTerraformValue(_ context.Context) (interface{}, error) {
4646

4747
// Equal returns true if `other` is a *Number and has the same value as `n`.
4848
func (n *Number) Equal(other attr.Value) bool {
49-
o, ok := other.(*Number)
50-
if !ok {
51-
return false
52-
}
5349
if n == nil && other == nil {
5450
return true
5551
}
5652
if n == nil || other == nil {
5753
return false
5854
}
55+
o, ok := other.(*Number)
56+
if !ok {
57+
return false
58+
}
5959
if n.Unknown != o.Unknown {
6060
return false
6161
}
6262
if n.Null != o.Null {
6363
return false
6464
}
65-
return n.Value == o.Value
65+
if n.Value == nil && o.Value == nil {
66+
return true
67+
}
68+
if n.Value == nil || o.Value == nil {
69+
return false
70+
}
71+
return n.Value.Cmp(o.Value) == 0
6672
}
6773

6874
// SetTerraformValue updates the Number to match the contents of `val`.

0 commit comments

Comments
 (0)