1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-04-25 06:59:13 -04:00

more json test cases

This commit is contained in:
Darien Raymond
2016-02-04 10:43:04 +00:00
parent be57f48bb3
commit c74bcc9c50
4 changed files with 68 additions and 8 deletions

View File

@@ -35,3 +35,12 @@ func TestDomainParsing(t *testing.T) {
assert.Bool(address.Address.IsDomain()).IsTrue()
assert.StringLiteral(address.Address.Domain()).Equals("v2ray.com")
}
func TestInvalidJson(t *testing.T) {
v2testing.Current(t)
rawJson := "1234"
var address AddressJson
err := json.Unmarshal([]byte(rawJson), &address)
assert.Error(err).IsNotNil()
}

View File

@@ -30,3 +30,11 @@ func TestStringNetworkList(t *testing.T) {
assert.Bool(list.HasNetwork(Network("tcp"))).IsTrue()
assert.Bool(list.HasNetwork(Network("udp"))).IsFalse()
}
func TestInvalidJson(t *testing.T) {
v2testing.Current(t)
var list NetworkList
err := json.Unmarshal([]byte("0"), &list)
assert.Error(err).IsNotNil()
}

View File

@@ -0,0 +1,43 @@
// +build json
package protocol_test
import (
"encoding/json"
"testing"
. "github.com/v2ray/v2ray-core/common/protocol"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestUserParsing(t *testing.T) {
v2testing.Current(t)
user := new(User)
err := json.Unmarshal([]byte(`{
"id": "96edb838-6d68-42ef-a933-25f7ac3a9d09",
"email": "love@v2ray.com",
"level": 1,
"alterId": 100
}`), user)
assert.Error(err).IsNil()
assert.String(user.ID).Equals("96edb838-6d68-42ef-a933-25f7ac3a9d09")
assert.Byte(byte(user.Level)).Equals(1)
}
func TestInvalidUserJson(t *testing.T) {
v2testing.Current(t)
user := new(User)
err := json.Unmarshal([]byte(`{"id": 1234}`), user)
assert.Error(err).IsNotNil()
}
func TestInvalidIdJson(t *testing.T) {
v2testing.Current(t)
user := new(User)
err := json.Unmarshal([]byte(`{"id": "1234"}`), user)
assert.Error(err).IsNotNil()
}