Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Do not merge) - CI Testing for PR #396 #397

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tftypes/value_msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func marshalMsgPackNumber(val Value, typ Type, p *AttributePath, enc *msgpack.En
if err != nil {
return p.NewErrorf("error encoding int value: %w", err)
}
} else if fv, acc := n.Float64(); acc == big.Exact {
} else if fv, acc := n.Float64(); acc == big.Exact && !n.IsInt() {
err := enc.EncodeFloat64(fv)
if err != nil {
return p.NewErrorf("error encoding float value: %w", err)
Expand Down
16 changes: 13 additions & 3 deletions tftypes/value_msgpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func TestValueFromMsgPack(t *testing.T) {
if err != nil {
t.Fatalf("error parsing awkward fraction: %s", err)
}

// integer under 64 bits which rounds incorrectly if parsed as a float64
uint64AsFloat, _ := new(big.Float).SetString("9223372036854775808")

tests := map[string]testCase{
"hello-string": {
hex: "a568656c6c6f",
Expand Down Expand Up @@ -94,7 +98,8 @@ func TestValueFromMsgPack(t *testing.T) {
typ: Number,
},
"float64-positive-number": {
hex: "cb7fefffffffffffff",
// Because MaxFloat64 is an integer value, it must be encoded as an integer to ensure we don't lose precision when decoding the value
hex: "da0135313739373639333133343836323331353730303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030",
value: NewValue(Number, new(big.Float).SetFloat64(math.MaxFloat64)),
typ: Number,
},
Expand Down Expand Up @@ -123,6 +128,11 @@ func TestValueFromMsgPack(t *testing.T) {
value: NewValue(Number, big.NewFloat(math.Inf(-1))),
typ: Number,
},
"large-uint64": {
hex: "b339323233333732303336383534373735383038",
value: NewValue(Number, uint64AsFloat),
typ: Number,
},
"dynamic-bool": {
hex: "92c40622626f6f6c22c3",
value: NewValue(Bool, true),
Expand Down Expand Up @@ -545,8 +555,8 @@ func TestValueFromMsgPack(t *testing.T) {
t.Fatalf("unexpected error unmarshaling: %s", err)
}

if diff := cmp.Diff(test.value, val); diff != "" {
t.Errorf("Unexpected results (-wanted +got): %s", diff)
if test.value.String() != val.String() {
t.Errorf("Unexpected results (-wanted +got): %s", cmp.Diff(test.value, val))
}
})
}
Expand Down
Loading