-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlinkio_test.go
53 lines (46 loc) · 1.05 KB
/
linkio_test.go
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
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package linkio
import (
"bytes"
"io"
"testing"
)
func TestReader(t *testing.T) {
// a dummy buffer full of zeros to send over the link
var y [1000]byte
buf := bytes.NewBuffer(y[:])
lr := NewLink(Throughput(30) * KilobitPerSecond /* kbps */).NewLinkReader(buf)
for {
var x [1024]byte
n, err := lr.Read(x[:])
if err == io.EOF {
break
}
if err != nil {
t.Error("err ", err)
}
t.Log("got", n, "bytes")
}
}
type fw struct {
buf []byte
}
func (f *fw) Write(buf []byte) (int, error) {
f.buf = append(f.buf, buf...)
return len(buf), nil
}
func TestWriter(t *testing.T) {
// a fake writer
w := &fw{}
// a dummy buffer full of zeros to send over the link
var y [1000]byte
lw := NewLink(Throughput(30) * KilobitPerSecond /* kbps */).NewLinkWriter(w)
n, err := lw.Write(y[:])
if err != nil {
t.Error("err ", err)
}
t.Log("wrote", n, "bytes")
t.Log("got", len(w.buf), "bytes")
}