1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-18 02:16:10 -05:00
v2fly/common/protocol/user_json_test.go

35 lines
688 B
Go
Raw Normal View History

2016-02-04 05:43:04 -05:00
// +build json
package protocol_test
import (
"encoding/json"
"testing"
2016-08-20 14:55:45 -04:00
. "v2ray.com/core/common/protocol"
"v2ray.com/core/testing/assert"
2016-02-04 05:43:04 -05:00
)
func TestUserParsing(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2016-02-04 05:43:04 -05:00
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.Byte(byte(user.Level)).Equals(1)
2016-07-25 11:36:24 -04:00
assert.String(user.Email).Equals("love@v2ray.com")
2016-02-04 05:43:04 -05:00
}
func TestInvalidUserJson(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2016-02-04 05:43:04 -05:00
user := new(User)
2016-07-25 11:36:24 -04:00
err := json.Unmarshal([]byte(`{"email": 1234}`), user)
2016-02-04 05:43:04 -05:00
assert.Error(err).IsNotNil()
}