Implement metadata code tests.
parent
7466ea6619
commit
92ca29cfac
|
@ -0,0 +1,32 @@
|
||||||
|
package streams
|
||||||
|
|
||||||
|
var (
|
||||||
|
exampleMetadataStr = `StreamTitle='Test 123';`
|
||||||
|
exampleMetadata = map[string]string{
|
||||||
|
"StreamTitle": "Test 123",
|
||||||
|
}
|
||||||
|
|
||||||
|
exampleData = []byte{
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7,
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7,
|
||||||
|
}
|
||||||
|
|
||||||
|
exampleCompleteData = append(
|
||||||
|
append(
|
||||||
|
append(
|
||||||
|
append(
|
||||||
|
append(
|
||||||
|
exampleData[0:4], // content
|
||||||
|
2, // 2*16 = 32 bytes in length
|
||||||
|
),
|
||||||
|
[]byte(exampleMetadataStr)..., // actual metadata
|
||||||
|
),
|
||||||
|
make([]byte, 9)..., // padding
|
||||||
|
),
|
||||||
|
exampleData[4:8]...,
|
||||||
|
),
|
||||||
|
0, // 0*16 = 0 bytes, no change in length
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_MetadataExtractor()
|
|
@ -0,0 +1,51 @@
|
||||||
|
package streams
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
originalStringA = "Aäöü´ß - \\_-_-_"
|
||||||
|
quotedStringA = "'Aäöü´ß - \\\\_-_-_'"
|
||||||
|
originalStringB = "hfn9'07';137gr\tbqp9\"ui"
|
||||||
|
quotedStringB = "'hfn9\\'07\\';137gr\tbqp9\"ui'"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Metadata(t *testing.T) {
|
||||||
|
Convey("Metadata", t, func() {
|
||||||
|
Convey("decoding", func() {
|
||||||
|
meta, err := DecodeMetadata("")
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(meta, ShouldHaveLength, 0)
|
||||||
|
|
||||||
|
meta, err = DecodeMetadata("StreamTitle=" + quotedStringA + ";")
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(meta, ShouldHaveLength, 1)
|
||||||
|
So(meta, ShouldContainKey, "StreamTitle")
|
||||||
|
So(meta["StreamTitle"], ShouldEqual, originalStringA)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("encoding", func() {
|
||||||
|
meta := Metadata{}
|
||||||
|
So(meta.String(), ShouldHaveLength, 0)
|
||||||
|
|
||||||
|
meta = Metadata{
|
||||||
|
"StreamTitle": originalStringA,
|
||||||
|
}
|
||||||
|
So(meta.String(), ShouldEqual,
|
||||||
|
fmt.Sprintf("StreamTitle=%s;",
|
||||||
|
quotedStringA))
|
||||||
|
|
||||||
|
meta = Metadata{
|
||||||
|
"StreamTitle": originalStringA,
|
||||||
|
"test": originalStringB,
|
||||||
|
}
|
||||||
|
So(meta.String(), ShouldEqual,
|
||||||
|
fmt.Sprintf("StreamTitle=%s;test=%s;",
|
||||||
|
quotedStringA, quotedStringB))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue