github.com/sfdevops1/terrra4orm@v0.11.12-beta1/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, nil) 12 tree := NewTree("", testConfig(t, "basic")) 13 14 // This should get things 15 storage.Mode = GetModeGet 16 if err := tree.Load(storage); err != nil { 17 t.Fatalf("err: %s", err) 18 } 19 20 // Encode it. 21 var buf bytes.Buffer 22 enc := gob.NewEncoder(&buf) 23 if err := enc.Encode(tree); err != nil { 24 t.Fatalf("err: %s", err) 25 } 26 27 dec := gob.NewDecoder(&buf) 28 var actual Tree 29 if err := dec.Decode(&actual); err != nil { 30 t.Fatalf("err: %s", err) 31 } 32 33 actualStr := strings.TrimSpace(actual.String()) 34 expectedStr := strings.TrimSpace(tree.String()) 35 if actualStr != expectedStr { 36 t.Fatalf("\n%s\n\nexpected:\n\n%s", actualStr, expectedStr) 37 } 38 }