-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbug_test.go
64 lines (56 loc) · 1.76 KB
/
bug_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package bug
import (
"context"
"fmt"
"net"
"strconv"
"testing"
"entgo.io/ent/dialect"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
"entgo.io/bug/ent"
"entgo.io/bug/ent/enttest"
)
func TestBugSQLite(t *testing.T) {
client := enttest.Open(t, dialect.SQLite, "file:ent?mode=memory&cache=shared&_fk=1")
defer client.Close()
test(t, client)
}
func TestBugMySQL(t *testing.T) {
for version, port := range map[string]int{"56": 3306, "57": 3307, "8": 3308} {
addr := net.JoinHostPort("localhost", strconv.Itoa(port))
t.Run(version, func(t *testing.T) {
client := enttest.Open(t, dialect.MySQL, fmt.Sprintf("root:pass@tcp(%s)/test?parseTime=True", addr))
defer client.Close()
test(t, client)
})
}
}
func TestBugPostgres(t *testing.T) {
for version, port := range map[string]int{"10": 5430, "11": 5431, "12": 5432, "13": 5433, "14": 5434} {
t.Run(version, func(t *testing.T) {
client := enttest.Open(t, dialect.Postgres, fmt.Sprintf("host=localhost port=%d user=postgres dbname=test password=pass sslmode=disable", port))
defer client.Close()
test(t, client)
})
}
}
func TestBugMaria(t *testing.T) {
for version, port := range map[string]int{"10.5": 4306, "10.2": 4307, "10.3": 4308} {
t.Run(version, func(t *testing.T) {
addr := net.JoinHostPort("localhost", strconv.Itoa(port))
client := enttest.Open(t, dialect.MySQL, fmt.Sprintf("root:pass@tcp(%s)/test?parseTime=True", addr))
defer client.Close()
test(t, client)
})
}
}
func test(t *testing.T, client *ent.Client) {
ctx := context.Background()
client.User.Delete().ExecX(ctx)
client.User.Create().SetName("Ariel").SetAge(30).ExecX(ctx)
if n := client.User.Query().CountX(ctx); n != 1 {
t.Errorf("unexpected number of users: %d", n)
}
}