~rbn/neinp

ref: b441da6dea2e963387a86b9d1d57802b77f21b83 neinp/message/walk_test.go -rw-r--r-- 1.1 KiB
b441da6dRuben Schuller initial commit 2 years 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package message

import (
	"github.com/rbns/neinp/qid"
	"bytes"
	"strings"
	"testing"
)

func TestTWalkEncodeDecode(t *testing.T) {
	var buf bytes.Buffer
	a := &TWalk{Fid: 1, Newfid: 2, Wname: []string{"dead", "beef"}}
	_, err := a.encode(&buf)
	if err != nil {
		t.Error(err)
	}

	b := &TWalk{}
	_, err = b.decode(&buf)
	if err != nil {
		t.Error(err)
	}

	if a.Fid != b.Fid || a.Newfid != b.Newfid {
		t.Log(a, b)
		t.Fail()
	}

	if len(a.Wname) != len(b.Wname) {
		t.Fail()
	}

	if strings.Join(a.Wname, "") != strings.Join(b.Wname, "") {
		t.Fail()
	}
}

func TestRWalkEncodeDecode(t *testing.T) {
	var buf bytes.Buffer
	a := &RWalk{Wqid: []qid.Qid{qid.Qid{1, 2, 3}, qid.Qid{4, 5, 6}}}
	_, err := a.encode(&buf)
	if err != nil {
		t.Error(err)
	}

	b := &RWalk{}
	_, err = b.decode(&buf)
	if err != nil {
		t.Error(err)
	}

	if len(a.Wqid) != len(b.Wqid) {
		t.Logf("wrong wqid len, a: %v, b: %v", len(a.Wqid), len(b.Wqid))
		t.Fail()
	} else {
		for i, v := range a.Wqid {
			if b.Wqid[i] != v {
				t.Logf("wqids differ, a.Wqid[i]: %v, b.Wqid[i]: %v", v, b.Wqid[i])
				t.Fail()
			}
		}
	}
}