forked from vmware-archive/pg2mysql
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pg2mysql_suite_test.go
68 lines (57 loc) · 1.77 KB
/
pg2mysql_suite_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
package pg2mysql_test
import (
"fmt"
"io/ioutil"
"path/filepath"
"github.com/mrmark/pg2mysql/mysqlrunner"
"github.com/mrmark/pg2mysql/postgresrunner"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestPg2mysql(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Pg2mysql Suite")
}
var mysqlRunner mysqlrunner.Runner
var pgRunner postgresrunner.Runner
var _ = BeforeSuite(func() {
mysqlRunner = mysqlrunner.Runner{
DBName: fmt.Sprintf("testdb_%d", GinkgoParallelNode()),
}
err := mysqlRunner.Setup()
Expect(err).NotTo(HaveOccurred())
bs, err := ioutil.ReadFile(filepath.Join("testdata", "mysqldata.sql"))
Expect(err).NotTo(HaveOccurred())
result, err := mysqlRunner.DB().Exec(fmt.Sprintf("USE %s;", mysqlRunner.DBName))
Expect(err).NotTo(HaveOccurred())
result, err = mysqlRunner.DB().Exec(string(bs))
Expect(err).NotTo(HaveOccurred())
rowsAffected, err := result.RowsAffected()
Expect(err).NotTo(HaveOccurred())
Expect(rowsAffected).To(BeNumerically("==", 0))
pgRunner = postgresrunner.Runner{
DBName: fmt.Sprintf("testdb_%d", GinkgoParallelNode()),
}
err = pgRunner.Setup()
Expect(err).NotTo(HaveOccurred())
bs, err = ioutil.ReadFile(filepath.Join("testdata", "pgdata.sql"))
Expect(err).NotTo(HaveOccurred())
result, err = pgRunner.DB().Exec(string(bs))
Expect(err).NotTo(HaveOccurred())
rowsAffected, err = result.RowsAffected()
Expect(err).NotTo(HaveOccurred())
Expect(rowsAffected).To(BeNumerically("==", 0))
})
var _ = AfterSuite(func() {
err := mysqlRunner.Teardown()
Expect(err).NotTo(HaveOccurred())
err = pgRunner.Teardown()
Expect(err).NotTo(HaveOccurred())
})
var _ = AfterEach(func() {
err := mysqlRunner.Truncate()
Expect(err).NotTo(HaveOccurred())
err = pgRunner.Truncate()
Expect(err).NotTo(HaveOccurred())
})