-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathviewmap_test.go
More file actions
44 lines (37 loc) · 1.04 KB
/
Copy pathviewmap_test.go
File metadata and controls
44 lines (37 loc) · 1.04 KB
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
package genddl
import (
"bytes"
"log"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestViewMap(t *testing.T) {
tr, err := retrieveTables(exampleSchemaDir)
if err != nil {
log.Fatalf("unexpected error: %s", err)
}
userProduct := tr.views["user_product"]
funcs := tr.funcs[userProduct]
bs := &bytes.Buffer{}
vm, err := NewViewMap(newViewMapInput{
name: "user_product",
st: userProduct,
funcs: funcs,
ti: tr.ti,
})
if err != nil {
t.Errorf("unexpected error on NewViewMap: %s", err)
t.FailNow()
}
if err := vm.WriteDDL(bs, MysqlDialect{}); err != nil {
t.Errorf("unexpected error on WriteDDL: %s", err)
}
expect := "CREATE VIEW `user_product`\n" +
" (`p_id`, `u_name`, `ru_name`, `p_id`, `p_type`) AS\n" +
" SELECT p.id, u.name, ru.name, p.id, p.type FROM product AS p\n" +
" INNER JOIN user AS u ON p.user_id = u.id\n" +
" LEFT JOIN user AS ru ON p.received_user_id = ru.id;\n\n"
if diff := cmp.Diff(expect, bs.String()); diff != "" {
t.Errorf("result is mismatch (-want +got):\n%s", diff)
}
}