Fix test
This commit is contained in:
parent
63f54e633a
commit
c4b5433155
|
@ -635,12 +635,14 @@ func (d *ZDecimal) FromDB(data []byte) error {
|
|||
func (d ZDecimal) ToDB() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf("%d", (d.value).Int64())), nil
|
||||
}
|
||||
|
||||
func (d ZDecimal) IsZero() bool {
|
||||
if d.value == nil {
|
||||
return true
|
||||
}
|
||||
return d.value.Sign() == 0
|
||||
}
|
||||
|
||||
func (d ZDecimal) String() string {
|
||||
if d.value == nil {
|
||||
return "0"
|
||||
|
@ -649,16 +651,16 @@ func (d ZDecimal) String() string {
|
|||
}
|
||||
|
||||
func TestZDecimal(t *testing.T) {
|
||||
type MyMoney struct {
|
||||
type ZMyMoney struct {
|
||||
Id int64
|
||||
Account string
|
||||
Amount ZDecimal
|
||||
}
|
||||
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(MyMoney))
|
||||
assertSync(t, new(ZMyMoney))
|
||||
|
||||
_, err := testEngine.Insert(&MyMoney{
|
||||
_, err := testEngine.Insert(&ZMyMoney{
|
||||
Account: "test",
|
||||
Amount: ZDecimal{
|
||||
value: big.NewInt(10000000000000000),
|
||||
|
@ -666,19 +668,19 @@ func TestZDecimal(t *testing.T) {
|
|||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
var m = MyMoney{
|
||||
m := ZMyMoney{
|
||||
Id: 1,
|
||||
}
|
||||
has, err := testEngine.Get(&m)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
|
||||
_, err = testEngine.Update(&MyMoney{
|
||||
_, err = testEngine.Update(&ZMyMoney{
|
||||
Id: 1,
|
||||
Account: "test2",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
var m2 = MyMoney{
|
||||
m2 := ZMyMoney{
|
||||
Id: 1,
|
||||
}
|
||||
has, err = testEngine.Get(&m2)
|
||||
|
@ -688,5 +690,4 @@ func TestZDecimal(t *testing.T) {
|
|||
assert.Equal(t, "test2", "test2")
|
||||
assert.False(t, m.Amount.IsZero())
|
||||
assert.Equal(t, "10000000000000000", m.Amount.String())
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue