(t *testing.T)
| 172 | } |
| 173 | |
| 174 | func TestBatchFlowExecution(t *testing.T) { |
| 175 | batchFlow := pf.NewBatchFlow(simpleLogNode()) // Start node logs based on params |
| 176 | |
| 177 | batchFlow.SetPrepBatch(func(ctx *pf.PfContext, params map[string]any) ([]map[string]any, error) { |
| 178 | // Generate parameter sets for each batch run |
| 179 | return []map[string]any{ |
| 180 | {"multiplier": 2}, |
| 181 | {"multiplier": 4}, |
| 182 | }, nil |
| 183 | }) |
| 184 | |
| 185 | batchFlow.SetPostBatch(func(ctx *pf.PfContext, params map[string]any, batchPrepResult []map[string]any) (string, error) { |
| 186 | // 原代码:ctx["postBatchCalled"] = true |
| 187 | ctx.SetValue("postBatchCalled", true) |
| 188 | assert.Len(t, batchPrepResult, 2, "PostBatch should receive the original prep result") |
| 189 | return "batch_complete", nil |
| 190 | }) |
| 191 | |
| 192 | batchContext := pf.WithParam(context.Background(), nil) |
| 193 | resultAction, err := batchFlow.Run(batchContext) |
| 194 | require.NoError(t, err) |
| 195 | |
| 196 | assert.Equal(t, "batch_complete", resultAction) |
| 197 | assert.True(t, batchContext.Value("postBatchCalled").(bool)) |
| 198 | |
| 199 | // Check that the log messages were stored in the shared context by the simpleLogNode's PostFunc |
| 200 | assert.Equal(t, "SimpleLogNode executed with multiplier: 2", batchContext.Value("last_message_from_batch_2")) |
| 201 | assert.Equal(t, "SimpleLogNode executed with multiplier: 4", batchContext.Value("last_message_from_batch_4")) |
| 202 | } |
| 203 | |
| 204 | // --- Additional Tests --- |
| 205 |
nothing calls this directly
no test coverage detected