-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
util_test.go
50 lines (42 loc) · 842 Bytes
/
util_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
package main
import (
"bytes"
"encoding/gob"
"io"
"testing"
)
func TestMsgWrite(t *testing.T) {
var err error
var buf bytes.Buffer
tests := []string{"foo", "bar", "baz"}
wc := msgWrite(gob.NewEncoder(&buf), "test")
for _, test := range tests {
if _, err = wc.Write([]byte(test)); err != nil {
t.Fatal(err)
}
}
dec := gob.NewDecoder(&buf)
for _, test := range tests {
var m msg
err = dec.Decode(&m)
if err != nil {
if err == io.EOF {
break
}
t.Fatal(err)
}
if m.Name != "test" {
t.Fatalf("want %q but %q", "test", m.Name)
}
if string(m.Data) != test {
t.Fatalf("want %q but %q", test, string(m.Data))
}
}
}
func TestMakeCmdLine(t *testing.T) {
got := makeCmdLine([]string{"foo", "bar baz"})
want := `foo "bar baz"`
if got != want {
t.Fatalf("want %q but %q", want, got)
}
}