commit 7641bd0d9aeb83e2e02c11d1e22b0699ba00bc49
parent 7d3701c071389c1c8b805d6e2b2585bacbe9ce59
Author: Oliver Lowe <o@olowe.co>
Date: Tue, 30 Apr 2024 23:07:05 +1000
internal/scte35: remove testify module
At this final stage pulling in an entire module only saved 17 lines of
code.
Diffstat:
3 files changed, 47 insertions(+), 41 deletions(-)
diff --git a/go.mod b/go.mod
@@ -4,12 +4,5 @@ go 1.19
require (
github.com/bamiaux/iobit v0.0.0-20170418073505-498159a04883
- github.com/stretchr/testify v1.9.0
golang.org/x/text v0.14.0
)
-
-require (
- github.com/davecgh/go-spew v1.1.1 // indirect
- github.com/pmezard/go-difflib v1.0.0 // indirect
- gopkg.in/yaml.v3 v3.0.1 // indirect
-)
diff --git a/go.sum b/go.sum
@@ -1,14 +1,4 @@
github.com/bamiaux/iobit v0.0.0-20170418073505-498159a04883 h1:XNtOMwxmV2PI/vuTHDZnFzGIFNUh8MK73q7+Kna7AXs=
github.com/bamiaux/iobit v0.0.0-20170418073505-498159a04883/go.mod h1:9IjZnSQGh45J46HHS45pxuMJ6WFTtSXbaX0FoHDvxh8=
-github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
-github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
-github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/internal/scte35/scte35_test.go b/internal/scte35/scte35_test.go
@@ -22,9 +22,6 @@ import (
"encoding/xml"
"errors"
"testing"
-
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
)
func TestDecodeBase64(t *testing.T) {
@@ -600,24 +597,37 @@ func TestDecodeBase64(t *testing.T) {
}
// test encode/decode XML
encodedXML := toXML(sis)
- assert.Equal(t, toXML(&c.expected), encodedXML)
- decodedXML := SpliceInfoSection{}
- assert.NoError(t, xml.Unmarshal([]byte(encodedXML), &decodedXML))
+ if toXML(&c.expected) != encodedXML {
+ t.Fatalf("encode xml: want %s, got %s", toXML(&c.expected), encodedXML)
+ }
+ var info SpliceInfoSection
+ if err := xml.Unmarshal([]byte(encodedXML), &info); err != nil {
+ t.Error(err)
+ }
// legacy 35's produce an "updated" binary so will not match
if !c.legacy {
- assert.Equal(t, c.binary, decodedXML.Base64())
+ if c.binary != info.Base64() {
+ t.Errorf("re-encode to binary: want %s, got %s", c.binary, info.Base64())
+ }
}
// test encode/decode JSON
encodedJSON := toJSON(sis)
- assert.Equal(t, toJSON(&c.expected), encodedJSON)
- decodedJSON := SpliceInfoSection{}
- require.NoError(t, json.Unmarshal([]byte(encodedJSON), &decodedJSON))
+ if toJSON(&c.expected) != encodedJSON {
+ t.Fatalf("encode to json: want %s, got %s", toJSON(&c.expected), encodedJSON)
+ }
+ info = SpliceInfoSection{}
+
+ if err := json.Unmarshal([]byte(encodedJSON), &info); err != nil {
+ t.Fatal(err)
+ }
// legacy 35's produce an "updated" binary so will not match
if !c.legacy {
- assert.Equal(t, c.binary, decodedJSON.Base64())
+ if c.binary != info.Base64() {
+ t.Errorf("re-encode to binary: want %s, got %s", c.binary, info.Base64())
+ }
}
})
}
@@ -716,24 +726,30 @@ func TestDecodeHex(t *testing.T) {
for k, c := range cases {
t.Run(k, func(t *testing.T) {
- // decode the binary
sis, err := DecodeHex(c.hex)
- require.Equal(t, c.err, err)
- if err != nil {
- return
+ if !errors.Is(c.err, err) {
+ t.Fatalf("want error %v, got %v", c.err, err)
}
// test encode/decode XML
encodedXML := toXML(sis)
- assert.Equal(t, toXML(&c.expected), encodedXML)
- decodedXML := SpliceInfoSection{}
- assert.NoError(t, xml.Unmarshal([]byte(encodedXML), &decodedXML))
+ if toXML(&c.expected) != encodedXML {
+ t.Fatalf("encode xml: want %s, got %s", toXML(&c.expected), encodedXML)
+ }
+ var info SpliceInfoSection
+ if err := xml.Unmarshal([]byte(encodedXML), &info); err != nil {
+ t.Errorf("unmarshal back from xml: %v", err)
+ }
// test encode/decode JSON
encodedJSON := toJSON(sis)
- assert.Equal(t, toJSON(&c.expected), encodedJSON)
- decodedJSON := SpliceInfoSection{}
- require.NoError(t, json.Unmarshal([]byte(encodedJSON), &decodedJSON))
+ if toJSON(&c.expected) != encodedJSON {
+ t.Fatalf("encode json: want %s, got %s", toJSON(&c.expected), encodedJSON)
+ }
+ info = SpliceInfoSection{}
+ if err := json.Unmarshal([]byte(encodedJSON), &info); err != nil {
+ t.Errorf("unmarshal from json back into splice info: %v", err)
+ }
})
}
}
@@ -754,8 +770,12 @@ func TestEncodeWithAlignmentStuffing(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
sis, err := DecodeBase64(c.binary)
- require.NoError(t, err)
- require.Equal(t, c.binary, sis.Base64())
+ if err != nil {
+ t.Fatal(err)
+ }
+ if c.binary != sis.Base64() {
+ t.Errorf("base64 re-encode: want %s, got %s", c.binary, sis.Base64())
+ }
})
}
}
@@ -766,7 +786,10 @@ func TestTicksToDuration(t *testing.T) {
max := 61 * TicksPerSecond
for i := min; i < max; i++ {
d := TicksToDuration(uint64(i))
- require.Equal(t, i, int(DurationToTicks(d)))
+ ticks := DurationToTicks(d)
+ if i != int(ticks) {
+ t.Errorf("DurationToTicks(%s) = %d, want %d", d, ticks, i)
+ }
}
}