Skip to content

Commit

Permalink
util/mock: migrate test-infra to testify (pingcap#26159)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxchan authored Jul 13, 2021
1 parent 93b5df2 commit 54f18d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
26 changes: 26 additions & 0 deletions util/mock/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package mock

import (
"testing"

"github.com/pingcap/tidb/util/testbridge"
"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
testbridge.WorkaroundGoCheckFlags()
goleak.VerifyTestMain(m)
}
22 changes: 6 additions & 16 deletions util/mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,9 @@ package mock
import (
"testing"

. "github.com/pingcap/check"
"github.com/pingcap/tidb/util/testleak"
"github.com/stretchr/testify/assert"
)

func TestT(t *testing.T) {
CustomVerboseFlag = true
TestingT(t)
}

var _ = Suite(&testMockSuite{})

type testMockSuite struct {
}

type contextKeyType int

func (k contextKeyType) String() string {
Expand All @@ -38,17 +27,18 @@ func (k contextKeyType) String() string {

const contextKey contextKeyType = 0

func (s *testMockSuite) TestContext(c *C) {
defer testleak.AfterTest(c)()
func TestContext(t *testing.T) {
t.Parallel()

ctx := NewContext()

ctx.SetValue(contextKey, 1)
v := ctx.Value(contextKey)
c.Assert(v, Equals, 1)
assert.Equal(t, 1, v)

ctx.ClearValue(contextKey)
v = ctx.Value(contextKey)
c.Assert(v, IsNil)
assert.Nil(t, v)
}

func BenchmarkNewContext(b *testing.B) {
Expand Down

0 comments on commit 54f18d5

Please sign in to comment.