Skip to content

Commit

Permalink
refactor(test-utils): adds support for all variable types in node out…
Browse files Browse the repository at this point in the history
…put (#1252)

Co-authored-by: Saul Piña <[email protected]>
  • Loading branch information
eduwercamacaro and sauljabin authored Jan 17, 2025
1 parent 4a43b5f commit 43c980c
Showing 1 changed file with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.littlehorse.test.internal.step;

import static org.junit.jupiter.api.Assertions.*;

import io.littlehorse.sdk.common.LHLibUtil;
import io.littlehorse.sdk.common.proto.ListTaskRunsRequest;
import io.littlehorse.sdk.common.proto.LittleHorseGrpc.LittleHorseBlockingStub;
Expand Down Expand Up @@ -27,12 +29,10 @@ public void tryExecute(TestExecutionContext context, LittleHorseBlockingStub lhC

TaskRunList taskRuns = lhClient.listTaskRuns(
ListTaskRunsRequest.newBuilder().setWfRunId(wfRunId).build());
if (expectedOutputs.size() != taskRuns.getResultsList().size()) {
throw new StepExecutionException(
id,
context.getWfRunId(),
"Expected %d taskRuns but got %d".formatted(expectedOutputs.size(), taskRuns.getResultsCount()));
}
assertEquals(
expectedOutputs.size(),
taskRuns.getResultsList().size(),
"Expected %d taskRuns but got %d".formatted(expectedOutputs.size(), taskRuns.getResultsCount()));

// Currently, the result of the rpc ListTaskRuns is NOT sorted. It will
// be sorted after LH-152. So for now we manually sort.
Expand All @@ -50,21 +50,50 @@ public void tryExecute(TestExecutionContext context, LittleHorseBlockingStub lhC

for (int i = 0; i < sortedTasks.size(); i++) {
VariableValue taskOutput = sortedTasks.get(i).getAttempts(0).getOutput();

if (!areEqual(taskOutput, expected.get(i))) {
throw new StepExecutionException(id, context.getWfRunId(), "Task outputs didn't match!");
}
areEqual(taskOutput, expected.get(i));
}
}

private boolean areEqual(VariableValue first, VariableValue second) {
if (first.getValueCase() != second.getValueCase()) return false;

private void areEqual(VariableValue first, VariableValue second) {
assertSame(
first.getValueCase(),
second.getValueCase(),
"Expected " + first.getValueCase() + " but got " + second.getValueCase());
Object firstValue;
Object secondValue;
switch (first.getValueCase()) {
case INT:
return first.getInt() == second.getInt();
firstValue = first.getInt();
secondValue = second.getInt();
break;
case STR:
firstValue = first.getStr();
secondValue = second.getStr();
break;
case BOOL:
firstValue = first.getBool();
secondValue = second.getBool();
break;
case BYTES:
firstValue = first.getBytes();
secondValue = second.getBytes();
break;
case DOUBLE:
firstValue = first.getDouble();
secondValue = second.getDouble();
break;
case JSON_ARR:
firstValue = first.getJsonArr();
secondValue = second.getJsonArr();
break;
case JSON_OBJ:
firstValue = first.getJsonObj();
secondValue = second.getJsonObj();
break;
default:
throw new UnsupportedOperationException(
String.format("As of now, %s values are not supported", first.getValueCase()));
}
throw new UnsupportedOperationException("As of now, only INT values are supported");
assertEquals(firstValue, secondValue);
}
}

0 comments on commit 43c980c

Please sign in to comment.