beam/data: fix a bug in encoding of multi-value maps
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
dbbde543b1
commit
53602b2464
2 changed files with 40 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -89,3 +90,40 @@ func TestEncodeBinaryValue(t *testing.T) {
|
|||
t.Fatalf("'%v' != '%v'", output, expectedOutput)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeString(t *testing.T) {
|
||||
validEncodedStrings := []struct{
|
||||
input string
|
||||
output string
|
||||
skip int
|
||||
}{
|
||||
{"3:foo,", "foo", 6},
|
||||
{"5:hello,", "hello", 8},
|
||||
{"5:hello,5:world,", "hello", 8},
|
||||
}
|
||||
for _, sample := range validEncodedStrings {
|
||||
output, skip, err := decodeString(sample.input)
|
||||
if err != nil {
|
||||
t.Fatalf("error decoding '%v': %v", sample.input, err)
|
||||
}
|
||||
if skip != sample.skip {
|
||||
t.Fatalf("invalid skip: %v!=%v", skip, sample.skip)
|
||||
}
|
||||
if output != sample.output {
|
||||
t.Fatalf("invalid output: %v!=%v", output, sample.output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecode1Key1Value(t *testing.T) {
|
||||
input := "000;3:foo,6:3:bar,,"
|
||||
output, err := Decode(input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v, exists := output["foo"]; !exists {
|
||||
t.Fatalf("wrong output: %v\n", output)
|
||||
} else if len(v) != 1 || strings.Join(v, "") != "bar" {
|
||||
t.Fatalf("wrong output: %v\n", output)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue