Skip to content

Commit

Permalink
expression: fix test cases in TestWrapWithCastAsTime and TestCompareB…
Browse files Browse the repository at this point in the history
…uiltin (pingcap#6024)

Those test cases use wrong timezone, they will fail when TimeZone set to Tokyo
and time.Now() is 01:04
  • Loading branch information
tiancaiamao authored and ngaut committed Mar 12, 2018
1 parent ef9745b commit a239b77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions expression/builtin_cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,13 @@ func (s *testEvaluatorSuite) TestWrapWithCastAsTypesClasses(c *C) {
}

func (s *testEvaluatorSuite) TestWrapWithCastAsTime(c *C) {
defer testleak.AfterTest(c)()
sc := s.ctx.GetSessionVars().StmtCtx
save := sc.TimeZone
sc.TimeZone = time.UTC
defer func() {
testleak.AfterTest(c)()
sc.TimeZone = save
}()
cases := []struct {
expr Expression
tp *types.FieldType
Expand Down Expand Up @@ -1188,13 +1194,13 @@ func (s *testEvaluatorSuite) TestWrapWithCastAsTime(c *C) {
tm,
},
}
for _, t := range cases {
for d, t := range cases {
expr := WrapWithCastAsTime(s.ctx, t.expr, t.tp)
res, isNull, err := expr.EvalTime(s.ctx, nil)
c.Assert(err, IsNil)
c.Assert(isNull, Equals, false)
c.Assert(res.Type, Equals, t.tp.Tp)
c.Assert(res.Compare(t.res), Equals, 0)
c.Assert(res.Compare(t.res), Equals, 0, Commentf("case %d res = %s, expect = %s", d, res, t.res))
}
}

Expand Down
2 changes: 1 addition & 1 deletion expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2603,7 +2603,7 @@ func (s *testIntegrationSuite) TestCompareBuiltin(c *C) {
tk.MustExec(`insert into t2 values(1, 1.1, "2017-08-01 12:01:01", "12:01:01", "abcdef", 0b10101)`)

result = tk.MustQuery("select coalesce(NULL, a), coalesce(NULL, b, a), coalesce(c, NULL, a, b), coalesce(d, NULL), coalesce(d, c), coalesce(NULL, NULL, e, 1), coalesce(f), coalesce(1, a, b, c, d, e, f) from t2")
result.Check(testkit.Rows(fmt.Sprintf("1 1.1 2017-08-01 12:01:01 12:01:01 %s 12:01:01 abcdef 21 1", time.Now().In(time.UTC).Format("2006-01-02"))))
result.Check(testkit.Rows(fmt.Sprintf("1 1.1 2017-08-01 12:01:01 12:01:01 %s 12:01:01 abcdef 21 1", time.Now().In(tk.Se.GetSessionVars().GetTimeZone()).Format("2006-01-02"))))

// nullif
result = tk.MustQuery(`SELECT NULLIF(NULL, 1), NULLIF(1, NULL), NULLIF(1, 1), NULLIF(NULL, NULL);`)
Expand Down

0 comments on commit a239b77

Please sign in to comment.