1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/fifsky-gosql

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
mapper_test.go 1.7 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
fifsky Отправлено 12.09.2019 09:50 2bec5dd
package gosql
import (
"strconv"
"testing"
)
func mapInsert(t *testing.T, id int64) int64 {
id, err := Table("users").Create(map[string]interface{}{
"id": id,
"name": "test" + strconv.Itoa(int(id)),
"status": 1,
"created_at": "2018-07-11 11:58:21",
"updated_at": "2018-07-11 11:58:21",
})
if err != nil {
t.Error(err)
}
if id <= 0 {
t.Error("map insert error")
}
return id
}
func TestMapper_Create(t *testing.T) {
RunWithSchema(t, func(t *testing.T) {
mapInsert(t, 1)
})
}
func TestMapper_Update(t *testing.T) {
RunWithSchema(t, func(t *testing.T) {
id := mapInsert(t, 1)
affected, err := Table("users").Where("id = ?", id).Update(map[string]interface{}{
"name": "fifsky",
})
if err != nil {
t.Error(err)
}
if affected <= 0 {
t.Error("map update error")
}
})
}
func TestMapper_Delete(t *testing.T) {
RunWithSchema(t, func(t *testing.T) {
{
id := mapInsert(t, 1)
affected, err := Table("users").Where("id = ?", id).Delete()
if err != nil {
t.Error(err)
}
if affected <= 0 {
t.Error("map delete error")
}
}
{
mapInsert(t, 2)
affected, err := Table("users").Delete()
if err != nil {
t.Error(err)
}
if affected <= 0 {
t.Error("map delete error")
}
}
})
}
func TestMapper_Count(t *testing.T) {
RunWithSchema(t, func(t *testing.T) {
{
id := mapInsert(t, 1)
num, err := Table("users").Where("id = ?", id).Count()
if err != nil {
t.Error(err)
}
if num != 1 {
t.Error("map count error")
}
}
{
mapInsert(t, 2)
mapInsert(t, 3)
num, err := Table("users").Count()
if err != nil {
t.Error(err)
}
if num <= 0 {
t.Error("map count error")
}
}
})
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/fifsky-gosql.git
git@api.gitlife.ru:oschina-mirror/fifsky-gosql.git
oschina-mirror
fifsky-gosql
fifsky-gosql
master