1 Star 0 Fork 1

niuja/webrtc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
icecredentialtype_test.go 2.30 KB
一键复制 编辑 原始数据 按行查看 历史
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))
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/niuja/webrtc.git
git@gitee.com:niuja/webrtc.git
niuja
webrtc
webrtc
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385