-
Notifications
You must be signed in to change notification settings - Fork 17
/
main_test.go
60 lines (55 loc) · 1.5 KB
/
main_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
package main
import (
"bytes"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestLoad(t *testing.T) {
for _, dialect := range []string{"mysql", "sqlite", "postgres"} {
t.Run(dialect, func(t *testing.T) {
var buf bytes.Buffer
cmd := &LoadCmd{
Path: "./internal/testdata/models",
Dialect: dialect,
out: &buf,
}
err := cmd.Run()
require.NoError(t, err)
require.Contains(t, buf.String(), "CREATE TABLE")
require.Contains(t, buf.String(), "pets")
require.Contains(t, buf.String(), "users")
require.NotContains(t, buf.String(), "toys") // Struct without GORM annotations.
})
}
}
func TestDeterministicOutput(t *testing.T) {
expected, err := os.ReadFile("./gormschema/testdata/mysql_deterministic_output")
require.NoError(t, err)
cmd := &LoadCmd{
Path: "./internal/testdata/models",
Dialect: "mysql",
}
for i := 0; i < 10; i++ {
var buf bytes.Buffer
cmd.out = &buf
err := cmd.Run()
require.NoError(t, err)
actual := bytes.TrimSuffix(buf.Bytes(), []byte("\n"))
require.Equal(t, string(expected), string(actual))
}
}
func TestCustomizeTablesLoad(t *testing.T) {
var buf bytes.Buffer
cmd := &LoadCmd{
Path: "./internal/testdata/customjointable",
Dialect: "mysql",
out: &buf,
}
err := cmd.Run()
require.NoError(t, err)
expected, err := os.ReadFile("./gormschema/testdata/mysql_custom_join_table")
require.NoError(t, err)
actual := bytes.TrimSuffix(buf.Bytes(), []byte("\n"))
require.Equal(t, string(expected), string(actual))
}