~rbn/neinp

ref: 280ca11dc4f314d4bb506de2f219eb70dd959227 neinp/server_test.go -rw-r--r-- 1.1 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
package neinp

import (
	"git.sr.ht/~rbn/neinp/message"
	"bytes"
	"context"
	"io"
	"testing"
)

type MsizeFS struct {
	NopP2000
}

func (f *MsizeFS) Version(ctx context.Context, req message.TVersion) (message.RVersion, error) {
	return message.RVersion{Msize: req.Msize, Version: req.Version}, nil
}

func TestMsize(t *testing.T) {
	s := NewServer(&MsizeFS{})

	content := message.TVersion{Msize: 1234, Version: "9P2000"}
	msg, err := message.New(0x1, &content)
	if err != nil {
		t.Error(err)
	}

	s.process(msg)

	if s.msize != content.Msize {
		t.Logf("Want: %v Have: %v", content.Msize, s.msize)
		t.Fail()
	}
}

func TestRcv(t *testing.T) {
	buf := bytes.NewReader([]byte{0x1b, 0x0, 0x0, 0x0, 0x68, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x0, 0x74, 0x65, 0x73, 0x74, 0x4, 0x0, 0x74, 0x65, 0x73, 0x74})

	done := make(chan struct{})

	s := &Server{}

	msgs, errs := s.rcv(done, buf)

	select {
	case x := <-msgs:
		y, ok := x.Content.(*message.TAttach)
		if !ok {
			t.Fail()
		}
		if y.Uname != "test" {
			t.Fail()
		}
		if y.Aname != "test" {
			t.Fail()
		}
	case err := <-errs:
		if err != io.EOF {
			t.Error(err)
		}
	}

}