~rbn/neinp

ref: 280ca11dc4f314d4bb506de2f219eb70dd959227 neinp/message/write_test.go -rw-r--r-- 781 bytes
280ca11dRuben Schuller update go.mod 1 year, 2 months 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
package message

import (
	"bytes"
	"testing"
)

func TestTWriteEncodeDecode(t *testing.T) {
	var buf bytes.Buffer
	a := &TWrite{Fid: 1, Offset: 2, Count: 4, Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}}
	_, err := a.encode(&buf)
	if err != nil {
		t.Error(err)
	}

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

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

	if !bytes.Equal(a.Data, b.Data) {
		t.Log(a, b)
		t.Log(a.Data, b.Data)
		t.Fail()
	}
}

func TestRWriteEncodeDecode(t *testing.T) {
	var buf bytes.Buffer
	a := &RWrite{Count: 1}
	_, err := a.encode(&buf)
	if err != nil {
		t.Error(err)
	}

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

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