beam: more unit tests
This adds testing to SendConn. Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
0e093988bf
commit
8104b14a8d
1 changed files with 39 additions and 0 deletions
39
beam/beam_test.go
Normal file
39
beam/beam_test.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package beam
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/dotcloud/docker/pkg/beam/data"
|
||||
)
|
||||
|
||||
func TestSendConn(t *testing.T) {
|
||||
a, b, err := USocketPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer a.Close()
|
||||
defer b.Close()
|
||||
go func() {
|
||||
conn, err := SendConn(a, data.Empty().Set("type", "connection").Bytes())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := conn.Send(data.Empty().Set("foo", "bar").Bytes(), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conn.CloseWrite()
|
||||
}()
|
||||
payload, conn, err := ReceiveConn(b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if val := data.Message(string(payload)).Get("type"); val == nil || val[0] != "connection" {
|
||||
t.Fatalf("%v != %v\n", val, "connection")
|
||||
}
|
||||
msg, _, err := conn.Receive()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if val := data.Message(string(msg)).Get("foo"); val == nil || val[0] != "bar" {
|
||||
t.Fatalf("%v != %v\n", val, "bar")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue