Exemplo n.º 1
0
// limitations under the License.

package types

import (
	"math"
	"time"

	"fmt"

	"github.com/pingcap/check"
	"github.com/pingcap/tidb/mysql"
	"github.com/pingcap/tidb/util/charset"
)

var _ = check.Suite(&testTypeConvertSuite{})

type testTypeConvertSuite struct {
}

type invalidMockType struct {
}

func (s *testTypeConvertSuite) TestConvertType(c *check.C) {
	ft := NewFieldType(mysql.TypeBlob)
	ft.Flen = 4
	ft.Charset = "utf8"
	v, err := Convert("123456", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, "1234")
	ft = NewFieldType(mysql.TypeString)
Exemplo n.º 2
0
//
//     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 types

import (
	"github.com/pingcap/check"
	"github.com/pingcap/tidb/mysql"
)

var _ = check.Suite(&testFieldTypeSuite{})

type testFieldTypeSuite struct {
}

func (s *testFieldTypeSuite) TestFieldType(c *check.C) {
	ft := NewFieldType(mysql.TypeDuration)
	c.Assert(ft.Flen, check.Equals, UnspecifiedLength)
	c.Assert(ft.Decimal, check.Equals, UnspecifiedLength)
	ft.Decimal = 5
	c.Assert(ft.String(), check.Equals, "time(5)")

	ft.Tp = mysql.TypeLong
	ft.Flag |= mysql.UnsignedFlag | mysql.ZerofillFlag
	c.Assert(ft.String(), check.Equals, "int(5) UNSIGNED ZEROFILL")
Exemplo n.º 3
0
package distinct

import (
	"testing"

	"github.com/pingcap/check"
	"github.com/pingcap/tidb/util/testleak"
)

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

var _ = check.Suite(&testDistinctSuite{})

type testDistinctSuite struct {
}

func (s *testDistinctSuite) TestDistinct(c *check.C) {
	defer testleak.AfterTest(c)()
	dc := CreateDistinctChecker()
	cases := []struct {
		vals   []interface{}
		expect bool
	}{
		{[]interface{}{1, 1}, true},
		{[]interface{}{1, 1}, false},
		{[]interface{}{1, 2}, true},
		{[]interface{}{1, 2}, false},
Exemplo n.º 4
0
import (
	"fmt"
	"github.com/pingcap/check"
	"log"
	"os"
	"regexp"
	"strings"
)

// -----------------------------------------------------------------------
// Foundation test suite.

type FoundationS struct{}

var foundationS = check.Suite(&FoundationS{})

func (s *FoundationS) TestCountSuite(c *check.C) {
	suitesRun += 1
}

func (s *FoundationS) TestErrorf(c *check.C) {
	// Do not use checkState() here.  It depends on Errorf() working.
	expectedLog := fmt.Sprintf("foundation_test.go:%d:\n"+
		"    c.Errorf(\"Error %%v!\", \"message\")\n"+
		"... Error: Error message!\n\n",
		getMyLine()+1)
	c.Errorf("Error %v!", "message")
	failed := c.Failed()
	c.Succeed()
	if log := c.GetTestLog(); log != expectedLog {
Exemplo n.º 5
0
import (
	"io"
	"reflect"
	"testing"
	"time"

	"github.com/pingcap/check"
	"github.com/pingcap/tidb/mysql"
)

func TestT(t *testing.T) {
	check.TestingT(t)
}

var _ = check.Suite(&testTypeEtcSuite{})

type testTypeEtcSuite struct {
}

func testIsTypeBlob(c *check.C, tp byte, expect bool) {
	v := IsTypeBlob(tp)
	c.Assert(v, check.Equals, expect)
}

func testIsTypeChar(c *check.C, tp byte, expect bool) {
	v := IsTypeChar(tp)
	c.Assert(v, check.Equals, expect)
}

func (s *testTypeEtcSuite) TestIsType(c *check.C) {
Exemplo n.º 6
0
// somehow isn't working! :-)
//
// Do not assume *any* internal functionality works as expected besides
// what's actually tested here.

package check_test

import (
	"fmt"
	"github.com/pingcap/check"
	"strings"
)

type BootstrapS struct{}

var boostrapS = check.Suite(&BootstrapS{})

func (s *BootstrapS) TestCountSuite(c *check.C) {
	suitesRun += 1
}

func (s *BootstrapS) TestFailedAndFail(c *check.C) {
	if c.Failed() {
		critical("c.Failed() must be false first!")
	}
	c.Fail()
	if !c.Failed() {
		critical("c.Fail() didn't put the test in a failed state!")
	}
	c.Succeed()
}
Exemplo n.º 7
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 types

import (
	"time"

	"github.com/pingcap/check"
	"github.com/pingcap/tidb/mysql"
)

var _ = check.Suite(&testCompareSuite{})

type testCompareSuite struct {
}

func (s *testCompareSuite) TestCompare(c *check.C) {
	cmpTbl := []struct {
		lhs interface{}
		rhs interface{}
		ret int // 0, 1, -1
	}{
		{float64(1), float64(1), 0},
		{float64(1), "1", 0},
		{int64(1), int64(1), 0},
		{int64(-1), uint64(1), -1},
		{int64(-1), "-1", 0},
Exemplo n.º 8
0
package check_test

import (
	"errors"
	"github.com/pingcap/check"
	"reflect"
	"runtime"
)

type CheckersS struct{}

var _ = check.Suite(&CheckersS{})

func testInfo(c *check.C, checker check.Checker, name string, paramNames []string) {
	info := checker.Info()
	if info.Name != name {
		c.Fatalf("Got name %s, expected %s", info.Name, name)
	}
	if !reflect.DeepEqual(info.Params, paramNames) {
		c.Fatalf("Got param names %#v, expected %#v", info.Params, paramNames)
	}
}

func testCheck(c *check.C, checker check.Checker, result bool, error string, params ...interface{}) ([]interface{}, []string) {
	info := checker.Info()
	if len(params) != len(info.Params) {
		c.Fatalf("unexpected param count in test; expected %d got %d", len(info.Params), len(params))
	}
	names := append([]string{}, info.Params...)
	result_, error_ := checker.Check(params, names)
	if result_ != result || error_ != error {
Exemplo n.º 9
0
// These tests verify the inner workings of the helper methods associated
// with check.T.

package check_test

import (
	"github.com/pingcap/check"
	"os"
	"reflect"
	"runtime"
	"sync"
)

var helpersS = check.Suite(&HelpersS{})

type HelpersS struct{}

func (s *HelpersS) TestCountSuite(c *check.C) {
	suitesRun += 1
}

// -----------------------------------------------------------------------
// Fake checker and bug info to verify the behavior of Assert() and Check().

type MyChecker struct {
	info   *check.CheckerInfo
	params []interface{}
	names  []string
	result bool
	error  string
}
Exemplo n.º 10
0
//     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 types

import (
	"math"

	"github.com/pingcap/check"
)

var _ = check.Suite(&testOverflowSuite{})

type testOverflowSuite struct {
}

func (s *testOverflowSuite) TestAdd(c *check.C) {
	tblUint64 := []struct {
		lsh      uint64
		rsh      uint64
		ret      uint64
		overflow bool
	}{
		{math.MaxUint64, 1, 0, true},
		{math.MaxUint64, 0, math.MaxUint64, false},
		{1, 1, 2, false},
	}
Exemplo n.º 11
0
package mysql

import (
	"testing"

	"github.com/pingcap/check"
)

func Test(t *testing.T) {
	check.TestingT(t)
}

type mysqlTestSuite struct {
}

var _ = check.Suite(&mysqlTestSuite{})

func (s *mysqlTestSuite) SetUpSuite(c *check.C) {

}

func (s *mysqlTestSuite) TearDownSuite(c *check.C) {

}

func (t *mysqlTestSuite) TestMysqlGTIDInterval(c *check.C) {
	i, err := parseInterval("1-2")
	c.Assert(err, check.IsNil)
	c.Assert(i, check.DeepEquals, Interval{1, 3})

	i, err = parseInterval("1")