예제 #1
0
func soUserShouldEqual(actual, expect *models.User) {
	So(actual.Uid, ShouldEqual, expect.Uid)

	So(utils.AreStringEquals(actual.Phone, expect.Phone), ShouldBeTrue)
	So(utils.IsEmptyString(actual.WeiXin), ShouldBeTrue)
	So(utils.IsEmptyString(actual.WeiBo), ShouldBeTrue)
	So(utils.IsEmptyString(actual.QQ), ShouldBeTrue)

	So(actual.Nickname, ShouldEqual, expect.Nickname)
	So(actual.QQNickName, ShouldEqual, expect.QQNickName)
	So(actual.WeiBoNickName, ShouldEqual, expect.WeiBoNickName)
	So(actual.WeiXinNickName, ShouldEqual, expect.WeiXinNickName)
	So(actual.Gender, ShouldEqual, expect.Gender)
	So(actual.Avatar, ShouldEqual, expect.Avatar)

	So(actual.CreateAt, ShouldEqual, expect.CreateAt)
	So(actual.UpdateAt, ShouldEqual, expect.UpdateAt)
}
예제 #2
0
func TestUserSerial(t *testing.T) {
	user := models.User{Id: 1, Nickname: "Piasy", Uid: 1905378617}
	data, err := json.Marshal(user)

	assert.Nil(t, err)

	var fromJson models.User
	err = json.Unmarshal(data, &fromJson)

	assert.Nil(t, err)

	assert.Empty(t, fromJson.Id)
	assert.Empty(t, fromJson.Password)
	assert.True(t, utils.IsEmptyString(fromJson.Phone))

	assert.Equal(t, user.Nickname, fromJson.Nickname)
	assert.Equal(t, user.Uid, fromJson.Uid)
}