You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

  1. package test
  2. import (
  3. "testing"
  4. "github.com/gobuffalo/packr/v2"
  5. "github.com/jmoiron/sqlx"
  6. migrate "github.com/rubenv/sql-migrate"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. // AssertUSD asserts pointers to float64, and checks that they are equal
  10. // with a tolerance of 0.01%. After that, the actual value is setted to the expected value
  11. // in order to be able to perform further assertions using the standar assert functions.
  12. func AssertUSD(t *testing.T, expected, actual *float64) {
  13. if actual == nil {
  14. assert.Equal(t, expected, actual)
  15. return
  16. }
  17. if *expected < *actual {
  18. assert.InEpsilon(t, *actual, *expected, 0.0001)
  19. } else if *expected > *actual {
  20. assert.InEpsilon(t, *expected, *actual, 0.0001)
  21. }
  22. *expected = *actual
  23. }
  24. // WipeDB redo all the migrations of the SQL DB (HistoryDB and L2DB),
  25. // efectively recreating the original state
  26. func WipeDB(db *sqlx.DB) {
  27. migrations := &migrate.PackrMigrationSource{
  28. Box: packr.New("hermez-db-migrations", "../db/migrations"),
  29. }
  30. _, err := migrate.Exec(db.DB, "postgres", migrations, migrate.Down)
  31. if err != nil {
  32. panic(err)
  33. }
  34. _, err = migrate.Exec(db.DB, "postgres", migrations, migrate.Up)
  35. if err != nil {
  36. panic(err)
  37. }
  38. }