コード例 #1
0
ファイル: bootstrap_test.go プロジェクト: ninefive/tidb
func (s *BootstrapS) TestLogAndGetTestLog(c *check.C) {
	c.Log("Hello there!")
	log := c.GetTestLog()
	if log != "Hello there!\n" {
		critical(fmt.Sprintf("Log() or GetTestLog() is not working! Got: %#v", log))
	}
}
コード例 #2
0
ファイル: foundation_test.go プロジェクト: ninefive/tidb
func (s *FoundationS) TestSucceedNow(c *check.C) {
	defer (func() {
		if c.Failed() {
			c.Error("SucceedNow() didn't succeed the test")
		}
		if c.GetTestLog() != "" {
			c.Error("Something got logged:\n" + c.GetTestLog())
		}
	})()

	c.Fail()
	c.SucceedNow()
	c.Log("SucceedNow() didn't stop the test")
}
コード例 #3
0
ファイル: foundation_test.go プロジェクト: ninefive/tidb
func (s *FoundationS) TestFatalf(c *check.C) {
	var line int
	defer (func() {
		if !c.Failed() {
			c.Error("Fatalf() didn't fail the test")
		} else {
			c.Succeed()
			expected := fmt.Sprintf("foundation_test.go:%d:\n"+
				"    c.Fatalf(\"Die %%s!\", \"now\")\n"+
				"... Error: Die now!\n\n",
				line)
			if c.GetTestLog() != expected {
				c.Error("Incorrect log:", c.GetTestLog())
			}
		}
	})()

	line = getMyLine() + 1
	c.Fatalf("Die %s!", "now")
	c.Log("Fatalf() didn't stop the test")
}
コード例 #4
0
ファイル: check_test.go プロジェクト: lovedboy/tidb
func (s *SuccessHelper) TestLogAndSucceed(c *check.C) {
	c.Log("Expected success!")
}
コード例 #5
0
ファイル: check_test.go プロジェクト: lovedboy/tidb
func (s *FailHelper) TestLogAndFail(c *check.C) {
	s.testLine = getMyLine() - 1
	c.Log("Expected failure!")
	c.Fail()
}
コード例 #6
0
ファイル: convert_test.go プロジェクト: astaxie/tidb
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)
	ft.Flen = 4
	ft.Charset = charset.CharsetBin
	v, err = Convert("12345", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.DeepEquals, []byte("1234"))

	ft = NewFieldType(mysql.TypeFloat)
	ft.Flen = 5
	ft.Decimal = 2
	v, err = Convert(111.114, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, float32(111.11))

	ft = NewFieldType(mysql.TypeFloat)
	ft.Flen = 5
	ft.Decimal = 2
	v, err = Convert(999.999, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, float32(999.99))

	ft = NewFieldType(mysql.TypeFloat)
	ft.Flen = 5
	ft.Decimal = 2
	v, err = Convert(-999.999, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, float32(-999.99))

	ft = NewFieldType(mysql.TypeFloat)
	ft.Flen = 5
	ft.Decimal = 2
	v, err = Convert(1111.11, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, float32(999.99))

	ft = NewFieldType(mysql.TypeFloat)
	ft.Flen = 5
	ft.Decimal = 2
	v, err = Convert(999.916, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, float32(999.92))

	ft = NewFieldType(mysql.TypeFloat)
	ft.Flen = 5
	ft.Decimal = 2
	v, err = Convert(999.915, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, float32(999.91))

	ft = NewFieldType(mysql.TypeFloat)
	ft.Flen = 5
	ft.Decimal = 2
	v, err = Convert(999.9155, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, float32(999.92))

	// For TypeBlob
	ft = NewFieldType(mysql.TypeBlob)
	v, err = Convert(&invalidMockType{}, ft)
	c.Assert(err, check.NotNil)

	// Nil
	ft = NewFieldType(mysql.TypeBlob)
	v, err = Convert(nil, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.IsNil)

	// TypeDouble
	ft = NewFieldType(mysql.TypeDouble)
	ft.Flen = 5
	ft.Decimal = 2
	v, err = Convert(999.9155, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, float64(999.92))

	// For TypeString
	ft = NewFieldType(mysql.TypeString)
	ft.Flen = 3
	v, err = Convert("12345", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, "123")
	ft = NewFieldType(mysql.TypeString)
	ft.Flen = 3
	ft.Charset = charset.CharsetBin
	v, err = Convert("12345", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.DeepEquals, []byte("123"))

	// For TypeDuration
	ft = NewFieldType(mysql.TypeDuration)
	ft.Decimal = 3
	v, err = Convert("10:11:12.123456", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v.(mysql.Duration).String(), check.Equals, "10:11:12.123")
	ft.Decimal = 1
	vv, err := Convert(v, ft)
	c.Assert(err, check.IsNil)
	c.Assert(vv.(mysql.Duration).String(), check.Equals, "10:11:12.1")

	vt, err := mysql.ParseTime("2010-10-10 10:11:11.12345", mysql.TypeTimestamp, 2)
	c.Assert(vt.String(), check.Equals, "2010-10-10 10:11:11.12")
	c.Assert(err, check.IsNil)
	v, err = Convert(vt, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v.(mysql.Duration).String(), check.Equals, "10:11:11.1")

	// For mysql.TypeTimestamp, mysql.TypeDatetime, mysql.TypeDate
	ft = NewFieldType(mysql.TypeTimestamp)
	ft.Decimal = 3
	v, err = Convert("2010-10-10 10:11:11.12345", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v.(mysql.Time).String(), check.Equals, "2010-10-10 10:11:11.123")
	ft.Decimal = 1
	vv, err = Convert(v, ft)
	c.Assert(err, check.IsNil)
	c.Assert(vv.(mysql.Time).String(), check.Equals, "2010-10-10 10:11:11.1")

	// For TypeLonglong
	ft = NewFieldType(mysql.TypeLonglong)
	v, err = Convert("100", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, int64(100))
	ft = NewFieldType(mysql.TypeLonglong)
	ft.Flag |= mysql.UnsignedFlag
	v, err = Convert("100", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, uint64(100))

	// For TypeBit
	ft = NewFieldType(mysql.TypeBit)
	ft.Flen = 8
	v, err = Convert("100", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, mysql.Bit{Value: 100, Width: 8})

	v, err = Convert(mysql.Hex{Value: 100}, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, mysql.Bit{Value: 100, Width: 8})

	v, err = Convert(mysql.Bit{Value: 100, Width: 8}, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, mysql.Bit{Value: 100, Width: 8})

	ft.Flen = 1
	v, err = Convert(1, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, mysql.Bit{Value: 1, Width: 1})

	_, err = Convert(2, ft)
	c.Assert(err, check.NotNil)

	ft.Flen = 0
	_, err = Convert(2, ft)
	c.Assert(err, check.NotNil)

	// For TypeNewDecimal
	ft = NewFieldType(mysql.TypeNewDecimal)
	ft.Decimal = 5
	v, err = Convert(3.1415926, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v.(mysql.Decimal).String(), check.Equals, "3.14159")

	// For TypeYear
	ft = NewFieldType(mysql.TypeYear)
	v, err = Convert("2015-11-11", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, int64(2015))
	v, err = Convert(2015, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.Equals, int64(2015))
	v, err = Convert(1800, ft)
	c.Assert(err, check.NotNil)
	dt, err := mysql.ParseDate("2015-11-11")
	c.Assert(err, check.IsNil)
	v, err = Convert(dt, ft)
	c.Assert(v, check.Equals, int64(2015))
	v, err = Convert(mysql.ZeroDuration, ft)
	c.Assert(v, check.Equals, int64(time.Now().Year()))

	// For enum
	ft = NewFieldType(mysql.TypeEnum)
	ft.Elems = []string{"a", "b", "c"}
	v, err = Convert("a", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.DeepEquals, mysql.Enum{Name: "a", Value: 1})
	v, err = Convert(2, ft)
	c.Log(errors.ErrorStack(err))
	c.Assert(err, check.IsNil)
	c.Assert(v, check.DeepEquals, mysql.Enum{Name: "b", Value: 2})
	_, err = Convert("d", ft)
	c.Assert(err, check.NotNil)
	_, err = Convert(4, ft)
	c.Assert(err, check.NotNil)

	ft = NewFieldType(mysql.TypeSet)
	ft.Elems = []string{"a", "b", "c"}
	v, err = Convert("a", ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.DeepEquals, mysql.Set{Name: "a", Value: 1})
	v, err = Convert(2, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.DeepEquals, mysql.Set{Name: "b", Value: 2})
	v, err = Convert(3, ft)
	c.Assert(err, check.IsNil)
	c.Assert(v, check.DeepEquals, mysql.Set{Name: "a,b", Value: 3})
	_, err = Convert("d", ft)
	c.Assert(err, check.NotNil)
	_, err = Convert(9, ft)
	c.Assert(err, check.NotNil)
}