-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils_test.go
83 lines (76 loc) · 2.2 KB
/
utils_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package mysql
import (
"fmt"
"log"
"os"
)
func createMockScripts(base string) {
log.Println("Create scripts on", base)
err := os.MkdirAll(fmt.Sprint(base, "/fulltable"), 0777)
if err != nil {
log.Println(err)
}
_, err = os.Create(fmt.Sprint(base, "/fulltable/get_all.read.sql"))
if err != nil {
log.Println(err)
}
_, err = os.Create(fmt.Sprint(base, "/fulltable/get_all_slice.read.sql"))
if err != nil {
log.Println(err)
}
_, err = os.Create(fmt.Sprint(base, "/fulltable/write_all.write.sql"))
if err != nil {
log.Println(err)
}
_, err = os.Create(fmt.Sprint(base, "/fulltable/create_table.write.sql"))
if err != nil {
log.Println(err)
}
_, err = os.Create(fmt.Sprint(base, "/fulltable/patch_all.update.sql"))
if err != nil {
log.Println(err)
}
_, err = os.Create(fmt.Sprint(base, "/fulltable/put_all.update.sql"))
if err != nil {
log.Println(err)
}
_, err = os.Create(fmt.Sprint(base, "/fulltable/delete_all.delete.sql"))
if err != nil {
log.Println(err)
}
}
func writeMockScripts(base string) {
base = fmt.Sprint(base, "/fulltable/")
log.Println("Write scripts on", base)
write := func(sql, fileName string) {
var file, err = os.OpenFile(fmt.Sprint(base, fileName), os.O_RDWR, 0644)
if err != nil {
log.Fatal(err)
}
defer file.Close()
// write some text to file
_, err = file.WriteString(sql)
if err != nil {
log.Fatal(err)
}
// save changes
err = file.Sync()
if err != nil {
log.Fatal(err)
}
}
write("SELECT * FROM test7 WHERE name = '{{.field1}}'", "get_all.read.sql")
write(`SELECT * FROM test7 WHERE name IN {{inFormat "field1"}}`, "get_all_slice.read.sql")
write("INSERT INTO test7 (name, surname) VALUES ('{{.field1}}', '{{.field2}}')", "write_all.write.sql")
write("CREATE TABLE {{.field1}};", "create_table.write.sql")
write("UPDATE test7 SET name = '{{.field1}}' WHERE surname = '{{.field2}}'", "patch_all.update.sql")
write("UPDATE test7 SET surname = '{{.field1}}' WHERE name = '{{.field2}}'", "put_all.update.sql")
write("DELETE FROM test7 WHERE name = '{{.field1}}'", "delete_all.delete.sql")
}
func removeMockScripts(base string) {
log.Println("Remove scripts on", base)
err := os.RemoveAll(base)
if err != nil {
log.Println(err)
}
}