github.com/richardbowden/terraform@v0.6.12-0.20160901200758-30ea22c25211/config/module/tree_gob_test.go (about) 1 package module 2 3 import ( 4 "bytes" 5 "encoding/gob" 6 "strings" 7 "testing" 8 ) 9 10 func TestTreeEncodeDecodeGob(t *testing.T) { 11 storage := testStorage(t) 12 tree := NewTree("", testConfig(t, "basic")) 13 14 // This should get things 15 if err := tree.Load(storage, GetModeGet); err != nil { 16 t.Fatalf("err: %s", err) 17 } 18 19 // Encode it. 20 var buf bytes.Buffer 21 enc := gob.NewEncoder(&buf) 22 if err := enc.Encode(tree); err != nil { 23 t.Fatalf("err: %s", err) 24 } 25 26 dec := gob.NewDecoder(&buf) 27 var actual Tree 28 if err := dec.Decode(&actual); err != nil { 29 t.Fatalf("err: %s", err) 30 } 31 32 actualStr := strings.TrimSpace(actual.String()) 33 expectedStr := strings.TrimSpace(tree.String()) 34 if actualStr != expectedStr { 35 t.Fatalf("\n%s\n\nexpected:\n\n%s", actualStr, expectedStr) 36 } 37 }