mirror of
https://github.com/pion/webrtc.git
synced 2025-10-26 00:30:35 +08:00
Add a bunch of default basic unittests to boost coverage
This commit is contained in:
committed by
Sean DuBois
parent
cbea80026d
commit
a08b5d51cf
@@ -16,6 +16,19 @@ const (
|
|||||||
RTCBundlePolicyMaxBundle
|
RTCBundlePolicyMaxBundle
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func NewRTCBundlePolicy(raw string) (unknown RTCBundlePolicy) {
|
||||||
|
switch raw {
|
||||||
|
case "balanced":
|
||||||
|
return RTCBundlePolicyBalanced
|
||||||
|
case "max-compat":
|
||||||
|
return RTCBundlePolicyMaxCompat
|
||||||
|
case "max-bundle":
|
||||||
|
return RTCBundlePolicyMaxBundle
|
||||||
|
default:
|
||||||
|
return unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t RTCBundlePolicy) String() string {
|
func (t RTCBundlePolicy) String() string {
|
||||||
switch t {
|
switch t {
|
||||||
case RTCBundlePolicyBalanced:
|
case RTCBundlePolicyBalanced:
|
||||||
|
|||||||
46
rtcbundlepolicy_test.go
Normal file
46
rtcbundlepolicy_test.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package webrtc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewRTCBundlePolicy(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
policyString string
|
||||||
|
expectedPolicy RTCBundlePolicy
|
||||||
|
}{
|
||||||
|
{"unknown", RTCBundlePolicy(Unknown)},
|
||||||
|
{"balanced", RTCBundlePolicyBalanced},
|
||||||
|
{"max-compat", RTCBundlePolicyMaxCompat},
|
||||||
|
{"max-bundle", RTCBundlePolicyMaxBundle},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, testCase := range testCases {
|
||||||
|
assert.Equal(t,
|
||||||
|
NewRTCBundlePolicy(testCase.policyString),
|
||||||
|
testCase.expectedPolicy,
|
||||||
|
"testCase: %d %v", i, testCase,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRTCBundlePolicy_String(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
policy RTCBundlePolicy
|
||||||
|
expectedString string
|
||||||
|
}{
|
||||||
|
{RTCBundlePolicy(Unknown), "unknown"},
|
||||||
|
{RTCBundlePolicyBalanced, "balanced"},
|
||||||
|
{RTCBundlePolicyMaxCompat, "max-compat"},
|
||||||
|
{RTCBundlePolicyMaxBundle, "max-bundle"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, testCase := range testCases {
|
||||||
|
assert.Equal(t,
|
||||||
|
testCase.policy.String(),
|
||||||
|
testCase.expectedString,
|
||||||
|
"testCase: %d %v", i, testCase,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,13 +3,13 @@ package webrtc
|
|||||||
import (
|
import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"time"
|
|
||||||
"crypto/x509/pkix"
|
"crypto/x509/pkix"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"crypto/rand"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RTCCertificate represents a x509Cert used to authenticate WebRTC communications.
|
// RTCCertificate represents a x509Cert used to authenticate WebRTC communications.
|
||||||
|
|||||||
@@ -10,6 +10,17 @@ const (
|
|||||||
RTCIceCredentialTypeOauth
|
RTCIceCredentialTypeOauth
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func NewRTCIceCredentialType(raw string) (unknown RTCIceCredentialType) {
|
||||||
|
switch raw {
|
||||||
|
case "password":
|
||||||
|
return RTCIceCredentialTypePassword
|
||||||
|
case "oauth":
|
||||||
|
return RTCIceCredentialTypeOauth
|
||||||
|
default:
|
||||||
|
return unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t RTCIceCredentialType) String() string {
|
func (t RTCIceCredentialType) String() string {
|
||||||
switch t {
|
switch t {
|
||||||
case RTCIceCredentialTypePassword:
|
case RTCIceCredentialTypePassword:
|
||||||
|
|||||||
44
rtcicecredentialtype_test.go
Normal file
44
rtcicecredentialtype_test.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package webrtc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewRTCIceCredentialType(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
credentialTypeString string
|
||||||
|
expectedCredentialType RTCIceCredentialType
|
||||||
|
}{
|
||||||
|
{"unknown", RTCIceCredentialType(Unknown)},
|
||||||
|
{"password", RTCIceCredentialTypePassword},
|
||||||
|
{"oauth", RTCIceCredentialTypeOauth},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, testCase := range testCases {
|
||||||
|
assert.Equal(t,
|
||||||
|
NewRTCIceCredentialType(testCase.credentialTypeString),
|
||||||
|
testCase.expectedCredentialType,
|
||||||
|
"testCase: %d %v", i, testCase,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRTCIceCredentialType_String(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
credentialType RTCIceCredentialType
|
||||||
|
expectedString string
|
||||||
|
}{
|
||||||
|
{RTCIceCredentialType(Unknown), "unknown"},
|
||||||
|
{RTCIceCredentialTypePassword, "password"},
|
||||||
|
{RTCIceCredentialTypeOauth, "oauth"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, testCase := range testCases {
|
||||||
|
assert.Equal(t,
|
||||||
|
testCase.credentialType.String(),
|
||||||
|
testCase.expectedString,
|
||||||
|
"testCase: %d %v", i, testCase,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,17 @@ const (
|
|||||||
RTCIceTransportPolicyAll
|
RTCIceTransportPolicyAll
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func NewRTCIceTransportPolicy(raw string) (unknown RTCIceTransportPolicy) {
|
||||||
|
switch raw {
|
||||||
|
case "relay":
|
||||||
|
return RTCIceTransportPolicyRelay
|
||||||
|
case "all":
|
||||||
|
return RTCIceTransportPolicyAll
|
||||||
|
default:
|
||||||
|
return unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t RTCIceTransportPolicy) String() string {
|
func (t RTCIceTransportPolicy) String() string {
|
||||||
switch t {
|
switch t {
|
||||||
case RTCIceTransportPolicyRelay:
|
case RTCIceTransportPolicyRelay:
|
||||||
|
|||||||
44
rtcicetransportpolicy_test.go
Normal file
44
rtcicetransportpolicy_test.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package webrtc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewRTCIceTransportPolicy(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
policyString string
|
||||||
|
expectedPolicy RTCIceTransportPolicy
|
||||||
|
}{
|
||||||
|
{"unknown", RTCIceTransportPolicy(Unknown)},
|
||||||
|
{"relay", RTCIceTransportPolicyRelay},
|
||||||
|
{"all", RTCIceTransportPolicyAll},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, testCase := range testCases {
|
||||||
|
assert.Equal(t,
|
||||||
|
NewRTCIceTransportPolicy(testCase.policyString),
|
||||||
|
testCase.expectedPolicy,
|
||||||
|
"testCase: %d %v", i, testCase,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRTCIceTransportPolicy_String(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
policy RTCIceTransportPolicy
|
||||||
|
expectedString string
|
||||||
|
}{
|
||||||
|
{RTCIceTransportPolicy(Unknown), "unknown"},
|
||||||
|
{RTCIceTransportPolicyRelay, "relay"},
|
||||||
|
{RTCIceTransportPolicyAll, "all"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, testCase := range testCases {
|
||||||
|
assert.Equal(t,
|
||||||
|
testCase.policy.String(),
|
||||||
|
testCase.expectedString,
|
||||||
|
"testCase: %d %v", i, testCase,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -123,7 +123,7 @@ func (pc *RTCPeerConnection) initConfiguration(configuration RTCConfiguration) e
|
|||||||
if !x509Cert.Expires().IsZero() && now.After(x509Cert.Expires()) {
|
if !x509Cert.Expires().IsZero() && now.After(x509Cert.Expires()) {
|
||||||
return &InvalidAccessError{ErrCertificateExpired}
|
return &InvalidAccessError{ErrCertificateExpired}
|
||||||
}
|
}
|
||||||
pc.configuration.Certificates = append(pc.configuration.Certificates, x509Cert, )
|
pc.configuration.Certificates = append(pc.configuration.Certificates, x509Cert)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
sk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import (
|
|||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"time"
|
"github.com/stretchr/testify/assert"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
|
|||||||
@@ -19,6 +19,21 @@ const (
|
|||||||
RTCSdpTypeRollback
|
RTCSdpTypeRollback
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func NewRTCSdpType(raw string) (unknown RTCSdpType) {
|
||||||
|
switch raw {
|
||||||
|
case "offer":
|
||||||
|
return RTCSdpTypeOffer
|
||||||
|
case "pranswer":
|
||||||
|
return RTCSdpTypePranswer
|
||||||
|
case "answer":
|
||||||
|
return RTCSdpTypeAnswer
|
||||||
|
case "rollback":
|
||||||
|
return RTCSdpTypeRollback
|
||||||
|
default:
|
||||||
|
return unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t RTCSdpType) String() string {
|
func (t RTCSdpType) String() string {
|
||||||
switch t {
|
switch t {
|
||||||
case RTCSdpTypeOffer:
|
case RTCSdpTypeOffer:
|
||||||
|
|||||||
48
rtcsdptype_test.go
Normal file
48
rtcsdptype_test.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package webrtc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewRTCSdpType(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
sdpTypeString string
|
||||||
|
expectedSdpType RTCSdpType
|
||||||
|
}{
|
||||||
|
{"unknown", RTCSdpType(Unknown)},
|
||||||
|
{"offer", RTCSdpTypeOffer},
|
||||||
|
{"pranswer", RTCSdpTypePranswer},
|
||||||
|
{"answer", RTCSdpTypeAnswer},
|
||||||
|
{"rollback", RTCSdpTypeRollback},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, testCase := range testCases {
|
||||||
|
assert.Equal(t,
|
||||||
|
NewRTCSdpType(testCase.sdpTypeString),
|
||||||
|
testCase.expectedSdpType,
|
||||||
|
"testCase: %d %v", i, testCase,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRTCSdpType_String(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
sdpType RTCSdpType
|
||||||
|
expectedString string
|
||||||
|
}{
|
||||||
|
{RTCSdpType(Unknown), "unknown"},
|
||||||
|
{RTCSdpTypeOffer, "offer"},
|
||||||
|
{RTCSdpTypePranswer, "pranswer"},
|
||||||
|
{RTCSdpTypeAnswer, "answer"},
|
||||||
|
{RTCSdpTypeRollback, "rollback"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, testCase := range testCases {
|
||||||
|
assert.Equal(t,
|
||||||
|
testCase.sdpType.String(),
|
||||||
|
testCase.expectedString,
|
||||||
|
"testCase: %d %v", i, testCase,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package webrtc
|
package webrtc
|
||||||
|
|
||||||
// RTCSignalingState indicates the state of the offer/answer process
|
// RTCSignalingState indicates the policy of the offer/answer process
|
||||||
type RTCSignalingState int
|
type RTCSignalingState int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -20,11 +20,15 @@ func TestNewRTCSignalingState(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
assert.Equal(t, NewRTCSignalingState(testCase.stateString), testCase.expectedState, "testCase: %d %v", i, testCase)
|
assert.Equal(t,
|
||||||
|
NewRTCSignalingState(testCase.stateString),
|
||||||
|
testCase.expectedState,
|
||||||
|
"testCase: %d %v", i, testCase,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestString(t *testing.T) {
|
func TestRTCSignalingState_String(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
state RTCSignalingState
|
state RTCSignalingState
|
||||||
expectedString string
|
expectedString string
|
||||||
@@ -39,6 +43,10 @@ func TestString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
assert.Equal(t, testCase.state.String(), testCase.expectedString, "testCase: %d %v", i, testCase)
|
assert.Equal(t,
|
||||||
|
testCase.state.String(),
|
||||||
|
testCase.expectedString,
|
||||||
|
"testCase: %d %v", i, testCase,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user