diff options
Diffstat (limited to 'src/hub/src/spreadspace.org/sfive/s5cvt_test.go')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5cvt_test.go | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5cvt_test.go b/src/hub/src/spreadspace.org/sfive/s5cvt_test.go index 0b13043..95c7958 100644 --- a/src/hub/src/spreadspace.org/sfive/s5cvt_test.go +++ b/src/hub/src/spreadspace.org/sfive/s5cvt_test.go @@ -48,7 +48,8 @@ var ( updateStruct = Update{Data: UpdateData{BytesSent: 1, ClientCount: 3, BytesReceived: 1}, StartTime: time.Date(2014, time.August, 24, 14, 35, 33, 847282000, time.UTC), Duration: 5000} ) -func GetExpected() (expected UpdateFull) { +func GetExpected() (expected *UpdateFull) { + expected = &UpdateFull{} expected.Version = ProtocolVersion expected.CopyFromSource(&initStruct) expected.CopyFromUpdate(&updateStruct) @@ -73,6 +74,28 @@ func TestDecodeStateless(t *testing.T) { t.Fatalf("decoding message with wrong protocol version should throw an error") } + // missing/empty source fields + emptyHostname := `"hostname": "", "stream": {"quality": "low", "content": "av", "format": "webm"}` + dec = NewStatelessDecoder(strings.NewReader(fmt.Sprintf(`{ "version": %d, %s, %s }`, ProtocolVersion, emptyHostname, updateEncoded))) + if _, err := dec.Decode(); err == nil { + t.Fatalf("decoding message with empty/missing hostname should throw an error") + } + emptyContentid := `"hostname": "localhost", "stream": {"quality": "low", "format": "webm"}` + dec = NewStatelessDecoder(strings.NewReader(fmt.Sprintf(`{ "version": %d, %s, %s }`, ProtocolVersion, emptyContentid, updateEncoded))) + if _, err := dec.Decode(); err == nil { + t.Fatalf("decoding message with empty/missing content-id should throw an error") + } + emptyFormat := `"hostname": "localhost", "stream": {"quality": "low", "content": "av", "format": ""}` + dec = NewStatelessDecoder(strings.NewReader(fmt.Sprintf(`{ "version": %d, %s, %s }`, ProtocolVersion, emptyFormat, updateEncoded))) + if _, err := dec.Decode(); err == nil { + t.Fatalf("decoding message with empty/missing format should throw an error") + } + emptyQuality := `"hostname": "localhost", "stream": {"content": "av", "format": "webm"}` + dec = NewStatelessDecoder(strings.NewReader(fmt.Sprintf(`{ "version": %d, %s, %s }`, ProtocolVersion, emptyQuality, updateEncoded))) + if _, err := dec.Decode(); err == nil { + t.Fatalf("decoding message with empty/missing quality should throw an error") + } + // valid message dec = NewStatelessDecoder(strings.NewReader(fmt.Sprintf(`{ "version": %d, %s, %s }`, ProtocolVersion, initEncoded, updateEncoded))) decoded, err := dec.Decode() @@ -155,7 +178,7 @@ func TestDecodeStateful(t *testing.T) { } func TestEncodeStateless(t *testing.T) { - var uf UpdateFull + uf := &UpdateFull{} uf.CopyFromSource(&initStruct) uf.CopyFromUpdate(&updateStruct) @@ -184,7 +207,7 @@ func TestEncodeStateless(t *testing.T) { } func TestEncodeStateful(t *testing.T) { - var uf UpdateFull + uf := &UpdateFull{} uf.CopyFromSource(&initStruct) uf.CopyFromUpdate(&updateStruct) |