15 Star 45 Fork 15

fifsky/gosql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mapper_test.go 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
fifsky 提交于 2019-09-12 14:50 . Upgrade the major version to V2
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")
}
}
})
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fifsky/gosql.git
[email protected]:fifsky/gosql.git
fifsky
gosql
gosql
master

搜索帮助