Skip to content

Commit

Permalink
fix cockroachdb tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoLiberali committed Jan 2, 2024
1 parent 965d6bd commit 9502306
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
8 changes: 0 additions & 8 deletions condition/field_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,21 @@ func (value NumericFieldValue[TModel, TAttribute]) getType() numeric {
}

// Plus sums other to value
//
// Warning: in PostgreSQL the value received by parameter could be casted to integer
func (value *NumericFieldValue[TModel, TAttribute]) Plus(other float64) *NumericFieldValue[TModel, TAttribute] {
return value.addOperation(other, "+")
}

// Minus subtracts other from the value
//
// Warning: in PostgreSQL the value received by parameter could be casted to integer
func (value *NumericFieldValue[TModel, TAttribute]) Minus(other float64) *NumericFieldValue[TModel, TAttribute] {
return value.addOperation(other, "-")
}

// Times multiplies value by other
//
// Warning: in PostgreSQL the value received by parameter could be casted to integer
func (value *NumericFieldValue[TModel, TAttribute]) Times(other float64) *NumericFieldValue[TModel, TAttribute] {
return value.addOperation(other, "*")
}

// Divided divides value by other
//
// Warning: in PostgreSQL the value received by parameter could be casted to integer
func (value *NumericFieldValue[TModel, TAttribute]) Divided(other float64) *NumericFieldValue[TModel, TAttribute] {
return value.addOperation(other, "/")
}
Expand Down
30 changes: 19 additions & 11 deletions test/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,18 +702,26 @@ func (ts *UpdateIntTestSuite) TestUpdateDynamicWithFunction() {
ts.db,
conditions.Product.Bool.Is().False(),
).Set(
conditions.Product.Int.Set().Dynamic(conditions.Product.Float.Value().Plus(1)),
conditions.Product.Int.Set().Dynamic(conditions.Product.Float.Value().Plus(1.1)),
)
ts.Require().NoError(err)
ts.Equal(int64(1), updated)

productReturned, err := cql.Query[models.Product](
ts.db,
conditions.Product.Int.Is().Eq(2),
).FindOne()
ts.Require().NoError(err)
if getDBDialector() == cqlSQL.Postgres && err != nil {
// cockroachdb
ts.ErrorContains(err, "unsupported binary operator: <decimal> + <anyelement> (desired <int>) (SQLSTATE 22023); method: Set")
} else {
ts.Require().NoError(err)
ts.Equal(int64(1), updated)

productReturned, err := cql.Query[models.Product](
ts.db,
conditions.Product.Int.Is().Eq(2),
).FindOne()

ts.Require().NoError(err)

ts.Equal(product1.ID, productReturned.ID)
ts.Equal(2, productReturned.Int)
ts.NotEqual(product1.UpdatedAt.UnixMicro(), productReturned.UpdatedAt.UnixMicro())
}

Check failure on line 726 in test/update_test.go

View workflow job for this annotation

GitHub Actions / Code style

File is not `gofumpt`-ed (gofumpt)
ts.Equal(product1.ID, productReturned.ID)
ts.Equal(2, productReturned.Int)
ts.NotEqual(product1.UpdatedAt.UnixMicro(), productReturned.UpdatedAt.UnixMicro())
}

Check failure on line 727 in test/update_test.go

View workflow job for this annotation

GitHub Actions / Code style

block should not end with a whitespace (or comment) (wsl)

0 comments on commit 9502306

Please sign in to comment.