diff --git a/.circleci/config.yml b/.circleci/config.yml
index f8b6ee8..89d2e12 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -7,20 +7,4 @@ jobs:
working_directory: "/go/src/github.com/zencoder/go-dash"
steps:
- checkout
- - run:
- name: Install Glide
- command: |
- set -eux
- curl -sSLfO https://github.com/Masterminds/glide/releases/download/v0.12.3/glide-v0.12.3-linux-amd64.tar.gz
- mkdir -p /go/bin glide
- tar -xzf glide-v0.12.3-linux-amd64.tar.gz -C ./glide
- cp ./glide/linux-amd64/glide /go/bin/glide
- rm -rf glide glide-v0.12.3-linux-amd64.tar.gz
- - restore_cache:
- key: glide-{{ checksum "glide.lock" }}
- - run: /go/bin/glide install
- - save_cache:
- key: glide-{{ checksum "glide.lock" }}
- paths:
- - vendor
- run: make test
diff --git a/Makefile b/Makefile
index 3857362..4606220 100644
--- a/Makefile
+++ b/Makefile
@@ -10,22 +10,18 @@ endif
.PHONY: all
all: test
-vendor:
- glide install
-
.PHONY: test
-test: vendor
+test:
go test $(V) ./... -race
.PHONY: generate
-generate: vendor
- GENERATE_FIXTURES=true $(MAKE) test
+generate: export GENERATE_FIXTURES=true
+generate: test
.PHONY: fmt
fmt:
- find . -not -path "./vendor/*" -name '*.go' -type f | sed 's#\(.*\)/.*#\1#' | sort -u | xargs -n1 -I {} bash -c "cd {} && goimports -w *.go && gofmt -w -s -l *.go"
+ go fmt $(X) ./...
.PHONY: clean
clean:
- rm -rf vendor/
go clean -i $(X) -cache -testcache
diff --git a/glide.lock b/glide.lock
deleted file mode 100644
index c25466f..0000000
--- a/glide.lock
+++ /dev/null
@@ -1,17 +0,0 @@
-hash: fa28369eecce691920c5e11d3c66f10a46cf5875614aacda800ca66099ba95cd
-updated: 2019-01-08T14:40:31.686615Z
-imports:
-- name: github.com/davecgh/go-spew
- version: 8991bc29aa16c548c550c7ff78260e27b9ab7c73
- subpackages:
- - spew
-- name: github.com/pmezard/go-difflib
- version: 792786c7400a136282c1664665ae0a8db921c6c2
- subpackages:
- - difflib
-- name: github.com/stretchr/testify
- version: ffdc059bfe9ce6a4e144ba849dbedead332c6053
- subpackages:
- - assert
- - require
-testImports: []
diff --git a/glide.yaml b/glide.yaml
deleted file mode 100644
index 03445c8..0000000
--- a/glide.yaml
+++ /dev/null
@@ -1,6 +0,0 @@
-package: github.com/zencoder/go-dash
-import:
-- package: github.com/stretchr/testify
- version: ^1.3.0
- subpackages:
- - require
diff --git a/helpers/require/require.go b/helpers/require/require.go
new file mode 100644
index 0000000..41b128a
--- /dev/null
+++ b/helpers/require/require.go
@@ -0,0 +1,189 @@
+package require
+
+import (
+ "reflect"
+ "testing"
+)
+
+func NoError(t *testing.T, err error, msgs ...string) {
+ if err != nil {
+ t.Errorf("Expected no error, but got: %s", err)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ }
+}
+
+func NotNil(t *testing.T, object interface{}, msgs ...string) {
+ if isNil(object) {
+ t.Errorf("Expected nil, but got an object")
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ }
+}
+
+func Nil(t *testing.T, object interface{}, msgs ...string) {
+ if !isNil(object) {
+ t.Errorf("Expected an object, but got nil")
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ }
+}
+
+func isNil(object interface{}) bool {
+ if object == nil {
+ return true
+ }
+
+ value := reflect.ValueOf(object)
+ kind := value.Kind()
+ if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
+ return true
+ }
+
+ return false
+}
+
+func EqualError(t *testing.T, theError error, errString string, msgs ...string) {
+ if theError == nil {
+ t.Errorf("Expected an error but got nil")
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ return
+ }
+
+ if theError.Error() != errString {
+ t.Errorf("Expected an error with message:\n%qbut got \n%q", errString, theError)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ }
+}
+
+func EqualFloat64(t *testing.T, expected, actual float64, msgs ...string) {
+ if expected != actual {
+ t.Errorf("Expected %f but got %f", expected, actual)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ }
+}
+
+func EqualStringPtr(t *testing.T, expected, actual *string, msgs ...string) {
+ if expected == nil && actual == nil {
+ return
+ }
+ if expected != nil && actual != nil {
+ EqualString(t, *expected, *actual, msgs...)
+ return
+ }
+
+ t.Errorf("Expected %v but got %v", expected, actual)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+}
+
+func EqualString(t *testing.T, expected, actual string, msgs ...string) {
+ if expected != actual {
+ t.Errorf("Expected %s but got %s", expected, actual)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ }
+}
+
+func EqualUInt32(t *testing.T, expected, actual uint32, msgs ...string) {
+ if expected != actual {
+ t.Errorf("Expected %d but got %d", expected, actual)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ }
+}
+
+func EqualUInt64Ptr(t *testing.T, expected, actual *uint64, msgs ...string) {
+ if expected == nil && actual == nil {
+ return
+ }
+ if expected != nil && actual != nil {
+ EqualUInt64(t, *expected, *actual, msgs...)
+ return
+ }
+
+ t.Errorf("Expected %v but got %v", expected, actual)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+}
+
+func EqualUInt64(t *testing.T, expected, actual uint64, msgs ...string) {
+ if expected != actual {
+ t.Errorf("Expected %d but got %d", expected, actual)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ }
+}
+
+func EqualIntPtr(t *testing.T, expected, actual *int, msgs ...string) {
+ if expected == nil && actual == nil {
+ return
+ }
+ if expected != nil && actual != nil {
+ EqualInt(t, *expected, *actual, msgs...)
+ return
+ }
+
+ t.Errorf("Expected %v but got %v", expected, actual)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+}
+
+func EqualInt(t *testing.T, expected, actual int, msgs ...string) {
+ if expected != actual {
+ t.Errorf("Expected %d but got %d", expected, actual)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ }
+}
+
+func EqualErr(t *testing.T, expected, actual error, msgs ...string) {
+ if expected != actual {
+ t.Errorf("Expected %s but got %s", expected, actual)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ }
+}
+
+func Implements(t *testing.T, interfaceObject interface{}, object interface{}, msgs ...string) {
+ interfaceType := reflect.TypeOf(interfaceObject).Elem()
+
+ if !reflect.TypeOf(object).Implements(interfaceType) {
+ t.Errorf("Expected %T but got %v", object, interfaceType)
+ for _, msg := range msgs {
+ t.Errorf("\n" + msg)
+ }
+ t.FailNow()
+ }
+}
diff --git a/helpers/testfixtures/testfixtures.go b/helpers/testfixtures/testfixtures.go
index e8298ab..8f45684 100644
--- a/helpers/testfixtures/testfixtures.go
+++ b/helpers/testfixtures/testfixtures.go
@@ -6,7 +6,7 @@ import (
"os"
"testing"
- "github.com/stretchr/testify/require"
+ "github.com/zencoder/go-dash/helpers/require"
)
// Load test fixture from path relative to fixtures directory
@@ -25,5 +25,5 @@ func CompareFixture(t *testing.T, fixturePath string, actualContent string) {
fmt.Println("Wrote fixture: " + fixturePath)
return
}
- require.Equal(t, expectedContent, actualContent)
+ require.EqualString(t, expectedContent, actualContent)
}
diff --git a/mpd/duration_test.go b/mpd/duration_test.go
index 2704190..d77fc36 100644
--- a/mpd/duration_test.go
+++ b/mpd/duration_test.go
@@ -1,10 +1,11 @@
package mpd
import (
+ "fmt"
"testing"
"time"
- "github.com/stretchr/testify/require"
+ "github.com/zencoder/go-dash/helpers/require"
)
func TestDuration(t *testing.T) {
@@ -15,9 +16,9 @@ func TestDuration(t *testing.T) {
}
for ins, ex := range in {
timeDur, err := time.ParseDuration(ins)
- require.Equal(t, nil, err)
+ require.NoError(t, err)
dur := Duration(timeDur)
- require.Equal(t, ex, dur.String())
+ require.EqualString(t, ex, dur.String())
}
}
@@ -37,7 +38,7 @@ func TestParseDuration(t *testing.T) {
for ins, ex := range in {
act, err := parseDuration(ins)
require.NoError(t, err, ins)
- require.Equal(t, ex, act.Seconds(), ins)
+ require.EqualFloat64(t, ex, act.Seconds(), ins)
}
}
@@ -54,6 +55,6 @@ func TestParseBadDurations(t *testing.T) {
}
for ins, msg := range in {
_, err := parseDuration(ins)
- require.EqualError(t, err, msg, "Expected an error for: %s", ins)
+ require.EqualError(t, err, msg, fmt.Sprintf("Expected an error for: %s", ins))
}
}
diff --git a/mpd/mpd_read_write_test.go b/mpd/mpd_read_write_test.go
index 3cc16a1..4431bc3 100644
--- a/mpd/mpd_read_write_test.go
+++ b/mpd/mpd_read_write_test.go
@@ -5,7 +5,7 @@ import (
"testing"
"time"
- "github.com/stretchr/testify/require"
+ "github.com/zencoder/go-dash/helpers/require"
"github.com/zencoder/go-dash/helpers/testfixtures"
)
@@ -43,13 +43,13 @@ func TestNewMPDLiveWriteToString(t *testing.T) {
AttrAvailabilityStartTime(VALID_AVAILABILITY_START_TIME))
xmlStr, err := m.WriteToString()
- require.Nil(t, err)
+ require.NoError(t, err)
expectedXML := `
`
- require.Equal(t, expectedXML, xmlStr)
+ require.EqualString(t, expectedXML, xmlStr)
}
func TestNewDynamicMPDLiveWriteToString(t *testing.T) {
@@ -58,26 +58,26 @@ func TestNewDynamicMPDLiveWriteToString(t *testing.T) {
AttrMinimumUpdatePeriod(VALID_MINIMUM_UPDATE_PERIOD))
xmlStr, err := m.WriteToString()
- require.Nil(t, err)
+ require.NoError(t, err)
expectedXML := `
`
- require.Equal(t, expectedXML, xmlStr)
+ require.EqualString(t, expectedXML, xmlStr)
}
func TestNewMPDOnDemandWriteToString(t *testing.T) {
m := NewMPD(DASH_PROFILE_ONDEMAND, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
xmlStr, err := m.WriteToString()
- require.Nil(t, err)
+ require.NoError(t, err)
expectedXML := `
`
- require.Equal(t, expectedXML, xmlStr)
+ require.EqualString(t, expectedXML, xmlStr)
}
func TestAddNewAdaptationSetAudioWriteToString(t *testing.T) {
@@ -86,7 +86,7 @@ func TestAddNewAdaptationSetAudioWriteToString(t *testing.T) {
_, _ = m.AddNewAdaptationSetAudioWithID("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG)
xmlStr, err := m.WriteToString()
- require.Nil(t, err)
+ require.NoError(t, err)
expectedXML := `
@@ -94,7 +94,7 @@ func TestAddNewAdaptationSetAudioWriteToString(t *testing.T) {
`
- require.Equal(t, expectedXML, xmlStr)
+ require.EqualString(t, expectedXML, xmlStr)
}
func TestAddNewAdaptationSetVideoWriteToString(t *testing.T) {
@@ -103,7 +103,7 @@ func TestAddNewAdaptationSetVideoWriteToString(t *testing.T) {
_, _ = m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
xmlStr, err := m.WriteToString()
- require.Nil(t, err)
+ require.NoError(t, err)
expectedXML := `
@@ -111,7 +111,7 @@ func TestAddNewAdaptationSetVideoWriteToString(t *testing.T) {
`
- require.Equal(t, expectedXML, xmlStr)
+ require.EqualString(t, expectedXML, xmlStr)
}
func TestAddNewAdaptationSetSubtitleWriteToString(t *testing.T) {
@@ -120,7 +120,7 @@ func TestAddNewAdaptationSetSubtitleWriteToString(t *testing.T) {
_, _ = m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG)
xmlStr, err := m.WriteToString()
- require.Nil(t, err)
+ require.NoError(t, err)
expectedXML := `
@@ -128,7 +128,7 @@ func TestAddNewAdaptationSetSubtitleWriteToString(t *testing.T) {
`
- require.Equal(t, expectedXML, xmlStr)
+ require.EqualString(t, expectedXML, xmlStr)
}
func TestExampleAddNewPeriod(t *testing.T) {
@@ -154,7 +154,7 @@ func TestExampleAddNewPeriod(t *testing.T) {
_, _ = as.SetNewSegmentTemplate(1968, "$RepresentationID$/audio-2.mp4", "$RepresentationID$/audio-2/seg-$Number$.m4f", 0, 1000)
xmlStr, err := m.WriteToString()
- require.Nil(t, err)
+ require.NoError(t, err)
testfixtures.CompareFixture(t, "fixtures/newperiod.mpd", xmlStr)
}
@@ -198,7 +198,7 @@ func TestFullLiveProfileWriteToString(t *testing.T) {
m := LiveProfile()
require.NotNil(t, m)
xmlStr, err := m.WriteToString()
- require.Nil(t, err)
+ require.NoError(t, err)
testfixtures.CompareFixture(t, "fixtures/live_profile.mpd", xmlStr)
}
@@ -208,9 +208,9 @@ func TestFullLiveProfileWriteToFile(t *testing.T) {
err := m.WriteToFile("test_live.mpd")
xmlStr := testfixtures.LoadFixture("test_live.mpd")
expectedXML := testfixtures.LoadFixture("fixtures/live_profile.mpd")
- require.Equal(t, expectedXML, xmlStr)
+ require.EqualString(t, expectedXML, xmlStr)
defer os.Remove("test_live.mpd")
- require.Nil(t, err)
+ require.NoError(t, err)
}
func LiveProfileDynamic() *MPD {
@@ -254,7 +254,7 @@ func TestFullLiveProfileDynamicWriteToString(t *testing.T) {
m := LiveProfileDynamic()
require.NotNil(t, m)
xmlStr, err := m.WriteToString()
- require.Nil(t, err)
+ require.NoError(t, err)
testfixtures.CompareFixture(t, "fixtures/live_profile_dynamic.mpd", xmlStr)
}
@@ -264,9 +264,9 @@ func TestFullLiveProfileDynamicWriteToFile(t *testing.T) {
err := m.WriteToFile("test_live_dynamic.mpd")
xmlStr := testfixtures.LoadFixture("test_live_dynamic.mpd")
expectedXML := testfixtures.LoadFixture("fixtures/live_profile_dynamic.mpd")
- require.Equal(t, expectedXML, xmlStr)
+ require.EqualString(t, expectedXML, xmlStr)
defer os.Remove("test_live_dynamic.mpd")
- require.Nil(t, err)
+ require.NoError(t, err)
}
func HbbTVProfile() *MPD {
@@ -309,7 +309,7 @@ func TestFullHbbTVProfileWriteToString(t *testing.T) {
m := HbbTVProfile()
require.NotNil(t, m)
xmlStr, err := m.WriteToString()
- require.Nil(t, err)
+ require.NoError(t, err)
testfixtures.CompareFixture(t, "fixtures/hbbtv_profile.mpd", xmlStr)
}
@@ -320,7 +320,7 @@ func TestFullHbbTVProfileWriteToFile(t *testing.T) {
xmlStr := testfixtures.LoadFixture("test_hbbtv.mpd")
testfixtures.CompareFixture(t, "fixtures/hbbtv_profile.mpd", xmlStr)
defer os.Remove("test_hbbtv.mpd")
- require.Nil(t, err)
+ require.NoError(t, err)
}
func OnDemandProfile() *MPD {
@@ -361,7 +361,7 @@ func TestFullOnDemandProfileWriteToString(t *testing.T) {
m := OnDemandProfile()
require.NotNil(t, m)
xmlStr, err := m.WriteToString()
- require.Nil(t, err)
+ require.NoError(t, err)
testfixtures.CompareFixture(t, "fixtures/ondemand_profile.mpd", xmlStr)
}
@@ -372,7 +372,7 @@ func TestFullOnDemandProfileWriteToFile(t *testing.T) {
xmlStr := testfixtures.LoadFixture("test-ondemand.mpd")
testfixtures.CompareFixture(t, "fixtures/ondemand_profile.mpd", xmlStr)
defer os.Remove("test-ondemand.mpd")
- require.Nil(t, err)
+ require.NoError(t, err)
}
func TestWriteToFileInvalidFilePath(t *testing.T) {
diff --git a/mpd/mpd_test.go b/mpd/mpd_test.go
index ef51966..6e9ae87 100644
--- a/mpd/mpd_test.go
+++ b/mpd/mpd_test.go
@@ -2,11 +2,10 @@ package mpd
import (
"encoding/base64"
- "encoding/xml"
"testing"
- "github.com/stretchr/testify/require"
. "github.com/zencoder/go-dash/helpers/ptrs"
+ "github.com/zencoder/go-dash/helpers/require"
)
const (
@@ -14,9 +13,6 @@ const (
VALID_MIN_BUFFER_TIME string = "PT1.97S"
VALID_AVAILABILITY_START_TIME string = "1970-01-01T00:00:00Z"
VALID_MINIMUM_UPDATE_PERIOD string = "PT5S"
- VALID_MIME_TYPE_VIDEO string = "video/mp4"
- VALID_MIME_TYPE_AUDIO string = "audio/mp4"
- VALID_MIME_TYPE_SUBTITLE_VTT string = "text/vtt"
VALID_SCAN_TYPE string = "progressive"
VALID_SEGMENT_ALIGNMENT bool = true
VALID_START_WITH_SAP int64 = 1
@@ -39,9 +35,6 @@ const (
VALID_BASE_URL_VIDEO string = "800k/output-video-1.mp4"
VALID_INDEX_RANGE string = "629-756"
VALID_INIT_RANGE string = "0-628"
- VALID_DEFAULT_KID_HEX string = "08e367028f33436ca5dd60ffe5571e60"
- VALID_DEFAULT_KID string = "08e36702-8f33-436c-a5dd-60ffe5571e60"
- VALID_PLAYREADY_XMLNS string = "urn:microsoft:playready"
VALID_PLAYREADY_PRO string = "BgIAAAEAAQD8ATwAVwBSAE0ASABFAEEARABFAFIAIAB4AG0AbABuAHMAPQAiAGgAdAB0AHAAOgAvAC8AcwBjAGgAZQBtAGEAcwAuAG0AaQBjAHIAbwBzAG8AZgB0AC4AYwBvAG0ALwBEAFIATQAvADIAMAAwADcALwAwADMALwBQAGwAYQB5AFIAZQBhAGQAeQBIAGUAYQBkAGUAcgAiACAAdgBlAHIAcwBpAG8AbgA9ACIANAAuADAALgAwAC4AMAAiAD4APABEAEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4ATAA5AFcAOQBXAGsAcABWAEsAawArADQAMABHAEgAMwBZAFUASgBSAFYAUQA9AD0APAAvAEsASQBEAD4APABDAEgARQBDAEsAUwBVAE0APgBJAEsAegBZADIASABaAEwAQQBsAEkAPQA8AC8AQwBIAEUAQwBLAFMAVQBNAD4APAAvAEQAQQBUAEEAPgA8AC8AVwBSAE0ASABFAEEARABFAFIAPgA="
VALID_WV_HEADER string = "CAESEFq91S9VSk8quNBh92FCUVUaCGNhc3RsYWJzIhhXcjNWTDFWS1R5cTQwR0gzWVVKUlZRPT0yB2RlZmF1bHQ="
VALID_SUBTITLE_BANDWIDTH int64 = 256
@@ -64,7 +57,13 @@ func TestNewMPDLive(t *testing.T) {
period: &Period{},
Periods: []*Period{{}},
}
- require.Equal(t, expectedMPD, m)
+
+ expectedString, err := expectedMPD.WriteToString()
+ require.NoError(t, err)
+ actualString, err := m.WriteToString()
+ require.NoError(t, err)
+
+ require.EqualString(t, expectedString, actualString)
}
func TestNewDynamicMPDLive(t *testing.T) {
@@ -83,7 +82,13 @@ func TestNewDynamicMPDLive(t *testing.T) {
period: &Period{},
Periods: []*Period{{}},
}
- require.Equal(t, expectedMPD, m)
+
+ expectedString, err := expectedMPD.WriteToString()
+ require.NoError(t, err)
+ actualString, err := m.WriteToString()
+ require.NoError(t, err)
+
+ require.EqualString(t, expectedString, actualString)
}
func TestContentProtection_ImplementsInterface(t *testing.T) {
@@ -124,7 +129,13 @@ func TestNewMPDLiveWithBaseURLInMPD(t *testing.T) {
Periods: []*Period{{}},
BaseURL: VALID_BASE_URL_VIDEO,
}
- require.Equal(t, expectedMPD, m)
+
+ expectedString, err := expectedMPD.WriteToString()
+ require.NoError(t, err)
+ actualString, err := m.WriteToString()
+ require.NoError(t, err)
+
+ require.EqualString(t, expectedString, actualString)
}
func TestNewMPDLiveWithBaseURLInPeriod(t *testing.T) {
@@ -143,7 +154,13 @@ func TestNewMPDLiveWithBaseURLInPeriod(t *testing.T) {
period: period,
Periods: []*Period{period},
}
- require.Equal(t, expectedMPD, m)
+
+ expectedString, err := expectedMPD.WriteToString()
+ require.NoError(t, err)
+ actualString, err := m.WriteToString()
+ require.NoError(t, err)
+
+ require.EqualString(t, expectedString, actualString)
}
func TestNewMPDHbbTV(t *testing.T) {
@@ -158,7 +175,13 @@ func TestNewMPDHbbTV(t *testing.T) {
period: &Period{},
Periods: []*Period{{}},
}
- require.Equal(t, expectedMPD, m)
+
+ expectedString, err := expectedMPD.WriteToString()
+ require.NoError(t, err)
+ actualString, err := m.WriteToString()
+ require.NoError(t, err)
+
+ require.EqualString(t, expectedString, actualString)
}
func TestNewMPDOnDemand(t *testing.T) {
@@ -173,174 +196,13 @@ func TestNewMPDOnDemand(t *testing.T) {
period: &Period{},
Periods: []*Period{{}},
}
- require.Equal(t, expectedMPD, m)
-}
-
-func TestAddNewAdaptationSetAudio(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
- as, err := m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG)
- require.NotNil(t, as)
- require.Nil(t, err)
- expectedAS := &AdaptationSet{
- SegmentAlignment: Boolptr(VALID_SEGMENT_ALIGNMENT),
- Lang: Strptr(VALID_LANG),
- ID: nil,
- CommonAttributesAndElements: CommonAttributesAndElements{
- Profiles: nil,
- Width: nil,
- Height: nil,
- Sar: nil,
- FrameRate: nil,
- AudioSamplingRate: nil,
- MimeType: Strptr(VALID_MIME_TYPE_AUDIO),
- SegmentProfiles: nil,
- Codecs: nil,
- MaximumSAPPeriod: nil,
- StartWithSAP: Int64ptr(VALID_START_WITH_SAP),
- MaxPlayoutRate: nil,
- ScanType: nil,
- FramePacking: nil,
- AudioChannelConfiguration: nil,
- ContentProtection: nil,
- EssentialProperty: nil,
- SupplementalProperty: nil,
- InbandEventStream: nil,
- },
- }
- require.Equal(t, expectedAS, as)
-}
-
-func TestAddNewAdaptationSetAudioWithID(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
- as, err := m.AddNewAdaptationSetAudioWithID("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG)
- require.NotNil(t, as)
- require.Nil(t, err)
- expectedAS := &AdaptationSet{
- SegmentAlignment: Boolptr(VALID_SEGMENT_ALIGNMENT),
- Lang: Strptr(VALID_LANG),
- ID: Strptr("7357"),
- CommonAttributesAndElements: CommonAttributesAndElements{
- Profiles: nil,
- Width: nil,
- Height: nil,
- Sar: nil,
- FrameRate: nil,
- AudioSamplingRate: nil,
- MimeType: Strptr(VALID_MIME_TYPE_AUDIO),
- SegmentProfiles: nil,
- Codecs: nil,
- MaximumSAPPeriod: nil,
- StartWithSAP: Int64ptr(VALID_START_WITH_SAP),
- MaxPlayoutRate: nil,
- ScanType: nil,
- FramePacking: nil,
- AudioChannelConfiguration: nil,
- ContentProtection: nil,
- EssentialProperty: nil,
- SupplementalProperty: nil,
- InbandEventStream: nil,
- },
- }
- require.Equal(t, expectedAS, as)
-}
-
-func TestAddNewAdaptationSetVideo(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
-
- as, err := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
- require.NotNil(t, as)
- require.Nil(t, err)
- expectedAS := &AdaptationSet{
- SegmentAlignment: Boolptr(VALID_SEGMENT_ALIGNMENT),
- ID: nil,
- CommonAttributesAndElements: CommonAttributesAndElements{
- Profiles: nil,
- Width: nil,
- Height: nil,
- Sar: nil,
- FrameRate: nil,
- AudioSamplingRate: nil,
- MimeType: Strptr(VALID_MIME_TYPE_VIDEO),
- SegmentProfiles: nil,
- Codecs: nil,
- MaximumSAPPeriod: nil,
- StartWithSAP: Int64ptr(VALID_START_WITH_SAP),
- MaxPlayoutRate: nil,
- ScanType: Strptr(VALID_SCAN_TYPE),
- FramePacking: nil,
- AudioChannelConfiguration: nil,
- ContentProtection: nil,
- EssentialProperty: nil,
- SupplementalProperty: nil,
- InbandEventStream: nil,
- },
- }
- require.Equal(t, expectedAS, as)
-}
-
-func TestAddNewAdaptationSetVideoWithID(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
-
- as, err := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
- require.NotNil(t, as)
- require.Nil(t, err)
- expectedAS := &AdaptationSet{
- SegmentAlignment: Boolptr(VALID_SEGMENT_ALIGNMENT),
- ID: Strptr("7357"),
- CommonAttributesAndElements: CommonAttributesAndElements{
- Profiles: nil,
- Width: nil,
- Height: nil,
- Sar: nil,
- FrameRate: nil,
- AudioSamplingRate: nil,
- MimeType: Strptr(VALID_MIME_TYPE_VIDEO),
- SegmentProfiles: nil,
- Codecs: nil,
- MaximumSAPPeriod: nil,
- StartWithSAP: Int64ptr(VALID_START_WITH_SAP),
- MaxPlayoutRate: nil,
- ScanType: Strptr(VALID_SCAN_TYPE),
- FramePacking: nil,
- AudioChannelConfiguration: nil,
- ContentProtection: nil,
- EssentialProperty: nil,
- SupplementalProperty: nil,
- InbandEventStream: nil,
- },
- }
- require.Equal(t, expectedAS, as)
-}
-
-func TestAddNewAdaptationSetSubtitle(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
-
- as, err := m.AddNewAdaptationSetSubtitle(DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG)
- require.NotNil(t, as)
- require.Nil(t, err)
- expectedAS := &AdaptationSet{
- Lang: Strptr(VALID_LANG),
- CommonAttributesAndElements: CommonAttributesAndElements{
- MimeType: Strptr(VALID_MIME_TYPE_SUBTITLE_VTT),
- },
- }
- require.Equal(t, expectedAS, as)
-}
-func TestAddNewAdaptationSetSubtitleWithID(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
+ expectedString, err := expectedMPD.WriteToString()
+ require.NoError(t, err)
+ actualString, err := m.WriteToString()
+ require.NoError(t, err)
- as, err := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG)
- require.NotNil(t, as)
- require.Nil(t, err)
- expectedAS := &AdaptationSet{
- ID: Strptr("7357"),
- Lang: Strptr(VALID_LANG),
- CommonAttributesAndElements: CommonAttributesAndElements{
- MimeType: Strptr(VALID_MIME_TYPE_SUBTITLE_VTT),
- },
- }
- require.Equal(t, expectedAS, as)
+ require.EqualString(t, expectedString, actualString)
}
func TestAddAdaptationSetErrorNil(t *testing.T) {
@@ -348,41 +210,7 @@ func TestAddAdaptationSetErrorNil(t *testing.T) {
err := m.period.addAdaptationSet(nil)
require.NotNil(t, err)
- require.Equal(t, ErrAdaptationSetNil, err)
-}
-
-func TestAddNewContentProtectionRoot_Legacy(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
- s, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
-
- cp, err := s.AddNewContentProtectionRootLegacyUUID(VALID_DEFAULT_KID_HEX)
- require.Nil(t, err)
- require.NotNil(t, cp)
- expectedCP := &CENCContentProtection{
- DefaultKID: Strptr("08e36702-8f33-436c-a5dd60ffe5571e60"),
- Value: Strptr(CONTENT_PROTECTION_ROOT_VALUE),
- }
- expectedCP.SchemeIDURI = Strptr(CONTENT_PROTECTION_ROOT_SCHEME_ID_URI)
- expectedCP.XMLNS = Strptr(CENC_XMLNS)
-
- require.Equal(t, expectedCP, cp)
-}
-
-func TestAddNewContentProtectionRoot(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
- s, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
-
- cp, err := s.AddNewContentProtectionRoot(VALID_DEFAULT_KID_HEX)
- require.Nil(t, err)
- require.NotNil(t, cp)
- expectedCP := &CENCContentProtection{
- DefaultKID: Strptr(VALID_DEFAULT_KID),
- Value: Strptr(CONTENT_PROTECTION_ROOT_VALUE),
- }
- expectedCP.SchemeIDURI = Strptr(CONTENT_PROTECTION_ROOT_SCHEME_ID_URI)
- expectedCP.XMLNS = Strptr(CENC_XMLNS)
-
- require.Equal(t, expectedCP, cp)
+ require.EqualErr(t, ErrAdaptationSetNil, err)
}
type TestProprietaryContentProtection struct {
@@ -393,28 +221,13 @@ type TestProprietaryContentProtection struct {
func (s *TestProprietaryContentProtection) ContentProtected() {}
-func TestAddNewContentProtection_Proprietary(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
- as, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
-
- cp := &ContentProtectionMarshal{
- SchemeIDURI: Strptr(CONTENT_PROTECTION_ROOT_SCHEME_ID_URI),
- }
-
- pcp := &TestProprietaryContentProtection{*cp, "foo", "bar"}
- x, _ := xml.Marshal(pcp)
- require.Equal(t, ``, string(x))
- _ = as.AddContentProtection(pcp)
- require.Equal(t, as.ContentProtection, []ContentProtectioner{pcp})
-}
-
func TestAddNewContentProtectionRootErrorInvalidLengthDefaultKID(t *testing.T) {
m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
s, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
cp, err := s.AddNewContentProtectionRoot("invalidkid")
require.NotNil(t, err)
- require.Equal(t, ErrInvalidDefaultKID, err)
+ require.EqualErr(t, ErrInvalidDefaultKID, err)
require.Nil(t, cp)
}
@@ -424,131 +237,36 @@ func TestAddNewContentProtectionRootErrorEmptyDefaultKID(t *testing.T) {
cp, err := s.AddNewContentProtectionRoot("")
require.NotNil(t, err)
- require.Equal(t, ErrInvalidDefaultKID, err)
+ require.EqualErr(t, ErrInvalidDefaultKID, err)
require.Nil(t, cp)
}
-func TestAddNewContentProtectionSchemeWidevineWithPSSH(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
- s, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
-
- cp, err := s.AddNewContentProtectionSchemeWidevineWithPSSH(getValidWVHeaderBytes())
- require.Nil(t, err)
- require.NotNil(t, cp)
- expectedCP := &WidevineContentProtection{
- PSSH: Strptr("AAAAYXBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAEEIARIQWr3VL1VKTyq40GH3YUJRVRoIY2FzdGxhYnMiGFdyM1ZMMVZLVHlxNDBHSDNZVUpSVlE9PTIHZGVmYXVsdA=="),
- }
- expectedCP.SchemeIDURI = Strptr(CONTENT_PROTECTION_WIDEVINE_SCHEME_ID)
- expectedCP.XMLNS = Strptr(CENC_XMLNS)
- require.Equal(t, expectedCP, cp)
-}
-
-func TestAddNewContentProtectionSchemeWidevine(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
- s, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
-
- cp, err := s.AddNewContentProtectionSchemeWidevine()
- require.Nil(t, err)
- require.NotNil(t, cp)
- expectedCP := &WidevineContentProtection{}
- expectedCP.SchemeIDURI = Strptr(CONTENT_PROTECTION_WIDEVINE_SCHEME_ID)
- require.Equal(t, expectedCP, cp)
-}
-
func TestAddNewContentProtectionSchemePlayreadyErrorEmptyPRO(t *testing.T) {
m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
s, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
cp, err := s.AddNewContentProtectionSchemePlayready("")
require.NotNil(t, err)
- require.Equal(t, ErrPROEmpty, err)
+ require.EqualErr(t, ErrPROEmpty, err)
require.Nil(t, cp)
}
-func TestAddNewContentProtectionSchemePlayready(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
- s, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
-
- cp, err := s.AddNewContentProtectionSchemePlayready(VALID_PLAYREADY_PRO)
- require.Nil(t, err)
- require.NotNil(t, cp)
- expectedCP := &PlayreadyContentProtection{
- PlayreadyXMLNS: Strptr(VALID_PLAYREADY_XMLNS),
- PRO: Strptr(VALID_PLAYREADY_PRO),
- }
- expectedCP.SchemeIDURI = Strptr(CONTENT_PROTECTION_PLAYREADY_SCHEME_ID)
-
- require.Equal(t, expectedCP, cp)
-}
-
func TestAddNewContentProtectionSchemePlayreadyV10ErrorEmptyPRO(t *testing.T) {
m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
s, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
cp, err := s.AddNewContentProtectionSchemePlayreadyV10("")
require.NotNil(t, err)
- require.Equal(t, ErrPROEmpty, err)
+ require.EqualErr(t, ErrPROEmpty, err)
require.Nil(t, cp)
}
-func TestAddNewContentProtectionSchemePlayreadyV10(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
- s, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
-
- cp, err := s.AddNewContentProtectionSchemePlayreadyV10(VALID_PLAYREADY_PRO)
- require.Nil(t, err)
- require.NotNil(t, cp)
- expectedCP := &PlayreadyContentProtection{
- PlayreadyXMLNS: Strptr(VALID_PLAYREADY_XMLNS),
- PRO: Strptr(VALID_PLAYREADY_PRO),
- }
- expectedCP.SchemeIDURI = Strptr(CONTENT_PROTECTION_PLAYREADY_SCHEME_V10_ID)
-
- require.Equal(t, expectedCP, cp)
-}
-
-func TestAddNewContentProtectionSchemePlayreadyWithPSSH(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
- s, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
-
- cp, err := s.AddNewContentProtectionSchemePlayreadyWithPSSH(VALID_PLAYREADY_PRO)
- require.Nil(t, err)
- require.NotNil(t, cp)
- expectedCP := &PlayreadyContentProtection{
- PlayreadyXMLNS: Strptr(VALID_PLAYREADY_XMLNS),
- PRO: Strptr(VALID_PLAYREADY_PRO),
- }
- expectedCP.SchemeIDURI = Strptr(CONTENT_PROTECTION_PLAYREADY_SCHEME_ID)
- expectedCP.XMLNS = Strptr(CENC_XMLNS)
- expectedCP.PSSH = Strptr("AAACJnBzc2gAAAAAmgTweZhAQoarkuZb4IhflQAAAgYGAgAAAQABAPwBPABXAFIATQBIAEUAQQBEAEUAUgAgAHgAbQBsAG4AcwA9ACIAaAB0AHQAcAA6AC8ALwBzAGMAaABlAG0AYQBzAC4AbQBpAGMAcgBvAHMAbwBmAHQALgBjAG8AbQAvAEQAUgBNAC8AMgAwADAANwAvADAAMwAvAFAAbABhAHkAUgBlAGEAZAB5AEgAZQBhAGQAZQByACIAIAB2AGUAcgBzAGkAbwBuAD0AIgA0AC4AMAAuADAALgAwACIAPgA8AEQAQQBUAEEAPgA8AFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBFAFkATABFAE4APgAxADYAPAAvAEsARQBZAEwARQBOAD4APABBAEwARwBJAEQAPgBBAEUAUwBDAFQAUgA8AC8AQQBMAEcASQBEAD4APAAvAFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBJAEQAPgBMADkAVwA5AFcAawBwAFYASwBrACsANAAwAEcASAAzAFkAVQBKAFIAVgBRAD0APQA8AC8ASwBJAEQAPgA8AEMASABFAEMASwBTAFUATQA+AEkASwB6AFkAMgBIAFoATABBAGwASQA9ADwALwBDAEgARQBDAEsAUwBVAE0APgA8AC8ARABBAFQAQQA+ADwALwBXAFIATQBIAEUAQQBEAEUAUgA+AA==")
-
- require.Equal(t, expectedCP, cp)
-}
-
-func TestAddNewContentProtectionSchemePlayreadyV10WithPSSH(t *testing.T) {
- m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
- s, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
-
- cp, err := s.AddNewContentProtectionSchemePlayreadyV10WithPSSH(VALID_PLAYREADY_PRO)
- require.Nil(t, err)
- require.NotNil(t, cp)
- expectedCP := &PlayreadyContentProtection{
- PlayreadyXMLNS: Strptr(VALID_PLAYREADY_XMLNS),
- PRO: Strptr(VALID_PLAYREADY_PRO),
- }
- expectedCP.SchemeIDURI = Strptr(CONTENT_PROTECTION_PLAYREADY_SCHEME_V10_ID)
- expectedCP.XMLNS = Strptr(CENC_XMLNS)
- expectedCP.PSSH = Strptr("AAACJnBzc2gAAAAAefAEmkCYhkKrkuZb4IhflQAAAgYGAgAAAQABAPwBPABXAFIATQBIAEUAQQBEAEUAUgAgAHgAbQBsAG4AcwA9ACIAaAB0AHQAcAA6AC8ALwBzAGMAaABlAG0AYQBzAC4AbQBpAGMAcgBvAHMAbwBmAHQALgBjAG8AbQAvAEQAUgBNAC8AMgAwADAANwAvADAAMwAvAFAAbABhAHkAUgBlAGEAZAB5AEgAZQBhAGQAZQByACIAIAB2AGUAcgBzAGkAbwBuAD0AIgA0AC4AMAAuADAALgAwACIAPgA8AEQAQQBUAEEAPgA8AFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBFAFkATABFAE4APgAxADYAPAAvAEsARQBZAEwARQBOAD4APABBAEwARwBJAEQAPgBBAEUAUwBDAFQAUgA8AC8AQQBMAEcASQBEAD4APAAvAFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBJAEQAPgBMADkAVwA5AFcAawBwAFYASwBrACsANAAwAEcASAAzAFkAVQBKAFIAVgBRAD0APQA8AC8ASwBJAEQAPgA8AEMASABFAEMASwBTAFUATQA+AEkASwB6AFkAMgBIAFoATABBAGwASQA9ADwALwBDAEgARQBDAEsAUwBVAE0APgA8AC8ARABBAFQAQQA+ADwALwBXAFIATQBIAEUAQQBEAEUAUgA+AA==")
-
- require.Equal(t, expectedCP, cp)
-}
-
func TestSetNewSegmentTemplate(t *testing.T) {
m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
audioAS, _ := m.AddNewAdaptationSetAudioWithID("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG)
st, err := audioAS.SetNewSegmentTemplate(VALID_DURATION, VALID_INIT_PATH_AUDIO, VALID_MEDIA_PATH_AUDIO, VALID_START_NUMBER, VALID_TIMESCALE)
require.NotNil(t, st)
- require.Nil(t, err)
+ require.NoError(t, err)
}
func TestSetNewSegmentTemplateErrorNoDASHProfile(t *testing.T) {
@@ -563,7 +281,7 @@ func TestSetNewSegmentTemplateErrorNoDASHProfile(t *testing.T) {
audioAS, _ := m.AddNewAdaptationSetAudioWithID("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG)
_, _ = audioAS.SetNewSegmentTemplate(VALID_DURATION, VALID_INIT_PATH_AUDIO, VALID_MEDIA_PATH_AUDIO, VALID_START_NUMBER, VALID_TIMESCALE)
err := m.Validate()
- require.Equal(t, ErrNoDASHProfileSet, err)
+ require.EqualErr(t, ErrNoDASHProfileSet, err)
}
func TestAddRepresentationAudio(t *testing.T) {
@@ -573,7 +291,7 @@ func TestAddRepresentationAudio(t *testing.T) {
r, err := audioAS.AddNewRepresentationAudio(VALID_AUDIO_SAMPLE_RATE, VALID_AUDIO_BITRATE, VALID_AUDIO_CODEC, VALID_AUDIO_ID)
require.NotNil(t, r)
- require.Nil(t, err)
+ require.NoError(t, err)
}
func TestAddAudioChannelConfiguration(t *testing.T) {
@@ -585,7 +303,7 @@ func TestAddAudioChannelConfiguration(t *testing.T) {
acc, err := r.AddNewAudioChannelConfiguration(AUDIO_CHANNEL_CONFIGURATION_MPEG_DASH, "2")
require.NotNil(t, acc)
- require.Nil(t, err)
+ require.NoError(t, err)
}
func TestAddRepresentationVideo(t *testing.T) {
@@ -595,7 +313,7 @@ func TestAddRepresentationVideo(t *testing.T) {
r, err := videoAS.AddNewRepresentationVideo(VALID_VIDEO_BITRATE, VALID_VIDEO_CODEC, VALID_VIDEO_ID, VALID_VIDEO_FRAMERATE, VALID_VIDEO_WIDTH, VALID_VIDEO_HEIGHT)
require.NotNil(t, r)
- require.Nil(t, err)
+ require.NoError(t, err)
}
func TestAddRepresentationSubtitle(t *testing.T) {
@@ -606,7 +324,7 @@ func TestAddRepresentationSubtitle(t *testing.T) {
r, err := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID)
require.NotNil(t, r)
- require.Nil(t, err)
+ require.NoError(t, err)
}
func TestAddRepresentationErrorNil(t *testing.T) {
@@ -615,7 +333,7 @@ func TestAddRepresentationErrorNil(t *testing.T) {
err := videoAS.addRepresentation(nil)
require.NotNil(t, err)
- require.Equal(t, ErrRepresentationNil, err)
+ require.EqualErr(t, ErrRepresentationNil, err)
}
func TestAddRole(t *testing.T) {
@@ -625,7 +343,7 @@ func TestAddRole(t *testing.T) {
r, err := audioAS.AddNewRole("urn:mpeg:dash:role:2011", VALID_ROLE)
require.NotNil(t, r)
- require.Nil(t, err)
+ require.NoError(t, err)
}
func TestSetSegmentTemplateErrorNil(t *testing.T) {
@@ -633,7 +351,7 @@ func TestSetSegmentTemplateErrorNil(t *testing.T) {
audioAS, _ := m.AddNewAdaptationSetAudioWithID("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG)
err := audioAS.setSegmentTemplate(nil)
require.NotNil(t, err)
- require.Equal(t, ErrSegmentTemplateNil, err)
+ require.EqualErr(t, ErrSegmentTemplateNil, err)
}
func TestSetNewBaseURLVideo(t *testing.T) {
@@ -644,7 +362,7 @@ func TestSetNewBaseURLVideo(t *testing.T) {
err := r.SetNewBaseURL(VALID_BASE_URL_VIDEO)
- require.Nil(t, err)
+ require.NoError(t, err)
}
func TestSetNewBaseURLSubtitle(t *testing.T) {
@@ -655,7 +373,7 @@ func TestSetNewBaseURLSubtitle(t *testing.T) {
err := r.SetNewBaseURL(VALID_SUBTITLE_URL)
- require.Nil(t, err)
+ require.NoError(t, err)
}
func TestSetNewBaseURLErrorNoDASHProfile(t *testing.T) {
@@ -675,7 +393,7 @@ func TestSetNewBaseURLErrorNoDASHProfile(t *testing.T) {
err := m.Validate()
require.NotNil(t, err)
- require.Equal(t, ErrNoDASHProfileSet, err)
+ require.EqualErr(t, ErrNoDASHProfileSet, err)
}
func TestSetNewBaseURLErrorEmpty(t *testing.T) {
@@ -687,7 +405,7 @@ func TestSetNewBaseURLErrorEmpty(t *testing.T) {
err := r.SetNewBaseURL("")
require.NotNil(t, err)
- require.Equal(t, ErrBaseURLEmpty, err)
+ require.EqualErr(t, ErrBaseURLEmpty, err)
}
func TestSetNewSegmentBase(t *testing.T) {
@@ -698,7 +416,7 @@ func TestSetNewSegmentBase(t *testing.T) {
sb, err := r.AddNewSegmentBase(VALID_INDEX_RANGE, VALID_INIT_RANGE)
require.NotNil(t, sb)
- require.Nil(t, err)
+ require.NoError(t, err)
}
func TestSetNewSegmentBaseErrorNoDASHProfile(t *testing.T) {
@@ -717,7 +435,7 @@ func TestSetNewSegmentBaseErrorNoDASHProfile(t *testing.T) {
_, _ = r.AddNewSegmentBase(VALID_INDEX_RANGE, VALID_INIT_RANGE)
err := m.Validate()
- require.Equal(t, ErrNoDASHProfileSet, err)
+ require.EqualErr(t, ErrNoDASHProfileSet, err)
}
func TestSetSegmentBaseErrorNil(t *testing.T) {
@@ -728,7 +446,7 @@ func TestSetSegmentBaseErrorNil(t *testing.T) {
err := r.setSegmentBase(nil)
require.NotNil(t, err)
- require.Equal(t, ErrSegmentBaseNil, err)
+ require.EqualErr(t, ErrSegmentBaseNil, err)
}
func getValidWVHeaderBytes() []byte {
diff --git a/mpd/pssh_test.go b/mpd/pssh_test.go
index 76b5262..27e29a1 100644
--- a/mpd/pssh_test.go
+++ b/mpd/pssh_test.go
@@ -3,9 +3,8 @@ package mpd
import (
"encoding/base64"
"encoding/hex"
+ "github.com/zencoder/go-dash/helpers/require"
"testing"
-
- "github.com/stretchr/testify/require"
)
func TestMakePSSHBox_Widevine(t *testing.T) {
@@ -27,7 +26,7 @@ func TestMakePSSHBox_Widevine(t *testing.T) {
psshBox, err := makePSSHBox(wvSystemID, payload)
require.NoError(t, err)
- require.Equal(t, expectedPSSH, psshBox)
+ require.EqualString(t, string(expectedPSSH), string(psshBox))
}
func TestMakePSSHBox_Playready(t *testing.T) {
@@ -50,15 +49,15 @@ func TestMakePSSHBox_Playready(t *testing.T) {
psshBox, err := makePSSHBox(wvSystemID, payload)
require.NoError(t, err)
- require.Equal(t, expectedPSSH, psshBox)
+ require.EqualString(t, string(expectedPSSH), string(psshBox))
}
func TestMakePSSHBox_BadSystemID(t *testing.T) {
_, err := makePSSHBox([]byte("meaningless byte array"), nil)
- require.Error(t, err)
+ require.EqualError(t, err, "SystemID must be 16 bytes, was: 22")
}
func TestMakePSSHBox_NilSystemID(t *testing.T) {
_, err := makePSSHBox(nil, nil)
- require.Error(t, err)
+ require.EqualError(t, err, "SystemID must be 16 bytes, was: 0")
}
diff --git a/mpd/segment_list_test.go b/mpd/segment_list_test.go
index 5f4ae14..b8482ac 100644
--- a/mpd/segment_list_test.go
+++ b/mpd/segment_list_test.go
@@ -3,8 +3,8 @@ package mpd
import (
"testing"
- "github.com/stretchr/testify/require"
"github.com/zencoder/go-dash/helpers/ptrs"
+ "github.com/zencoder/go-dash/helpers/require"
"github.com/zencoder/go-dash/helpers/testfixtures"
)
@@ -19,32 +19,40 @@ func TestSegmentListDeserialization(t *testing.T) {
xml := testfixtures.LoadFixture("fixtures/segment_list.mpd")
m, err := ReadFromString(xml)
- require.Nil(t, err)
+ require.NoError(t, err)
if err == nil {
expected := getSegmentListMPD()
- require.Equal(t, expected.Periods[0].BaseURL, m.Periods[0].BaseURL)
+ require.EqualString(t, expected.Periods[0].BaseURL, m.Periods[0].BaseURL)
expectedAudioSegList := expected.Periods[0].AdaptationSets[0].Representations[0].SegmentList
audioSegList := m.Periods[0].AdaptationSets[0].Representations[0].SegmentList
- require.Equal(t, expectedAudioSegList.Timescale, audioSegList.Timescale)
- require.Equal(t, expectedAudioSegList.Duration, audioSegList.Duration)
- require.Equal(t, expectedAudioSegList.Initialization, audioSegList.Initialization)
+ require.EqualUInt32(t, *expectedAudioSegList.Timescale, *audioSegList.Timescale)
+ require.EqualUInt32(t, *expectedAudioSegList.Duration, *audioSegList.Duration)
+ require.EqualStringPtr(t, expectedAudioSegList.Initialization.SourceURL, audioSegList.Initialization.SourceURL)
+ require.EqualStringPtr(t, expectedAudioSegList.Initialization.Range, audioSegList.Initialization.Range)
for i := range expectedAudioSegList.SegmentURLs {
- require.Equal(t, expectedAudioSegList.SegmentURLs[i], audioSegList.SegmentURLs[i])
+ require.EqualStringPtr(t, expectedAudioSegList.SegmentURLs[i].Media, audioSegList.SegmentURLs[i].Media)
+ require.EqualStringPtr(t, expectedAudioSegList.SegmentURLs[i].Index, audioSegList.SegmentURLs[i].Index)
+ require.EqualStringPtr(t, expectedAudioSegList.SegmentURLs[i].IndexRange, audioSegList.SegmentURLs[i].IndexRange)
+ require.EqualStringPtr(t, expectedAudioSegList.SegmentURLs[i].MediaRange, audioSegList.SegmentURLs[i].MediaRange)
}
expectedVideoSegList := expected.Periods[0].AdaptationSets[1].Representations[0].SegmentList
videoSegList := m.Periods[0].AdaptationSets[1].Representations[0].SegmentList
- require.Equal(t, expectedVideoSegList.Timescale, videoSegList.Timescale)
- require.Equal(t, expectedVideoSegList.Duration, videoSegList.Duration)
- require.Equal(t, expectedVideoSegList.Initialization, videoSegList.Initialization)
+ require.EqualUInt32(t, *expectedVideoSegList.Timescale, *videoSegList.Timescale)
+ require.EqualUInt32(t, *expectedVideoSegList.Duration, *videoSegList.Duration)
+ require.EqualStringPtr(t, expectedVideoSegList.Initialization.Range, videoSegList.Initialization.Range)
+ require.EqualStringPtr(t, expectedVideoSegList.Initialization.SourceURL, videoSegList.Initialization.SourceURL)
for i := range expectedVideoSegList.SegmentURLs {
- require.Equal(t, expectedVideoSegList.SegmentURLs[i], videoSegList.SegmentURLs[i])
+ require.EqualStringPtr(t, expectedVideoSegList.SegmentURLs[i].Media, videoSegList.SegmentURLs[i].Media)
+ require.EqualStringPtr(t, expectedVideoSegList.SegmentURLs[i].Index, videoSegList.SegmentURLs[i].Index)
+ require.EqualStringPtr(t, expectedVideoSegList.SegmentURLs[i].IndexRange, videoSegList.SegmentURLs[i].IndexRange)
+ require.EqualStringPtr(t, expectedVideoSegList.SegmentURLs[i].MediaRange, videoSegList.SegmentURLs[i].MediaRange)
}
}
}
diff --git a/mpd/segment_timeline_test.go b/mpd/segment_timeline_test.go
index 5522c58..41f2719 100644
--- a/mpd/segment_timeline_test.go
+++ b/mpd/segment_timeline_test.go
@@ -5,8 +5,8 @@ import (
"testing"
"time"
- "github.com/stretchr/testify/require"
"github.com/zencoder/go-dash/helpers/ptrs"
+ "github.com/zencoder/go-dash/helpers/require"
"github.com/zencoder/go-dash/helpers/testfixtures"
)
@@ -32,20 +32,24 @@ func TestSegmentTimelineDeserialization(t *testing.T) {
m, err := ReadFromString(xml)
require.NoError(t, err)
expected := getSegmentTimelineMPD()
- require.Equal(t, expected.Periods[0].BaseURL, m.Periods[0].BaseURL)
+ require.EqualString(t, expected.Periods[0].BaseURL, m.Periods[0].BaseURL)
expectedAudioSegTimeline := expected.Periods[0].AdaptationSets[0].Representations[0].SegmentTemplate.SegmentTimeline
audioSegTimeline := m.Periods[0].AdaptationSets[0].Representations[0].SegmentTemplate.SegmentTimeline
for i := range expectedAudioSegTimeline.Segments {
- require.Equal(t, expectedAudioSegTimeline.Segments[i], audioSegTimeline.Segments[i])
+ require.EqualUInt64(t, expectedAudioSegTimeline.Segments[i].Duration, audioSegTimeline.Segments[i].Duration)
+ require.EqualUInt64Ptr(t, expectedAudioSegTimeline.Segments[i].StartTime, audioSegTimeline.Segments[i].StartTime)
+ require.EqualIntPtr(t, expectedAudioSegTimeline.Segments[i].RepeatCount, audioSegTimeline.Segments[i].RepeatCount)
}
expectedVideoSegTimeline := expected.Periods[0].AdaptationSets[1].Representations[0].SegmentTemplate.SegmentTimeline
videoSegTimeline := m.Periods[0].AdaptationSets[1].Representations[0].SegmentTemplate.SegmentTimeline
for i := range expectedVideoSegTimeline.Segments {
- require.Equal(t, expectedVideoSegTimeline.Segments[i], videoSegTimeline.Segments[i])
+ require.EqualUInt64(t, expectedVideoSegTimeline.Segments[i].Duration, videoSegTimeline.Segments[i].Duration)
+ require.EqualUInt64Ptr(t, expectedVideoSegTimeline.Segments[i].StartTime, videoSegTimeline.Segments[i].StartTime)
+ require.EqualIntPtr(t, expectedVideoSegTimeline.Segments[i].RepeatCount, videoSegTimeline.Segments[i].RepeatCount)
}
}