tests/session_query_test.go aktualisiert
Adding explicit only NotEmpty Tests for ID fields in cockroachDB
This commit is contained in:
parent
4e9669ae78
commit
acd92b44d9
|
@ -19,6 +19,7 @@ import (
|
|||
|
||||
func TestQueryString(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
dbEdtion, _ := testEngine.DBVersion()
|
||||
|
||||
type GetVar2 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -42,7 +43,12 @@ func TestQueryString(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, 1, len(records))
|
||||
assert.Equal(t, 5, len(records[0]))
|
||||
assert.Equal(t, "1", records[0]["id"])
|
||||
|
||||
if dbEdtion.Edition == "CockroachDB" {
|
||||
assert.NotEmpty(t, records[0]["id"])
|
||||
} else {
|
||||
assert.Equal(t, "1", records[0]["id"])
|
||||
}
|
||||
assert.Equal(t, "hi", records[0]["msg"])
|
||||
assert.Equal(t, "28", records[0]["age"])
|
||||
assert.Equal(t, "1.5", records[0]["money"])
|
||||
|
@ -50,6 +56,7 @@ func TestQueryString(t *testing.T) {
|
|||
|
||||
func TestQueryString2(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
dbEdtion, _ := testEngine.DBVersion()
|
||||
|
||||
type GetVar3 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -68,7 +75,13 @@ func TestQueryString2(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, 1, len(records))
|
||||
assert.Equal(t, 2, len(records[0]))
|
||||
assert.Equal(t, "1", records[0]["id"])
|
||||
|
||||
if dbEdtion.Edition == "CockroachDB" {
|
||||
assert.NotEmpty(t, records[0]["id"])
|
||||
} else {
|
||||
assert.Equal(t, "1", records[0]["id"])
|
||||
}
|
||||
|
||||
assert.True(t, "0" == records[0]["msg"] || "false" == records[0]["msg"])
|
||||
}
|
||||
|
||||
|
@ -84,6 +97,7 @@ func toBool(i interface{}) bool {
|
|||
|
||||
func TestQueryInterface(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
dbEdtion, _ := testEngine.DBVersion()
|
||||
|
||||
type GetVarInterface struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -107,7 +121,13 @@ func TestQueryInterface(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, 1, len(records))
|
||||
assert.Equal(t, 5, len(records[0]))
|
||||
assert.EqualValues(t, int64(1), records[0]["id"])
|
||||
|
||||
if dbEdtion.Edition == "CockroachDB" {
|
||||
assert.NotEmpty(t, records[0]["id"])
|
||||
} else {
|
||||
assert.EqualValues(t, int64(1), records[0]["id"])
|
||||
}
|
||||
|
||||
assert.Equal(t, "hi", records[0]["msg"])
|
||||
assert.EqualValues(t, 28, records[0]["age"])
|
||||
assert.EqualValues(t, 1.5, records[0]["money"])
|
||||
|
@ -115,6 +135,7 @@ func TestQueryInterface(t *testing.T) {
|
|||
|
||||
func TestQueryNoParams(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
dbEdtion, _ := testEngine.DBVersion()
|
||||
|
||||
type QueryNoParams struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -141,7 +162,12 @@ func TestQueryNoParams(t *testing.T) {
|
|||
assert.EqualValues(t, 1, len(results))
|
||||
id, err := strconv.ParseInt(string(results[0]["id"]), 10, 64)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, id)
|
||||
if dbEdtion.Edition == "CockroachDB" {
|
||||
assert.NotEmpty(t, id)
|
||||
} else {
|
||||
assert.EqualValues(t, 1, id)
|
||||
}
|
||||
|
||||
assert.Equal(t, "message", string(results[0]["msg"]))
|
||||
|
||||
age, err := strconv.Atoi(string(results[0]["age"]))
|
||||
|
@ -164,6 +190,7 @@ func TestQueryNoParams(t *testing.T) {
|
|||
|
||||
func TestQueryStringNoParam(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
dbEdtion, _ := testEngine.DBVersion()
|
||||
|
||||
type GetVar4 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -181,7 +208,12 @@ func TestQueryStringNoParam(t *testing.T) {
|
|||
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 dbEdtion.Edition == "CockroachDB" {
|
||||
assert.NotEmpty(t, records[0]["id"])
|
||||
} else {
|
||||
assert.EqualValues(t, "1", records[0]["id"])
|
||||
}
|
||||
|
||||
if testEngine.Dialect().URI().DBType == schemas.POSTGRES || testEngine.Dialect().URI().DBType == schemas.MSSQL {
|
||||
assert.EqualValues(t, "false", records[0]["msg"])
|
||||
} else {
|
||||
|
@ -201,6 +233,7 @@ func TestQueryStringNoParam(t *testing.T) {
|
|||
|
||||
func TestQuerySliceStringNoParam(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
dbEdtion, _ := testEngine.DBVersion()
|
||||
|
||||
type GetVar6 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -218,7 +251,12 @@ func TestQuerySliceStringNoParam(t *testing.T) {
|
|||
records, err := testEngine.Table("get_var6").Limit(1).QuerySliceString()
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(records))
|
||||
assert.EqualValues(t, "1", records[0][0])
|
||||
if dbEdtion.Edition == "CockroachDB" {
|
||||
assert.NotEmpty(t, records[0][0])
|
||||
} else {
|
||||
assert.EqualValues(t, "1", records[0][0])
|
||||
}
|
||||
|
||||
if testEngine.Dialect().URI().DBType == schemas.POSTGRES || testEngine.Dialect().URI().DBType == schemas.MSSQL {
|
||||
assert.EqualValues(t, "false", records[0][1])
|
||||
} else {
|
||||
|
@ -238,6 +276,7 @@ func TestQuerySliceStringNoParam(t *testing.T) {
|
|||
|
||||
func TestQueryInterfaceNoParam(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
dbEdtion, _ := testEngine.DBVersion()
|
||||
|
||||
type GetVar5 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -255,18 +294,31 @@ func TestQueryInterfaceNoParam(t *testing.T) {
|
|||
records, err := testEngine.Table("get_var5").Limit(1).QueryInterface()
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(records))
|
||||
assert.EqualValues(t, 1, records[0]["id"])
|
||||
|
||||
if dbEdtion.Edition == "CockroachDB" {
|
||||
assert.NotEmpty(t, 1, records[0]["id"])
|
||||
} else {
|
||||
assert.EqualValues(t, 1, records[0]["id"])
|
||||
}
|
||||
|
||||
assert.False(t, toBool(records[0]["msg"]))
|
||||
|
||||
records, err = testEngine.Table("get_var5").Where(builder.Eq{"`id`": 1}).QueryInterface()
|
||||
records, err = testEngine.Table("get_var5").Where(builder.Eq{"`id`": records[0]["id"]}).QueryInterface()
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(records))
|
||||
assert.EqualValues(t, 1, records[0]["id"])
|
||||
|
||||
if dbEdtion.Edition == "CockroachDB" {
|
||||
assert.NotEmpty(t, 1, records[0]["id"])
|
||||
} else {
|
||||
assert.EqualValues(t, 1, records[0]["id"])
|
||||
}
|
||||
|
||||
assert.False(t, toBool(records[0]["msg"]))
|
||||
}
|
||||
|
||||
func TestQueryWithBuilder(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
dbEdtion, _ := testEngine.DBVersion()
|
||||
|
||||
type QueryWithBuilder struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -293,7 +345,12 @@ func TestQueryWithBuilder(t *testing.T) {
|
|||
assert.EqualValues(t, 1, len(results))
|
||||
id, err := strconv.ParseInt(string(results[0]["id"]), 10, 64)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, id)
|
||||
if dbEdtion.Edition == "CockroachDB" {
|
||||
assert.NotEmpty(t, id)
|
||||
} else {
|
||||
assert.EqualValues(t, 1, id)
|
||||
}
|
||||
|
||||
assert.Equal(t, "message", string(results[0]["msg"]))
|
||||
|
||||
age, err := strconv.Atoi(string(results[0]["age"]))
|
||||
|
|
Loading…
Reference in New Issue