opentofu/config/module/tree_gob_test.go
James Bardin 36eb40a432 export ModuleStorage and use it for Tree.Load
Exporting ModuleStorage allows us to explicitly pass in the storgae
location rather than extracting it out of the getter.Storage interface,
set a UI for communiating actions back to the user, and accepting a
services Disco for discovery.
2017-10-27 11:29:29 -04:00

39 lines
779 B
Go

package module
import (
"bytes"
"encoding/gob"
"strings"
"testing"
)
func TestTreeEncodeDecodeGob(t *testing.T) {
storage := testStorage(t)
tree := NewTree("", testConfig(t, "basic"))
// This should get things
storage.Mode = GetModeGet
if err := tree.Load(storage); err != nil {
t.Fatalf("err: %s", err)
}
// Encode it.
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
if err := enc.Encode(tree); err != nil {
t.Fatalf("err: %s", err)
}
dec := gob.NewDecoder(&buf)
var actual Tree
if err := dec.Decode(&actual); err != nil {
t.Fatalf("err: %s", err)
}
actualStr := strings.TrimSpace(actual.String())
expectedStr := strings.TrimSpace(tree.String())
if actualStr != expectedStr {
t.Fatalf("\n%s\n\nexpected:\n\n%s", actualStr, expectedStr)
}
}