Skip to content

Commit

Permalink
planner/implementation: migrate test-infra to testify (#26910)
Browse files Browse the repository at this point in the history
  • Loading branch information
yedamao authored Aug 9, 2021
1 parent 2079700 commit 880c9b5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
43 changes: 8 additions & 35 deletions planner/implementation/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,22 @@ package implementation
import (
"testing"

. "github.com/pingcap/check"
"github.com/pingcap/parser"
"github.com/pingcap/parser/model"
"github.com/pingcap/tidb/infoschema"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/planner/memo"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/util/testleak"
"github.com/stretchr/testify/require"
)

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

var _ = Suite(&testImplSuite{})

type testImplSuite struct {
*parser.Parser
is infoschema.InfoSchema
sctx sessionctx.Context
}

func (s *testImplSuite) SetUpSuite(c *C) {
testleak.BeforeTest()
s.is = infoschema.MockInfoSchema([]*model.TableInfo{plannercore.MockSignedTable()})
s.sctx = plannercore.MockContext()
s.Parser = parser.New()
}

func (s *testImplSuite) TearDownSuite(c *C) {
testleak.AfterTest(c)()
}
func TestBaseImplementation(t *testing.T) {

func (s *testImplSuite) TestBaseImplementation(c *C) {
p := plannercore.PhysicalLimit{}.Init(s.sctx, nil, 0, nil)
sctx := plannercore.MockContext()
p := plannercore.PhysicalLimit{}.Init(sctx, nil, 0, nil)
impl := &baseImpl{plan: p}
c.Assert(impl.GetPlan(), Equals, p)
require.Equal(t, p, impl.GetPlan())

cost := impl.CalcCost(10, []memo.Implementation{}...)
c.Assert(cost, Equals, 0.0)
c.Assert(impl.GetCost(), Equals, 0.0)
require.Equal(t, 0.0, cost)
require.Equal(t, 0.0, impl.GetCost())

impl.SetCost(6.0)
c.Assert(impl.GetCost(), Equals, 6.0)
require.Equal(t, 6.0, impl.GetCost())
}
26 changes: 26 additions & 0 deletions planner/implementation/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 implementation

import (
"testing"

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

func TestMain(m *testing.M) {
testbridge.WorkaroundGoCheckFlags()
goleak.VerifyTestMain(m)
}

0 comments on commit 880c9b5

Please sign in to comment.