~whereswaldon/forest-go

forest-go/node_test.go -rw-r--r-- 624 bytes
0e51e2b5Chris Waldon deps: update to latest protonmail crypto 4 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package forest_test

import (
	"testing"

	forest "git.sr.ht/~whereswaldon/forest-go"
	"git.sr.ht/~whereswaldon/forest-go/testutil"
)

func TestUnmarshalNode(t *testing.T) {
	id, _, community, reply := testutil.MakeReplyOrSkip(t)
	for _, node := range []forest.Node{id, community, reply} {
		bin, err := node.MarshalBinary()
		if err != nil {
			t.Skip("Failed to marshal node into binary", err)
		}
		out, err := forest.UnmarshalBinaryNode(bin)
		if err != nil {
			t.Errorf("Failed to unmarshal valid binary node: %v", err)
		}
		if !out.Equals(node) {
			t.Errorf("Unmarshaled node is not the same as original")
		}
	}
}