Skip to content

Commit 8e38b86

Browse files
Merge branch 'master' of https://github.com/github/gh-ost into meiji163/parallel-repl
2 parents 113e674 + 00f450d commit 8e38b86

16 files changed

+477
-558
lines changed

go/base/context_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/openark/golib/log"
14-
test "github.com/openark/golib/tests"
14+
"github.com/stretchr/testify/require"
1515
)
1616

1717
func init() {
@@ -22,22 +22,22 @@ func TestGetTableNames(t *testing.T) {
2222
{
2323
context := NewMigrationContext()
2424
context.OriginalTableName = "some_table"
25-
test.S(t).ExpectEquals(context.GetOldTableName(), "_some_table_del")
26-
test.S(t).ExpectEquals(context.GetGhostTableName(), "_some_table_gho")
27-
test.S(t).ExpectEquals(context.GetChangelogTableName(), "_some_table_ghc")
25+
require.Equal(t, "_some_table_del", context.GetOldTableName())
26+
require.Equal(t, "_some_table_gho", context.GetGhostTableName())
27+
require.Equal(t, "_some_table_ghc", context.GetChangelogTableName(), "_some_table_ghc")
2828
}
2929
{
3030
context := NewMigrationContext()
3131
context.OriginalTableName = "a123456789012345678901234567890123456789012345678901234567890"
32-
test.S(t).ExpectEquals(context.GetOldTableName(), "_a1234567890123456789012345678901234567890123456789012345678_del")
33-
test.S(t).ExpectEquals(context.GetGhostTableName(), "_a1234567890123456789012345678901234567890123456789012345678_gho")
34-
test.S(t).ExpectEquals(context.GetChangelogTableName(), "_a1234567890123456789012345678901234567890123456789012345678_ghc")
32+
require.Equal(t, "_a1234567890123456789012345678901234567890123456789012345678_del", context.GetOldTableName())
33+
require.Equal(t, "_a1234567890123456789012345678901234567890123456789012345678_gho", context.GetGhostTableName())
34+
require.Equal(t, "_a1234567890123456789012345678901234567890123456789012345678_ghc", context.GetChangelogTableName())
3535
}
3636
{
3737
context := NewMigrationContext()
3838
context.OriginalTableName = "a123456789012345678901234567890123456789012345678901234567890123"
3939
oldTableName := context.GetOldTableName()
40-
test.S(t).ExpectEquals(oldTableName, "_a1234567890123456789012345678901234567890123456789012345678_del")
40+
require.Equal(t, "_a1234567890123456789012345678901234567890123456789012345678_del", oldTableName)
4141
}
4242
{
4343
context := NewMigrationContext()
@@ -46,15 +46,15 @@ func TestGetTableNames(t *testing.T) {
4646
longForm := "Jan 2, 2006 at 3:04pm (MST)"
4747
context.StartTime, _ = time.Parse(longForm, "Feb 3, 2013 at 7:54pm (PST)")
4848
oldTableName := context.GetOldTableName()
49-
test.S(t).ExpectEquals(oldTableName, "_a1234567890123456789012345678901234567890123_20130203195400_del")
49+
require.Equal(t, "_a1234567890123456789012345678901234567890123_20130203195400_del", oldTableName)
5050
}
5151
{
5252
context := NewMigrationContext()
5353
context.OriginalTableName = "foo_bar_baz"
5454
context.ForceTmpTableName = "tmp"
55-
test.S(t).ExpectEquals(context.GetOldTableName(), "_tmp_del")
56-
test.S(t).ExpectEquals(context.GetGhostTableName(), "_tmp_gho")
57-
test.S(t).ExpectEquals(context.GetChangelogTableName(), "_tmp_ghc")
55+
require.Equal(t, "_tmp_del", context.GetOldTableName())
56+
require.Equal(t, "_tmp_gho", context.GetGhostTableName())
57+
require.Equal(t, "_tmp_ghc", context.GetChangelogTableName())
5858
}
5959
}
6060

go/base/load_map_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/openark/golib/log"
12-
test "github.com/openark/golib/tests"
12+
"github.com/stretchr/testify/require"
1313
)
1414

1515
func init() {
@@ -20,39 +20,39 @@ func TestParseLoadMap(t *testing.T) {
2020
{
2121
loadList := ""
2222
m, err := ParseLoadMap(loadList)
23-
test.S(t).ExpectNil(err)
24-
test.S(t).ExpectEquals(len(m), 0)
23+
require.NoError(t, err)
24+
require.Len(t, m, 0)
2525
}
2626
{
2727
loadList := "threads_running=20,threads_connected=10"
2828
m, err := ParseLoadMap(loadList)
29-
test.S(t).ExpectNil(err)
30-
test.S(t).ExpectEquals(len(m), 2)
31-
test.S(t).ExpectEquals(m["threads_running"], int64(20))
32-
test.S(t).ExpectEquals(m["threads_connected"], int64(10))
29+
require.NoError(t, err)
30+
require.Len(t, m, 2)
31+
require.Equal(t, int64(20), m["threads_running"])
32+
require.Equal(t, int64(10), m["threads_connected"])
3333
}
3434
{
3535
loadList := "threads_running=20=30,threads_connected=10"
3636
_, err := ParseLoadMap(loadList)
37-
test.S(t).ExpectNotNil(err)
37+
require.Error(t, err)
3838
}
3939
{
4040
loadList := "threads_running=20,threads_connected"
4141
_, err := ParseLoadMap(loadList)
42-
test.S(t).ExpectNotNil(err)
42+
require.Error(t, err)
4343
}
4444
}
4545

4646
func TestString(t *testing.T) {
4747
{
4848
m, _ := ParseLoadMap("")
4949
s := m.String()
50-
test.S(t).ExpectEquals(s, "")
50+
require.Equal(t, "", s)
5151
}
5252
{
5353
loadList := "threads_running=20,threads_connected=10"
5454
m, _ := ParseLoadMap(loadList)
5555
s := m.String()
56-
test.S(t).ExpectEquals(s, "threads_connected=10,threads_running=20")
56+
require.Equal(t, "threads_connected=10,threads_running=20", s)
5757
}
5858
}

go/base/utils_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/openark/golib/log"
12-
test "github.com/openark/golib/tests"
12+
"github.com/stretchr/testify/require"
1313
)
1414

1515
func init() {
@@ -19,11 +19,11 @@ func init() {
1919
func TestStringContainsAll(t *testing.T) {
2020
s := `insert,delete,update`
2121

22-
test.S(t).ExpectFalse(StringContainsAll(s))
23-
test.S(t).ExpectFalse(StringContainsAll(s, ""))
24-
test.S(t).ExpectFalse(StringContainsAll(s, "drop"))
25-
test.S(t).ExpectTrue(StringContainsAll(s, "insert"))
26-
test.S(t).ExpectFalse(StringContainsAll(s, "insert", "drop"))
27-
test.S(t).ExpectTrue(StringContainsAll(s, "insert", ""))
28-
test.S(t).ExpectTrue(StringContainsAll(s, "insert", "update", "delete"))
22+
require.False(t, StringContainsAll(s))
23+
require.False(t, StringContainsAll(s, ""))
24+
require.False(t, StringContainsAll(s, "drop"))
25+
require.True(t, StringContainsAll(s, "insert"))
26+
require.False(t, StringContainsAll(s, "insert", "drop"))
27+
require.True(t, StringContainsAll(s, "insert", ""))
28+
require.True(t, StringContainsAll(s, "insert", "update", "delete"))
2929
}

go/logic/applier_test.go

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12-
test "github.com/openark/golib/tests"
12+
"github.com/stretchr/testify/require"
1313

1414
"github.com/github/gh-ost/go/base"
1515
"github.com/github/gh-ost/go/binlog"
@@ -21,33 +21,33 @@ func TestApplierGenerateSqlModeQuery(t *testing.T) {
2121
applier := NewApplier(migrationContext)
2222

2323
{
24-
test.S(t).ExpectEquals(
25-
applier.generateSqlModeQuery(),
24+
require.Equal(t,
2625
`sql_mode = CONCAT(@@session.sql_mode, ',NO_AUTO_VALUE_ON_ZERO,STRICT_ALL_TABLES')`,
26+
applier.generateSqlModeQuery(),
2727
)
2828
}
2929
{
3030
migrationContext.SkipStrictMode = true
3131
migrationContext.AllowZeroInDate = false
32-
test.S(t).ExpectEquals(
33-
applier.generateSqlModeQuery(),
32+
require.Equal(t,
3433
`sql_mode = CONCAT(@@session.sql_mode, ',NO_AUTO_VALUE_ON_ZERO')`,
34+
applier.generateSqlModeQuery(),
3535
)
3636
}
3737
{
3838
migrationContext.SkipStrictMode = false
3939
migrationContext.AllowZeroInDate = true
40-
test.S(t).ExpectEquals(
41-
applier.generateSqlModeQuery(),
40+
require.Equal(t,
4241
`sql_mode = REPLACE(REPLACE(CONCAT(@@session.sql_mode, ',NO_AUTO_VALUE_ON_ZERO,STRICT_ALL_TABLES'), 'NO_ZERO_IN_DATE', ''), 'NO_ZERO_DATE', '')`,
42+
applier.generateSqlModeQuery(),
4343
)
4444
}
4545
{
4646
migrationContext.SkipStrictMode = true
4747
migrationContext.AllowZeroInDate = true
48-
test.S(t).ExpectEquals(
49-
applier.generateSqlModeQuery(),
48+
require.Equal(t,
5049
`sql_mode = REPLACE(REPLACE(CONCAT(@@session.sql_mode, ',NO_AUTO_VALUE_ON_ZERO'), 'NO_ZERO_IN_DATE', ''), 'NO_ZERO_DATE', '')`,
50+
applier.generateSqlModeQuery(),
5151
)
5252
}
5353
}
@@ -72,8 +72,8 @@ func TestApplierUpdateModifiesUniqueKeyColumns(t *testing.T) {
7272
NewColumnValues: columnValues,
7373
WhereColumnValues: columnValues,
7474
})
75-
test.S(t).ExpectEquals(modifiedColumn, "")
76-
test.S(t).ExpectFalse(isModified)
75+
require.Equal(t, "", modifiedColumn)
76+
require.False(t, isModified)
7777
})
7878

7979
t.Run("modified", func(t *testing.T) {
@@ -83,8 +83,8 @@ func TestApplierUpdateModifiesUniqueKeyColumns(t *testing.T) {
8383
NewColumnValues: sql.ToColumnValues([]interface{}{123456, 24}),
8484
WhereColumnValues: columnValues,
8585
})
86-
test.S(t).ExpectEquals(modifiedColumn, "item_id")
87-
test.S(t).ExpectTrue(isModified)
86+
require.Equal(t, "item_id", modifiedColumn)
87+
require.True(t, isModified)
8888
})
8989
}
9090

@@ -112,17 +112,17 @@ func TestApplierBuildDMLEventQuery(t *testing.T) {
112112
}
113113

114114
res := applier.buildDMLEventQuery(binlogEvent)
115-
test.S(t).ExpectEquals(len(res), 1)
116-
test.S(t).ExpectNil(res[0].err)
117-
test.S(t).ExpectEquals(strings.TrimSpace(res[0].query), `delete /* gh-ost `+"`test`.`_test_gho`"+` */
115+
require.Len(t, res, 1)
116+
require.NoError(t, res[0].err)
117+
require.Equal(t, `delete /* gh-ost `+"`test`.`_test_gho`"+` */
118118
from
119119
`+"`test`.`_test_gho`"+`
120120
where
121121
((`+"`id`"+` = ?) and (`+"`item_id`"+` = ?))`,
122-
)
123-
test.S(t).ExpectEquals(len(res[0].args), 2)
124-
test.S(t).ExpectEquals(res[0].args[0], 123456)
125-
test.S(t).ExpectEquals(res[0].args[1], 42)
122+
strings.TrimSpace(res[0].query))
123+
require.Len(t, res[0].args, 2)
124+
require.Equal(t, 123456, res[0].args[0])
125+
require.Equal(t, 42, res[0].args[1])
126126
})
127127

128128
t.Run("insert", func(t *testing.T) {
@@ -132,18 +132,19 @@ func TestApplierBuildDMLEventQuery(t *testing.T) {
132132
NewColumnValues: columnValues,
133133
}
134134
res := applier.buildDMLEventQuery(binlogEvent)
135-
test.S(t).ExpectEquals(len(res), 1)
136-
test.S(t).ExpectNil(res[0].err)
137-
test.S(t).ExpectEquals(strings.TrimSpace(res[0].query),
135+
require.Len(t, res, 1)
136+
require.NoError(t, res[0].err)
137+
require.Equal(t,
138138
`replace /* gh-ost `+"`test`.`_test_gho`"+` */
139139
into
140140
`+"`test`.`_test_gho`"+`
141141
`+"(`id`, `item_id`)"+`
142142
values
143-
(?, ?)`)
144-
test.S(t).ExpectEquals(len(res[0].args), 2)
145-
test.S(t).ExpectEquals(res[0].args[0], 123456)
146-
test.S(t).ExpectEquals(res[0].args[1], 42)
143+
(?, ?)`,
144+
strings.TrimSpace(res[0].query))
145+
require.Len(t, res[0].args, 2)
146+
require.Equal(t, 123456, res[0].args[0])
147+
require.Equal(t, 42, res[0].args[1])
147148
})
148149

