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