base: improve coverage

This commit is contained in:
aler9
2021-05-29 19:30:12 +02:00
parent 4f595a1d0d
commit 14393985fe
2 changed files with 39 additions and 18 deletions

View File

@@ -11,14 +11,15 @@ const (
StreamProtocolTCP
)
var streamProtocolLabels = map[StreamProtocol]string{
StreamProtocolUDP: "UDP",
StreamProtocolTCP: "TCP",
}
// String implements fmt.Stringer.
func (sp StreamProtocol) String() string {
switch sp {
case StreamProtocolUDP:
return "UDP"
case StreamProtocolTCP:
return "TCP"
if l, ok := streamProtocolLabels[sp]; ok {
return l
}
return "unknown"
}
@@ -34,14 +35,15 @@ const (
StreamDeliveryMulticast
)
var streamDeliveryLabels = map[StreamDelivery]string{
StreamDeliveryUnicast: "unicast",
StreamDeliveryMulticast: "multicast",
}
// String implements fmt.Stringer.
func (sc StreamDelivery) String() string {
switch sc {
case StreamDeliveryUnicast:
return "unicast"
case StreamDeliveryMulticast:
return "multicast"
if l, ok := streamDeliveryLabels[sc]; ok {
return l
}
return "unknown"
}
@@ -57,14 +59,15 @@ const (
StreamTypeRTCP
)
var streamTypeLabels = map[StreamType]string{
StreamTypeRTP: "RTP",
StreamTypeRTCP: "RTCP",
}
// String implements fmt.Stringer
func (st StreamType) String() string {
switch st {
case StreamTypeRTP:
return "RTP"
case StreamTypeRTCP:
return "RTCP"
if l, ok := streamTypeLabels[st]; ok {
return l
}
return "unknown"
}

18
pkg/base/defs_test.go Normal file
View File

@@ -0,0 +1,18 @@
package base
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestDefs(t *testing.T) {
require.NotEqual(t, "unknown", StreamProtocolUDP.String())
require.Equal(t, "unknown", StreamProtocol(4).String())
require.NotEqual(t, "unknown", StreamDeliveryUnicast.String())
require.Equal(t, "unknown", StreamDelivery(4).String())
require.NotEqual(t, "unknown", StreamTypeRTP.String())
require.Equal(t, "unknown", StreamType(4).String())
}