diff --git a/CHANGELOG.md b/CHANGELOG.md index 8750999c..9eed8490 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,3 +58,4 @@ - [4473](https://github.com/beego/beego/pull/4473) - [4474](https://github.com/beego/beego/pull/4474) - [4479](https://github.com/beego/beego/pull/4479) +- [4639](https://github.com/beego/beego/pull/4639) diff --git a/client/cache/calc_utils.go b/client/cache/calc_utils.go index 417f8337..f8b7f24a 100644 --- a/client/cache/calc_utils.go +++ b/client/cache/calc_utils.go @@ -12,6 +12,11 @@ var ( ErrNotIntegerType = berror.Error(NotIntegerType, "item val is not (u)int (u)int32 (u)int64") ) +const ( + MinUint32 uint32 = 0 + MinUint64 uint64 = 0 +) + func incr(originVal interface{}) (interface{}, error) { switch val := originVal.(type) { case int: @@ -75,12 +80,12 @@ func decr(originVal interface{}) (interface{}, error) { } return val - 1, nil case uint32: - if val == 0 { + if val == MinUint32 { return nil, ErrDecrementOverflow } return val - 1, nil case uint64: - if val == 0 { + if val == MinUint64 { return nil, ErrDecrementOverflow } return val - 1, nil diff --git a/client/orm/clauses/order_clause/order_test.go b/client/orm/clauses/order_clause/order_test.go index 172e7492..7854948e 100644 --- a/client/orm/clauses/order_clause/order_test.go +++ b/client/orm/clauses/order_clause/order_test.go @@ -120,25 +120,21 @@ func TestOrder_GetColumn(t *testing.T) { } } -func TestOrder_GetSort(t *testing.T) { - o := Clause( - SortDescending(), - ) - if o.GetSort() != Descending { - t.Error() - } -} +func TestSortString(t *testing.T) { + template := "got: %s, want: %s" -func TestOrder_IsRaw(t *testing.T) { - o1 := Clause() - if o1.IsRaw() { - t.Error() + o1 := Clause(sort(Sort(1))) + if o1.SortString() != "ASC" { + t.Errorf(template, o1.SortString(), "ASC") } - o2 := Clause( - Raw(), - ) - if !o2.IsRaw() { - t.Error() + o2 := Clause(sort(Sort(2))) + if o2.SortString() != "DESC" { + t.Errorf(template, o2.SortString(), "DESC") + } + + o3 := Clause(sort(Sort(3))) + if o3.SortString() != `` { + t.Errorf(template, o3.SortString(), ``) } } diff --git a/client/orm/orm_test.go b/client/orm/orm_test.go index 58f2a597..5ded367a 100644 --- a/client/orm/orm_test.go +++ b/client/orm/orm_test.go @@ -1845,17 +1845,12 @@ func TestRawQueryRow(t *testing.T) { case "id": throwFail(t, AssertIs(id, 1)) break - case "time": + case "time", "datetime": v = v.(time.Time).In(DefaultTimeLoc) value := dataValues[col].(time.Time).In(DefaultTimeLoc) assert.True(t, v.(time.Time).Sub(value) <= time.Second) break case "date": - case "datetime": - v = v.(time.Time).In(DefaultTimeLoc) - value := dataValues[col].(time.Time).In(DefaultTimeLoc) - assert.True(t, v.(time.Time).Sub(value) <= time.Second) - break default: throwFail(t, AssertIs(v, dataValues[col])) } @@ -2769,6 +2764,7 @@ func TestStrPkInsert(t *testing.T) { fmt.Println(err) if err.Error() == "postgres version must 9.5 or higher" || err.Error() == "`sqlite3` nonsupport InsertOrUpdate in beego" { } else if err == ErrLastInsertIdUnavailable { + return } else { throwFailNow(t, err) }