mirror of
https://github.com/pion/webrtc.git
synced 2025-09-27 03:25:58 +08:00
101 lines
2.2 KiB
Go
101 lines
2.2 KiB
Go
package webrtc
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewICECredentialType(t *testing.T) {
|
|
testCases := []struct {
|
|
credentialTypeString string
|
|
expectedCredentialType ICECredentialType
|
|
}{
|
|
{"password", ICECredentialTypePassword},
|
|
{"oauth", ICECredentialTypeOauth},
|
|
}
|
|
|
|
for i, testCase := range testCases {
|
|
assert.Equal(t,
|
|
testCase.expectedCredentialType,
|
|
newICECredentialType(testCase.credentialTypeString),
|
|
"testCase: %d %v", i, testCase,
|
|
)
|
|
}
|
|
}
|
|
|
|
func TestICECredentialType_String(t *testing.T) {
|
|
testCases := []struct {
|
|
credentialType ICECredentialType
|
|
expectedString string
|
|
}{
|
|
{ICECredentialTypePassword, "password"},
|
|
{ICECredentialTypeOauth, "oauth"},
|
|
}
|
|
|
|
for i, testCase := range testCases {
|
|
assert.Equal(t,
|
|
testCase.expectedString,
|
|
testCase.credentialType.String(),
|
|
"testCase: %d %v", i, testCase,
|
|
)
|
|
}
|
|
}
|
|
|
|
func TestICECredentialType_new(t *testing.T) {
|
|
testCases := []struct {
|
|
credentialType ICECredentialType
|
|
expectedString string
|
|
}{
|
|
{ICECredentialTypePassword, "password"},
|
|
{ICECredentialTypeOauth, "oauth"},
|
|
}
|
|
|
|
for i, testCase := range testCases {
|
|
assert.Equal(t,
|
|
newICECredentialType(testCase.expectedString),
|
|
testCase.credentialType,
|
|
"testCase: %d %v", i, testCase,
|
|
)
|
|
}
|
|
}
|
|
|
|
func TestICECredentialType_Json(t *testing.T) {
|
|
testCases := []struct {
|
|
credentialType ICECredentialType
|
|
jsonRepresentation []byte
|
|
}{
|
|
{ICECredentialTypePassword, []byte("\"password\"")},
|
|
{ICECredentialTypeOauth, []byte("\"oauth\"")},
|
|
}
|
|
|
|
for i, testCase := range testCases {
|
|
m, err := json.Marshal(testCase.credentialType)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t,
|
|
testCase.jsonRepresentation,
|
|
m,
|
|
"Marshal testCase: %d %v", i, testCase,
|
|
)
|
|
var ct ICECredentialType
|
|
err = json.Unmarshal(testCase.jsonRepresentation, &ct)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t,
|
|
testCase.credentialType,
|
|
ct,
|
|
"Unmarshal testCase: %d %v", i, testCase,
|
|
)
|
|
}
|
|
|
|
{
|
|
ct := ICECredentialType(1000)
|
|
err := json.Unmarshal([]byte("\"invalid\""), &ct)
|
|
assert.Error(t, err)
|
|
assert.Equal(t, ct, ICECredentialType(1000))
|
|
err = json.Unmarshal([]byte("\"invalid"), &ct)
|
|
assert.Error(t, err)
|
|
assert.Equal(t, ct, ICECredentialType(1000))
|
|
}
|
|
}
|