~rbn/neinp

ref: 280ca11dc4f314d4bb506de2f219eb70dd959227 neinp/message/stat_test.go -rw-r--r-- 1.2 KiB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package message

import (
	"git.sr.ht/~rbn/neinp/qid"
	"git.sr.ht/~rbn/neinp/stat"
	"bytes"
	"testing"
	"time"
)

func TestStatEncodeDecode(t *testing.T) {
	var buf bytes.Buffer
	a := &stat.Stat{Typ: 1, Dev: 2, Qid: qid.Qid{3, 4, 5}, Mode: 6, Atime: time.Unix(1234567, 0), Mtime: time.Unix(1234567, 0), Length: 6, Name: "deadbeef", Uid: "foo", Gid: "bar", Muid: "baz"}
	_, err := a.Encode(&buf)
	if err != nil {
		t.Error(err)
	}

	b := &stat.Stat{}
	_, err = b.Decode(&buf)
	if err != nil {
		t.Error(err)
	}

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

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

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

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

func TestRStatEncodeDecode(t *testing.T) {
	var buf bytes.Buffer
	a := &RStat{Stat: stat.Stat{Typ: 1, Dev: 2, Qid: qid.Qid{3, 4, 5}, Mode: 6, Atime: time.Unix(1234567, 0), Mtime: time.Unix(1234567, 0), Length: 6, Name: "deadbeef", Uid: "foo", Gid: "bar", Muid: "baz"}}
	_, err := a.encode(&buf)
	if err != nil {
		t.Error(err)
	}

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

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