Skip to content

Commit

Permalink
Add more test for query (go-xorm#932)
Browse files Browse the repository at this point in the history
* add more test for query

* fix tests
  • Loading branch information
lunny authored May 8, 2018
1 parent d85bb49 commit ab17aa2
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions session_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/go-xorm/builder"
"github.com/go-xorm/core"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -186,6 +187,72 @@ func TestQueryNoParams(t *testing.T) {
assertResult(t, results)
}

func TestQueryStringNoParam(t *testing.T) {
assert.NoError(t, prepareEngine())

type GetVar4 struct {
Id int64 `xorm:"autoincr pk"`
Msg bool `xorm:"bit"`
}

assert.NoError(t, testEngine.Sync2(new(GetVar4)))

var data = GetVar4{
Msg: false,
}
_, err := testEngine.Insert(data)
assert.NoError(t, err)

records, err := testEngine.Table("get_var4").Limit(1).QueryString()
assert.NoError(t, err)
assert.EqualValues(t, 1, len(records))
assert.EqualValues(t, "1", records[0]["id"])
if testEngine.Dialect().URI().DbType == core.POSTGRES {
assert.EqualValues(t, "false", records[0]["msg"])
} else {
assert.EqualValues(t, "0", records[0]["msg"])
}

records, err = testEngine.Table("get_var4").Where(builder.Eq{"id": 1}).QueryString()
assert.NoError(t, err)
assert.EqualValues(t, 1, len(records))
assert.EqualValues(t, "1", records[0]["id"])
if testEngine.Dialect().URI().DbType == core.POSTGRES {
assert.EqualValues(t, "false", records[0]["msg"])
} else {
assert.EqualValues(t, "0", records[0]["msg"])
}
}

func TestQueryInterfaceNoParam(t *testing.T) {
assert.NoError(t, prepareEngine())

type GetVar5 struct {
Id int64 `xorm:"autoincr pk"`
Msg bool `xorm:"bit"`
}

assert.NoError(t, testEngine.Sync2(new(GetVar5)))

var data = GetVar5{
Msg: false,
}
_, err := testEngine.Insert(data)
assert.NoError(t, err)

records, err := testEngine.Table("get_var5").Limit(1).QueryInterface()
assert.NoError(t, err)
assert.EqualValues(t, 1, len(records))
assert.EqualValues(t, 1, toInt64(records[0]["id"]))
assert.EqualValues(t, 0, toInt64(records[0]["msg"]))

records, err = testEngine.Table("get_var5").Where(builder.Eq{"id": 1}).QueryInterface()
assert.NoError(t, err)
assert.EqualValues(t, 1, len(records))
assert.EqualValues(t, 1, toInt64(records[0]["id"]))
assert.EqualValues(t, 0, toInt64(records[0]["msg"]))
}

func TestQueryWithBuilder(t *testing.T) {
assert.NoError(t, prepareEngine())

Expand Down

0 comments on commit ab17aa2

Please sign in to comment.