open-nomad/vendor/github.com/zclconf/go-cty/cty/gob_test.go
Danielle Tomlinson b59ed9d6c9 vendor: Update to latest hcl2
* Includes fixes for handling null blocks https://github.com/hashicorp/hcl2/pull/87
* Updates go-cty as a newer version is required by hcl2
2019-02-14 13:34:46 +01:00

55 lines
941 B
Go

package cty
import (
"bytes"
"testing"
"encoding/gob"
)
func TestGobabilty(t *testing.T) {
tests := []Value{
StringVal("hi"),
True,
NumberIntVal(1),
NumberFloatVal(96.5),
ListVal([]Value{True}),
MapVal(map[string]Value{"true": True}),
SetVal([]Value{True}),
TupleVal([]Value{True}),
ObjectVal(map[string]Value{"true": True}),
}
for _, testValue := range tests {
t.Run(testValue.GoString(), func(t *testing.T) {
tv := testGob{
testValue,
}
buf := &bytes.Buffer{}
enc := gob.NewEncoder(buf)
err := enc.Encode(tv)
if err != nil {
t.Fatalf("gob encode error: %s", err)
}
var ov testGob
dec := gob.NewDecoder(buf)
err = dec.Decode(&ov)
if err != nil {
t.Fatalf("gob decode error: %s", err)
}
if !ov.Value.RawEquals(tv.Value) {
t.Errorf("value did not survive gobbing\ninput: %#v\noutput: %#v", tv, ov)
}
})
}
}
type testGob struct {
Value Value
}