-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathforeignkey_test.go
49 lines (42 loc) · 1.01 KB
/
foreignkey_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
package sol
import "testing"
func TestForeignKey(t *testing.T) {
expect := NewTester(t, &defaultDialect{})
expect.SQL(
contacts.Create(),
`CREATE TABLE contacts (
id INTEGER,
user_id INTEGER REFERENCES users(id),
key VARCHAR,
value VARCHAR,
PRIMARY KEY (id),
UNIQUE (user_id, key)
);`,
)
expect.SQL(
messages.Create(),
`CREATE TABLE messages (
id INTEGER,
user_id INTEGER REFERENCES users(id),
parent_id INTEGER REFERENCES messages(id),
text TEXT
);`,
)
if len(messages.ForeignKeys()) != 2 {
t.Fatalf(
"unexpected length of messages foreign keys: %d != 2",
len(messages.ForeignKeys()),
)
}
// The messages table's first reference should be users
if messages.ForeignKeys()[0].references != users {
t.Errorf("messages' first foreign key should reference table users")
}
// The users table should be referenced by messages and contacts
if len(users.ReferencedBy()) != 2 {
t.Fatalf(
"unexpected length of users references: %d != 2",
len(users.ReferencedBy()),
)
}
}