Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: migrate test-infra to testify for explain_unit_test.go #32706

Merged
merged 4 commits into from
Mar 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions executor/explain_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/mock"
"github.com/stretchr/testify/require"
)

var (
Expand All @@ -37,11 +38,11 @@ type mockErrorOperator struct {
closed bool
}

func (e *mockErrorOperator) Open(ctx context.Context) error {
func (e *mockErrorOperator) Open(_ context.Context) error {
return nil
}

func (e *mockErrorOperator) Next(ctx context.Context, req *chunk.Chunk) error {
func (e *mockErrorOperator) Next(_ context.Context, _ *chunk.Chunk) error {
if e.toPanic {
panic("next panic")
} else {
Expand Down Expand Up @@ -76,11 +77,9 @@ func TestExplainAnalyzeInvokeNextAndClose(t *testing.T) {
explainExec.analyzeExec = &mockOpr
tmpCtx := context.Background()
_, err := explainExec.generateExplainInfo(tmpCtx)
require.EqualError(t, err, "next error, close error")
require.True(t, mockOpr.closed)

expectedStr := "next error, close error"
if err != nil && (err.Error() != expectedStr || !mockOpr.closed) {
t.Errorf(err.Error())
}
// mockErrorOperator panic
explainExec = &ExplainExec{
baseExecutor: baseExec,
Expand All @@ -89,13 +88,10 @@ func TestExplainAnalyzeInvokeNextAndClose(t *testing.T) {
mockOpr = mockErrorOperator{baseExec, true, false}
explainExec.analyzeExec = &mockOpr
defer func() {
if panicErr := recover(); panicErr == nil || !mockOpr.closed {
t.Errorf("panic test failed: without panic or close() is not called")
}
panicErr := recover()
require.NotNil(t, panicErr)
require.True(t, mockOpr.closed)
}()

_, err = explainExec.generateExplainInfo(tmpCtx)
if err != nil {
t.Errorf(err.Error())
}
require.FailNow(t, "generateExplainInfo should panic")
}