-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_jointer_test.go
50 lines (42 loc) · 1.4 KB
/
sql_jointer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package dbx
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestJoin(t *testing.T) {
assert := assert.New(t)
// create table
tDatabase.DropTable(USER_TABLE)
tDatabase.DropTable(USER_LOGIN_TABLE)
assert.Nil(tDatabase.CreateTable(USER_TABLE))
assert.Nil(tDatabase.CreateTable(USER_LOGIN_TABLE))
var err error
_, err = tDatabase.T(USER_TABLE).Insert(&TestUsers[0])
assert.Nil(err)
_, err = tDatabase.T(USER_TABLE).Insert(&TestUsers[1])
assert.Nil(err)
_, err = tDatabase.T(USER_TABLE).Insert(&TestUsers[2])
assert.Nil(err)
_, err = tDatabase.T(USER_LOGIN_TABLE).Insert(&TestUserLogins[0])
assert.Nil(err)
_, err = tDatabase.T(USER_LOGIN_TABLE).Insert(&TestUserLogins[1])
assert.Nil(err)
_, err = tDatabase.T(USER_LOGIN_TABLE).Insert(&TestUserLogins[2])
assert.Nil(err)
user := User{}
userLogin := UserLogin{}
assert.Nil(tDatabase.T(USER_TABLE).SelectAll().
InnerJoin(USER_LOGIN_TABLE, "userid", "userid").SelectAll().
Filter("user.userid=?", TestUsers[1].Userid).One(&user, &userLogin))
TestUsers[1].Id = user.Id
TestUserLogins[1].Id = userLogin.Id
assert.Equal(user, TestUsers[1])
assert.Equal(userLogin, TestUserLogins[1])
users := []User{}
userLogins := []UserLogin{}
assert.Nil(tDatabase.T(USER_TABLE).SelectAll().
InnerJoin(USER_LOGIN_TABLE, "userid", "userid").SelectAll().
All(&users, &userLogins))
assert.Equal(len(users), 3)
assert.Equal(len(userLogins), 3)
}