2014-09-24 23:56:48 +02:00
|
|
|
package module
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/gob"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTreeEncodeDecodeGob(t *testing.T) {
|
2017-10-27 21:07:24 +02:00
|
|
|
storage := testStorage(t, nil)
|
2014-09-24 23:56:48 +02:00
|
|
|
tree := NewTree("", testConfig(t, "basic"))
|
|
|
|
|
|
|
|
// This should get things
|
2017-10-27 17:29:29 +02:00
|
|
|
storage.Mode = GetModeGet
|
|
|
|
if err := tree.Load(storage); err != nil {
|
2014-09-24 23:56:48 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|