149150
t.Run("update", func(t *testing.T) {
@@ -154,20 +155,21 @@ func TestApplierBuildDMLEventQuery(t *testing.T) {
154155
WhereColumnValues: columnValues,
155156
}
156157
res := applier.buildDMLEventQuery(binlogEvent)
157-
test.S(t).ExpectEquals(len(res), 1)
158-
test.S(t).ExpectNil(res[0].err)
159-
test.S(t).ExpectEquals(strings.TrimSpace(res[0].query),
158+
require.Len(t, res, 1)
159+
require.NoError(t, res[0].err)
160+
require.Equal(t,
160161
`update /* gh-ost `+"`test`.`_test_gho`"+` */
161162
`+"`test`.`_test_gho`"+`
162163
set
163164
`+"`id`"+`=?, `+"`item_id`"+`=?
164165
where
165-
((`+"`id`"+` = ?) and (`+"`item_id`"+` = ?))`)
166-
test.S(t).ExpectEquals(len(res[0].args), 4)
167-
test.S(t).ExpectEquals(res[0].args[0], 123456)
168-
test.S(t).ExpectEquals(res[0].args[1], 42)
169-
test.S(t).ExpectEquals(res[0].args[2], 123456)
170-
test.S(t).ExpectEquals(res[0].args[3], 42)
166+
((`+"`id`"+` = ?) and (`+"`item_id`"+` = ?))`,
167+
strings.TrimSpace(res[0].query))
168+
require.Len(t, res[0].args, 4)
169+
require.Equal(t, 123456, res[0].args[0])
170+
require.Equal(t, 42, res[0].args[1])
171+
require.Equal(t, 123456, res[0].args[2])
172+
require.Equal(t, 42, res[0].args[3])
171173
})
172174
}
173175

@@ -180,6 +182,6 @@ func TestApplierInstantDDL(t *testing.T) {
180182

181183
t.Run("instantDDLstmt", func(t *testing.T) {
182184
stmt := applier.generateInstantDDLQuery()
183-
test.S(t).ExpectEquals(stmt, "ALTER /* gh-ost */ TABLE `test`.`mytable` ADD INDEX (foo), ALGORITHM=INSTANT")
185+
require.Equal(t, "ALTER /* gh-ost */ TABLE `test`.`mytable` ADD INDEX (foo), ALGORITHM=INSTANT", stmt)
184186
})
185187
}

go/logic/hooks_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"testing"
1717
"time"
1818

19-
"github.com/openark/golib/tests"
19+
"github.com/stretchr/testify/require"
2020

2121
"github.com/github/gh-ost/go/base"
2222
)
@@ -44,7 +44,7 @@ func TestHooksExecutorExecuteHooks(t *testing.T) {
4444

4545
t.Run("does-not-exist", func(t *testing.T) {
4646
migrationContext.HooksPath = "/does/not/exist"
47-
tests.S(t).ExpectNil(hooksExecutor.executeHooks("test-hook"))
47+
require.Nil(t, hooksExecutor.executeHooks("test-hook"))
4848
})
4949

5050
t.Run("failed", func(t *testing.T) {
@@ -57,7 +57,7 @@ func TestHooksExecutorExecuteHooks(t *testing.T) {
5757
panic(err)
5858
}
5959
defer os.RemoveAll(migrationContext.HooksPath)
60-
tests.S(t).ExpectNotNil(hooksExecutor.executeHooks("failed-hook"))
60+
require.NotNil(t, hooksExecutor.executeHooks("failed-hook"))
6161
})
6262

6363
t.Run("success", func(t *testing.T) {
@@ -73,40 +73,40 @@ func TestHooksExecutorExecuteHooks(t *testing.T) {
7373

7474
var buf bytes.Buffer
7575
hooksExecutor.writer = &buf
76-
tests.S(t).ExpectNil(hooksExecutor.executeHooks("success-hook", "TEST="+t.Name()))
76+
require.Nil(t, hooksExecutor.executeHooks("success-hook", "TEST="+t.Name()))
7777

7878
scanner := bufio.NewScanner(&buf)
7979
for scanner.Scan() {
8080
split := strings.SplitN(scanner.Text(), "=", 2)
8181
switch split[0] {
8282
case "GH_OST_COPIED_ROWS":
8383
copiedRows, _ := strconv.ParseInt(split[1], 10, 64)
84-
tests.S(t).ExpectEquals(copiedRows, migrationContext.TotalRowsCopied)
84+
require.Equal(t, migrationContext.TotalRowsCopied, copiedRows)
8585
case "GH_OST_DATABASE_NAME":
86-
tests.S(t).ExpectEquals(split[1], migrationContext.DatabaseName)
86+
require.Equal(t, migrationContext.DatabaseName, split[1])
8787
case "GH_OST_DDL":
88-
tests.S(t).ExpectEquals(split[1], migrationContext.AlterStatement)
88+
require.Equal(t, migrationContext.AlterStatement, split[1])
8989
case "GH_OST_DRY_RUN":
90-
tests.S(t).ExpectEquals(split[1], "false")
90+
require.Equal(t, "false", split[1])
9191
case "GH_OST_ESTIMATED_ROWS":
9292
estimatedRows, _ := strconv.ParseInt(split[1], 10, 64)
93-
tests.S(t).ExpectEquals(estimatedRows, int64(123))
93+
require.Equal(t, int64(123), estimatedRows)
9494
case "GH_OST_ETA_SECONDS":
9595
etaSeconds, _ := strconv.ParseInt(split[1], 10, 64)
96-
tests.S(t).ExpectEquals(etaSeconds, int64(60))
96+
require.Equal(t, int64(60), etaSeconds)
9797
case "GH_OST_EXECUTING_HOST":
98-
tests.S(t).ExpectEquals(split[1], migrationContext.Hostname)
98+
require.Equal(t, migrationContext.Hostname, split[1])
9999
case "GH_OST_GHOST_TABLE_NAME":
100-
tests.S(t).ExpectEquals(split[1], fmt.Sprintf("_%s_gho", migrationContext.OriginalTableName))
100+
require.Equal(t, fmt.Sprintf("_%s_gho", migrationContext.OriginalTableName), split[1])
101101
case "GH_OST_OLD_TABLE_NAME":
102-
tests.S(t).ExpectEquals(split[1], fmt.Sprintf("_%s_del", migrationContext.OriginalTableName))
102+
require.Equal(t, fmt.Sprintf("_%s_del", migrationContext.OriginalTableName), split[1])
103103
case "GH_OST_PROGRESS":
104104
progress, _ := strconv.ParseFloat(split[1], 64)
105-
tests.S(t).ExpectEquals(progress, 50.0)
105+
require.Equal(t, 50.0, progress)
106106
case "GH_OST_TABLE_NAME":
107-
tests.S(t).ExpectEquals(split[1], migrationContext.OriginalTableName)
107+
require.Equal(t, migrationContext.OriginalTableName, split[1])
108108
case "TEST":
109-
tests.S(t).ExpectEquals(split[1], t.Name())
109+
require.Equal(t, t.Name(), split[1])
110110
}
111111
}
112112
})

0 commit comments

Comments
 (0)