streaming

Media streaming and broadcast systems in Go
Log | Files | Refs | README | LICENSE

commit fd089add456294f2b1ac042ab8f58324f8cc31d0
parent 35dba76d750bb75f1becd09a646fa639926888b9
Author: Oliver Lowe <o@olowe.co>
Date:   Fri,  5 Jul 2024 12:02:11 +1000

sdp: test parsing bandwidth field

From this we found a bug when parsing bandwidth info with a missing
bandwidth type.

Diffstat:
Msdp/sdp.go | 3+++
Msdp/sdp_test.go | 22++++++++++++++++------
2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/sdp/sdp.go b/sdp/sdp.go @@ -209,6 +209,9 @@ func parseBandwidth(s string) (Bandwidth, error) { return Bandwidth{}, fmt.Errorf("missing %s separator", ":") } // TODO(otl): check bandwith type is actually one specified in section 5.8. + if t == "" { + return Bandwidth{}, fmt.Errorf("missing bandwidth type") + } kbps, err := strconv.Atoi(b) if err != nil { return Bandwidth{}, fmt.Errorf("parse bitrate: %w", err) diff --git a/sdp/sdp_test.go b/sdp/sdp_test.go @@ -72,17 +72,27 @@ func TestReadSession(t *testing.T) { } func TestBandwidth(t *testing.T) { - var cases = []struct{ - name string - s string - err bool + var cases = []struct { + name string + s string + wantErr bool }{ {"conference total", "CT:2048", false}, {"app specific", "AS:87654321", false}, {"custom", "69something:12345", false}, {"missing modifier", ":12345", true}, - {"missing separator" "CT2048", true}, + {"missing separator", "CT2048", true}, } for _, tt := range cases { - t.Errorf("TODO ", tt.name) + t.Run(tt.name, func(t *testing.T) { + _, err := parseBandwidth(tt.s) + if err != nil && tt.wantErr { + // no worries, we got what we expected + } else if err != nil && !tt.wantErr { + t.Errorf("parseBandwidth(%q): unexpected error %v", tt.s, err) + } else if err == nil && tt.wantErr { + t.Errorf("parseBandwidth(%q): unexpected nil error", tt.s) + } + }) } +}