beam/data: convenience Message type for chained manipulation
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
ccdcd9ff0c
commit
dbbde543b1
2 changed files with 100 additions and 0 deletions
53
beam/data/message_test.go
Normal file
53
beam/data/message_test.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEmptyMessage(t *testing.T) {
|
||||
m := Empty()
|
||||
if m.String() != Encode(nil) {
|
||||
t.Fatalf("%v != %v", m.String(), Encode(nil))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetMessage(t *testing.T) {
|
||||
m := Empty().Set("foo", "bar")
|
||||
output := m.String()
|
||||
expectedOutput := "000;3:foo,6:3:bar,,"
|
||||
if output != expectedOutput {
|
||||
t.Fatalf("'%v' != '%v'", output, expectedOutput)
|
||||
}
|
||||
decodedOutput, err := Decode(output)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(decodedOutput) != 1 {
|
||||
t.Fatalf("wrong output data: %#v\n", decodedOutput)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetMessageTwice(t *testing.T) {
|
||||
m := Empty().Set("foo", "bar").Set("ga", "bu")
|
||||
output := m.String()
|
||||
expectedOutput := "000;3:foo,6:3:bar,,2:ga,5:2:bu,,"
|
||||
if output != expectedOutput {
|
||||
t.Fatalf("'%v' != '%v'", output, expectedOutput)
|
||||
}
|
||||
decodedOutput, err := Decode(output)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(decodedOutput) != 2 {
|
||||
t.Fatalf("wrong output data: %#v\n", decodedOutput)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDelMessage(t *testing.T) {
|
||||
m := Empty().Set("foo", "bar").Del("foo")
|
||||
output := m.String()
|
||||
expectedOutput := Encode(nil)
|
||||
if output != expectedOutput {
|
||||
t.Fatalf("'%v' != '%v'", output, expectedOutput)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue