commit 1fbc9b17002d187c9cbeceaf8f63ac8226fdc52d
parent c03db991d2ab3a966afec47eae05d4da9353efea
Author: Oliver Lowe <o@olowe.co>
Date: Fri, 10 May 2024 16:12:14 +1000
internal/scte35: print clear splice descriptor diffs
As recommended Go Testing By Example
https://www.youtube.com/watch?v=X4rxi9jStLo
Diffstat:
1 file changed, 62 insertions(+), 0 deletions(-)
diff --git a/internal/scte35/splice_info_test.go b/internal/scte35/splice_info_test.go
@@ -2,7 +2,9 @@ package scte35
import (
"encoding/base64"
+ "fmt"
"reflect"
+ "strings"
"testing"
)
@@ -15,6 +17,65 @@ func TestPackTier(t *testing.T) {
}
}
+func diffInfo(a, b SpliceInfo) string {
+ buf := &strings.Builder{}
+ if a.SAPType != b.SAPType {
+ fmt.Fprintf(buf, "SAP type = %s, %s\n", a.SAPType, b.SAPType)
+ }
+ if a.EncryptionAlgorithm != b.EncryptionAlgorithm {
+ fmt.Fprintln(buf, "cipher = ", a.EncryptionAlgorithm, b.EncryptionAlgorithm)
+ }
+ if a.PTSAdjustment != b.PTSAdjustment {
+ fmt.Fprintln(buf, "pts adjustment = ", a.PTSAdjustment, b.PTSAdjustment)
+ }
+ if a.CWIndex != b.CWIndex {
+ fmt.Fprintln(buf, "cw index differs")
+ fmt.Fprintf(buf, "< %v\n> %v\n", a.CWIndex, b.CWIndex)
+ }
+ if a.Tier != b.Tier {
+ fmt.Fprintln(buf, "tier differs")
+ fmt.Fprintf(buf, "< %#x\n> %#x\n", a.Tier, b.Tier)
+ }
+ if !reflect.DeepEqual(a.Command, b.Command) {
+ fmt.Fprintln(buf, "command = ", *a.Command, *b.Command)
+ }
+ if !reflect.DeepEqual(a.Descriptors, b.Descriptors) {
+ if len(a.Descriptors) != len(b.Descriptors) {
+ fmt.Fprintf(buf, "descriptor count = %d, %d\n", len(a.Descriptors), len(b.Descriptors))
+ fmt.Fprintf(buf, "descriptors = %+v, %+v\n", a.Descriptors, b.Descriptors)
+ } else {
+ fmt.Fprintln(buf, "descriptors differ")
+ for i := range a.Descriptors {
+ fmt.Fprintln(buf, "descriptor", i)
+ buf.WriteString(diffDescriptors(a.Descriptors[i], b.Descriptors[i]))
+ }
+ }
+ }
+ if a.CRC32 != b.CRC32 {
+ fmt.Fprintln(buf, "crc32 = ", a.CRC32, b.CRC32)
+ }
+ return buf.String()
+}
+
+func diffDescriptors(a, b SpliceDescriptor) string {
+ buf := &strings.Builder{}
+ if a.Tag() != b.Tag() {
+ fmt.Fprintln(buf, "tag differs")
+ fmt.Fprintln(buf, "<", a.Tag())
+ fmt.Fprintln(buf, ">", b.Tag())
+ }
+ if a.ID() != b.ID() {
+ fmt.Fprintln(buf, "id differs")
+ fmt.Fprintf(buf, "< %d\n> %d\n", a.ID(), b.ID())
+ }
+ if !reflect.DeepEqual(a.Data(), b.Data()) {
+ fmt.Fprintln(buf, "data differs")
+ fmt.Fprintf(buf, "< %v\n> %v\n", a.Data(), b.Data())
+ }
+ fmt.Fprintf(buf, "< %T %v\n> %T %v\n", a, a, b, b)
+ return buf.String()
+}
+
/*
func TestReadSpliceInfo(t *testing.T) {
var tsig uint64 = 0x072bd0050
@@ -90,6 +151,7 @@ func TestDecodeSpliceInfo(t *testing.T) {
}
if !reflect.DeepEqual(tt.want, info) {
t.Errorf("decode splice info: want %+v, got %+v", tt.want, info)
+ t.Log(diffInfo(tt.want, *info))
}
})
}