Пример #1
0
func TestUpdateAccount(t *testing.T) {
	testAcc = &Account{
		ID:         testAcc.ID,
		OpenID:     testAcc.OpenID,
		Mobile:     "138" + types.NewUUID()[:8],
		Email:      types.NewUUID()[:6] + "@test.com",
		Password:   "******",
		LoginToken: types.NewUUID(),

		Nick:      "Nick" + types.NewUUID()[:6],
		Gender:    1,
		Avatar:    "http://image.a.com/" + types.NewUUID(),
		Birthdate: "1980-03-11",
		CreatedAt: testAcc.CreatedAt,
		Status:    3,
	}

	if err := UpdateAccount(testAcc); err != nil {
		t.Error(err)
		t.Fail()
	}

	a, err := GetAccount(testAcc.ID)
	if a == nil || *a != *testAcc {
		t.Error(err)
		t.Fail()
	}
}
Пример #2
0
package persistence

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/justintan/gox/types"
	"testing"
	"time"
)

var testAcc = &Account{
	ID:         types.NewID(),
	OpenID:     types.NewUUID(),
	Mobile:     "138" + types.NewUUID()[:8],
	Email:      types.NewUUID()[:6] + "@test.com",
	Password:   "******",
	LoginToken: types.NewUUID(),

	Nick:      "Nick" + types.NewUUID()[:6],
	Gender:    1,
	Avatar:    "http://image.a.com/" + types.NewUUID(),
	Birthdate: "1980-03-21",
	CreatedAt: time.Now().Unix(),
	Status:    3,
}

func TestInsertAccount(t *testing.T) {
	err := InsertAccount(testAcc)
	if err != nil {
		t.Error(err)
		t.Fail()
	}
Пример #3
0
func GenerateSessionID(accountID types.ID) string {
	sid := crypt.SHA1(fmt.Sprint(accountID) + fmt.Sprint(time.Now().Unix()) + types.NewUUID())
	_cache.HSet("sid", sid, accountID, time.Minute*30)
	return sid
}