代码拉取完成,页面将自动刷新
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 {
tpe, err := newICECredentialType(testCase.credentialTypeString)
assert.NoError(t, err)
assert.Equal(t,
testCase.expectedCredentialType, tpe,
"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 {
tpe, err := newICECredentialType(testCase.expectedString)
assert.NoError(t, err)
assert.Equal(t,
tpe, 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))
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。