-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathworkflow_test.go
More file actions
49 lines (40 loc) · 1.66 KB
/
Copy pathworkflow_test.go
File metadata and controls
49 lines (40 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package externalstorage
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"go.temporal.io/sdk/testsuite"
)
func Test_ProcessOrderBatchWorkflow(t *testing.T) {
testSuite := &testsuite.WorkflowTestSuite{}
env := testSuite.NewTestWorkflowEnvironment()
// Real activities, not mocks: generateOrders is deterministic per batchID
// so the workflow's totals can be derived from the same source of truth.
env.RegisterActivity(FetchOrders)
env.RegisterActivity(ProcessOrders)
request := OrderBatchRequest{BatchID: "BATCH-TEST", OrderCount: 10}
env.ExecuteWorkflow(ProcessOrderBatchWorkflow, request)
require.True(t, env.IsWorkflowCompleted())
require.NoError(t, env.GetWorkflowError())
var summary BatchSummary
require.NoError(t, env.GetWorkflowResult(&summary))
// Re-run the activity pipeline directly to compute the expected totals.
// The workflow's BatchSummary must agree with this independent reduction.
orders, err := FetchOrders(context.Background(), request)
require.NoError(t, err)
processed, err := ProcessOrders(context.Background(), orders)
require.NoError(t, err)
var expectedCost, expectedWeight float64
var totalDays int
for _, p := range processed {
expectedCost += p.ShippingCostUSD
expectedWeight += p.TotalWeightKg
totalDays += p.EstimatedDeliveryDays
}
expectedAvg := float64(totalDays) / float64(len(processed))
require.Equal(t, request.BatchID, summary.BatchID)
require.Equal(t, request.OrderCount, summary.OrderCount)
require.InDelta(t, expectedCost, summary.TotalShippingCostUSD, 0.01)
require.InDelta(t, expectedWeight, summary.TotalWeightKg, 0.01)
require.InDelta(t, expectedAvg, summary.AvgDeliveryDays, 0.1)
}