Skip to content

Commit

Permalink
Add example test for divide task (#13196)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsondav authored May 15, 2024
1 parent 09660df commit 37805cd
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions core/services/pipeline/task.divide_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

bridgesMocks "github.com/smartcontractkit/chainlink/v2/core/bridges/mocks"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
)
Expand Down Expand Up @@ -193,3 +196,38 @@ func TestDivideTask_Overflow(t *testing.T) {
assert.False(t, runInfo.IsRetryable)
require.Equal(t, pipeline.ErrDivisionOverlow, errors.Cause(result.Error))
}

func TestDivide_Example(t *testing.T) {
t.Parallel()

dag := `
ds1 [type=memo value=10000.1234]
ds2 [type=memo value=100]
div_by_ds2 [type=divide divisor="$(ds2)"]
multiply [type=multiply times=10000 index=0]
ds1->div_by_ds2->multiply;
`

db := pgtest.NewSqlxDB(t)
cfg := configtest.NewTestGeneralConfig(t)
btORM := bridgesMocks.NewORM(t)
r, _ := newRunner(t, db, btORM, cfg)

spec := pipeline.Spec{DotDagSource: dag}
vars := pipeline.NewVarsFrom(nil)

lggr := logger.TestLogger(t)
_, trrs, err := r.ExecuteRun(testutils.Context(t), spec, vars, lggr)
require.NoError(t, err)

require.Len(t, trrs, 4)

finalResult := trrs[3]

assert.Nil(t, finalResult.Result.Error)
assert.Equal(t, "1000012.34", finalResult.Result.Value.(decimal.Decimal).String())
}

0 comments on commit 37805cd

Please sign in to comment.