2016-02-04 05:43:04 -05:00
|
|
|
// +build json
|
|
|
|
|
|
|
|
package protocol_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/v2ray/v2ray-core/common/protocol"
|
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
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-05-28 07:44:11 -04:00
|
|
|
|
|
|
|
account, ok := user.Account.(*VMessAccount)
|
|
|
|
assert.Bool(ok).IsTrue()
|
|
|
|
assert.String(account.ID.String()).Equals("96edb838-6d68-42ef-a933-25f7ac3a9d09")
|
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)
|
|
|
|
err := json.Unmarshal([]byte(`{"id": 1234}`), user)
|
|
|
|
assert.Error(err).IsNotNil()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidIdJson(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": "1234"}`), user)
|
|
|
|
assert.Error(err).IsNotNil()
|
|
|
|
}
|