|
1 | 1 | package execution |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "bytes" |
5 | 4 | "encoding/json" |
6 | 5 | "fmt" |
7 | 6 | "io" |
@@ -1330,19 +1329,34 @@ func (mv *monoValentExecution) GetExecutor() (func(pc primitive.IPrimitiveCtx) i |
1330 | 1329 | expectedResponse, isExpectedResponse := m.GetResponse() |
1331 | 1330 | if isExpectedResponse { |
1332 | 1331 | responseTransform, responseTransformExists := expectedResponse.GetTransform() |
1333 | | - if responseTransformExists && responseTransform.GetType() == "golang_template_v0.1.0" { |
| 1332 | + if responseTransformExists { |
1334 | 1333 | input := stdoutStr |
1335 | | - tmpl := responseTransform.GetBody() |
1336 | | - inStream := stream_transform.NewTextReader(bytes.NewBufferString(input)) |
1337 | | - outStream := bytes.NewBuffer(nil) |
1338 | | - tfm, setupErr := stream_transform.NewTemplateStreamTransformer(tmpl, inStream, outStream) |
1339 | | - if setupErr != nil { |
1340 | | - return internaldto.NewErroneousExecutorOutput(fmt.Errorf("template stream transform error: %w", setupErr)) |
| 1334 | + streamTransformerFactory := stream_transform.NewStreamTransformerFactory( |
| 1335 | + responseTransform.GetType(), |
| 1336 | + responseTransform.GetBody(), |
| 1337 | + ) |
| 1338 | + if !streamTransformerFactory.IsTransformable() { |
| 1339 | + return internaldto.NewErroneousExecutorOutput( |
| 1340 | + fmt.Errorf("unsupported template type: %s", responseTransform.GetType()), |
| 1341 | + ) |
1341 | 1342 | } |
1342 | | - if tfErr := tfm.Transform(); tfErr != nil { |
1343 | | - return internaldto.NewErroneousExecutorOutput(fmt.Errorf("failed to transform: %w", tfErr)) |
| 1343 | + tfm, getTfmErr := streamTransformerFactory.GetTransformer(input) |
| 1344 | + if getTfmErr != nil { |
| 1345 | + return internaldto.NewErroneousExecutorOutput( |
| 1346 | + fmt.Errorf("failed to transform: %w", getTfmErr)) |
1344 | 1347 | } |
1345 | | - outputStr := outStream.String() |
| 1348 | + transformError := tfm.Transform() |
| 1349 | + if transformError != nil { |
| 1350 | + return internaldto.NewErroneousExecutorOutput( |
| 1351 | + fmt.Errorf("failed to transform: %w", transformError)) |
| 1352 | + } |
| 1353 | + outStream := tfm.GetOutStream() |
| 1354 | + outputBytes, readErr := io.ReadAll(outStream) |
| 1355 | + if readErr != nil { |
| 1356 | + return internaldto.NewErroneousExecutorOutput( |
| 1357 | + fmt.Errorf("failed to read transformed stream: %w", readErr)) |
| 1358 | + } |
| 1359 | + outputStr := string(outputBytes) |
1346 | 1360 | stdoutStr = outputStr |
1347 | 1361 | } |
1348 | 1362 | } |
|
0 commit comments