test: replace pingcap/check with testify#12690
Conversation
Migrate all test files using the github.com/pingcap/check (gocheck) framework to testify across the dm/ and pkg/diff/ packages. - Stateless gocheck suites are flattened into plain func TestX(t *testing.T) functions using testify/require. - Stateful suites (with fields and/or SetUp*/TearDown* lifecycle methods) are converted to stretchr/testify/suite, with assertions via s.Require().*, and a suite.Run entry replacing check.TestingT. - c.MkDir() -> t.TempDir(), check.Commentf -> testify message args, check.ErrorMatches -> require.Error + require.Regexp, and the operand order is swapped for Equals/DeepEquals. - conn.InitMockDB now takes require.TestingT instead of *check.C. - github.com/pingcap/check is dropped from go.mod/go.sum. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. |
|
/check-issue-triage-complete |
There was a problem hiding this comment.
Code Review
This pull request migrates the test suite from github.com/pingcap/check to github.com/stretchr/testify across multiple packages, replacing go-check assertions and suites with testify/require and testify/suite. The review feedback correctly identifies a highly dangerous pattern in info_test.go where &testing.T{} is manually instantiated, which can cause nil pointer dereference panics during test execution. Additionally, several instances of swapped expected and actual arguments in require.Equal assertions were identified in source_converter_test.go and task_converters_test.go that should be corrected to ensure accurate test failure messages.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| func TestMain(m *testing.M) { | ||
| mockCluster := integration.NewClusterV3(&testing.T{}, &integration.ClusterConfig{Size: 1}) | ||
| etcdTestCli = mockCluster.RandClient() | ||
|
|
||
| check.TestingT(t) | ||
| code := m.Run() | ||
|
|
||
| mockCluster.Terminate(&testing.T{}) | ||
| os.Exit(code) | ||
| } |
There was a problem hiding this comment.
Passing &testing.T{} to integration.NewClusterV3 and mockCluster.Terminate is highly dangerous. testing.T is managed by the Go testing framework and should never be instantiated manually. An uninitialized testing.T struct has nil internal fields, which will cause a nil pointer dereference panic if any test helper, logging, or cleanup method is called on it.\n\nInstead of using TestMain with a fake testing.T, consider initializing the cluster lazily inside the test functions using the real t *testing.T provided by the test runner, or use a custom testing.TB implementation that safely discards logs and errors.
|
|
||
| // we only need to make sure the source config that user can see is the same as the source config that user create | ||
| c.Assert(sourceCfg1.String(), check.Equals, sourceCfg2.String()) | ||
| require.Equal(t, sourceCfg2.String(), sourceCfg1.String()) |
There was a problem hiding this comment.
The arguments to require.Equal are swapped. The expected value should be the first argument (sourceCfg1.String()), and the actual value should be the second argument (sourceCfg2.String()). Swapping them ensures that test failure messages are accurate and easy to read.
| require.Equal(t, sourceCfg2.String(), sourceCfg1.String()) | |
| \trequire.Equal(t, sourceCfg1.String(), sourceCfg2.String()) |
| openapiSource2 := SourceCfgToOpenAPISource(OpenAPISourceToSourceCfg(openapiSource1)) | ||
| openapiSource2.Password = openapiSource1.Password // we set passwd to "******" for privacy | ||
| c.Assert(openapiSource1, check.DeepEquals, openapiSource2) | ||
| require.Equal(t, openapiSource2, openapiSource1) |
There was a problem hiding this comment.
The arguments to require.Equal are swapped. The expected value should be the first argument (openapiSource1), and the actual value should be the second argument (openapiSource2). Swapping them ensures that test failure messages are accurate and easy to read.
| require.Equal(t, openapiSource2, openapiSource1) | |
| \trequire.Equal(t, openapiSource1, openapiSource2) |
| require.Len(t, taskList, 1) | ||
| newTask := taskList[0] | ||
| c.Assert(&task, check.DeepEquals, newTask) | ||
| require.Equal(t, newTask, &task) |
There was a problem hiding this comment.
The arguments to require.Equal are swapped. The expected value should be the first argument (&task), and the actual value should be the second argument (newTask). Swapping them ensures that test failure messages are accurate and easy to read.
| require.Equal(t, newTask, &task) | |
| \trequire.Equal(t, &task, newTask) |
| } | ||
|
|
||
| c.Assert(&task, check.DeepEquals, newTask) | ||
| require.Equal(t, newTask, &task) |
There was a problem hiding this comment.
The arguments to require.Equal are swapped. The expected value should be the first argument (&task), and the actual value should be the second argument (newTask). Swapping them ensures that test failure messages are accurate and easy to read.
| require.Equal(t, newTask, &task) | |
| \trequire.Equal(t, &task, newTask) |
…heck-with-testify
|
/retest |
1 similar comment
|
/retest |
Fix the failures that pull-verify found in dm_unit_test_in_verify_ci: - dm/master, dm/relay: patterns with a leading bare '*' compiled under pingcap/check because ErrorMatches prepends '^', but panic in require.Regexp which uses the pattern verbatim. Anchor with '.*'. - dm/pkg/shardddl/optimism: parse the testing flags in TestMain before integration.NewClusterV3, which consults testing.Short and panics if flags are not parsed yet. - dm/syncer/dbconn: skip the suite when no upstream MySQL is reachable. The check.Suite was never run (no check.TestingT in the package), so the migrated suite ran for the first time in CI and tried to connect to a real MySQL on 127.0.0.1:3306. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
/test pull-error-log-review |
|
/override pull-error-log-review |
|
@wuhuizuo: wuhuizuo unauthorized: /override is restricted to Repo administrators, and the following github teams:. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/override pull-error-log-review |
|
@wuhuizuo: Overrode contexts on behalf of wuhuizuo: pull-error-log-review DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/cc @OliverS929 @kennytm |
|
/retest |
What problem does this PR solve?
Issue Number: close #12689
What is changed and how it works?
Migrate all test files using the github.com/pingcap/check (gocheck) framework to testify across the dm/ and pkg/diff/ packages.
Co-Authored-By: Claude Opus 4.8 (1M context)
Check List
Tests
Questions
Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?
Release note