This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
validator_test.go
137 lines (118 loc) · 4.3 KB
/
validator_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package pg2mysql_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pivotal-cf/pg2mysql"
)
var _ = Describe("Validator", func() {
var (
validator pg2mysql.Validator
mysql pg2mysql.DB
pg pg2mysql.DB
)
BeforeEach(func() {
mysql = pg2mysql.NewMySQLDB(
mysqlRunner.DBName,
"root",
"",
"127.0.0.1",
3306,
)
err := mysql.Open()
Expect(err).NotTo(HaveOccurred())
pg = pg2mysql.NewPostgreSQLDB(
pgRunner.DBName,
"",
"",
"127.0.0.1",
5432,
"disable",
)
err = pg.Open()
Expect(err).NotTo(HaveOccurred())
validator = pg2mysql.NewValidator(pg, mysql)
})
AfterEach(func() {
err := mysql.Close()
Expect(err).NotTo(HaveOccurred())
err = pg.Close()
Expect(err).NotTo(HaveOccurred())
})
Describe("Validate", func() {
It("returns a result", func() {
result, err := validator.Validate()
Expect(err).NotTo(HaveOccurred())
Expect(result).To(HaveLen(3))
Expect(result).To(ContainElement(pg2mysql.ValidationResult{
TableName: "table_with_id",
}))
Expect(result).To(ContainElement(pg2mysql.ValidationResult{
TableName: "table_without_id",
}))
})
Context("when there is compatible data in postgres", func() {
BeforeEach(func() {
result, err := pgRunner.DB().Exec("INSERT INTO table_with_id (id, name, ci_name, created_at, truthiness) VALUES (3, 'some-name', 'some-ci-name', now(), false);")
Expect(err).NotTo(HaveOccurred())
rowsAffected, err := result.RowsAffected()
Expect(err).NotTo(HaveOccurred())
Expect(rowsAffected).To(BeNumerically("==", 1))
})
It("returns a result", func() {
result, err := validator.Validate()
Expect(err).NotTo(HaveOccurred())
Expect(result).To(HaveLen(3))
Expect(result).To(ContainElement(pg2mysql.ValidationResult{
TableName: "table_with_id",
}))
Expect(result).To(ContainElement(pg2mysql.ValidationResult{
TableName: "table_without_id",
}))
})
})
Context("when there is incompatible data in postgres in a table with an 'id' column", func() {
BeforeEach(func() {
result, err := pgRunner.DB().Exec("INSERT INTO table_with_id (id, name, ci_name, created_at, truthiness) VALUES (3, 'some-name-that-is-too-long-for-mysql-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'some-other-ci-name', now(), false);")
Expect(err).NotTo(HaveOccurred())
rowsAffected, err := result.RowsAffected()
Expect(err).NotTo(HaveOccurred())
Expect(rowsAffected).To(BeNumerically("==", 1))
})
It("returns a result", func() {
result, err := validator.Validate()
Expect(err).NotTo(HaveOccurred())
Expect(result).To(HaveLen(3))
Expect(result).To(ContainElement(pg2mysql.ValidationResult{
TableName: "table_with_id",
IncompatibleRowIDs: []int{3},
IncompatibleRowCount: 1,
}))
Expect(result).To(ContainElement(pg2mysql.ValidationResult{
TableName: "table_without_id",
}))
})
})
Context("when there is incompatible data in postgres in a table without an 'id' column", func() {
BeforeEach(func() {
result, err := pgRunner.DB().Exec("INSERT INTO table_without_id (name, ci_name, created_at, truthiness) VALUES ('some-name-that-is-too-long-for-mysql-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'some-other-ci-name', now(), false);")
Expect(err).NotTo(HaveOccurred())
rowsAffected, err := result.RowsAffected()
Expect(err).NotTo(HaveOccurred())
Expect(rowsAffected).To(BeNumerically("==", 1))
})
It("returns a result", func() {
result, err := validator.Validate()
Expect(err).NotTo(HaveOccurred())
Expect(result).To(HaveLen(3))
Expect(result).To(ContainElement(pg2mysql.ValidationResult{
TableName: "table_with_id",
}))
Expect(result).To(ContainElement(pg2mysql.ValidationResult{
TableName: "table_without_id",
IncompatibleRowIDs: nil,
IncompatibleRowCount: 1,
}))
})
})
})
})