-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flytepropeller] Add Tests in v1alpha.go including
array_test.go
, `…
…branch_test.go`, `error_test.go`, and `iface_test.go` with 0.13% Coverage Improvment (#4234) * add flyteworkflow 4 test file Signed-off-by: Future Outlier <[email protected]> * import error Signed-off-by: Future Outlier <[email protected]> * golangci-lint run --fix Signed-off-by: Future Outlier <[email protected]> --------- Signed-off-by: Future Outlier <[email protected]> Co-authored-by: Future Outlier <[email protected]> Co-authored-by: Kevin Su <[email protected]>
- Loading branch information
1 parent
0fc2ab0
commit 033276d
Showing
4 changed files
with
340 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
flytepropeller/pkg/apis/flyteworkflow/v1alpha1/array_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestArrayNodeSpec_GetSubNodeSpec(t *testing.T) { | ||
nodeSpec := &NodeSpec{} | ||
arrayNodeSpec := ArrayNodeSpec{ | ||
SubNodeSpec: nodeSpec, | ||
} | ||
|
||
if arrayNodeSpec.GetSubNodeSpec() != nodeSpec { | ||
t.Errorf("Expected nodeSpec, but got a different value") | ||
} | ||
} | ||
|
||
func TestArrayNodeSpec_GetParallelism(t *testing.T) { | ||
parallelism := uint32(5) | ||
arrayNodeSpec := ArrayNodeSpec{ | ||
Parallelism: parallelism, | ||
} | ||
|
||
if arrayNodeSpec.GetParallelism() != parallelism { | ||
t.Errorf("Expected %d, but got %d", parallelism, arrayNodeSpec.GetParallelism()) | ||
} | ||
} | ||
|
||
func TestArrayNodeSpec_GetMinSuccesses(t *testing.T) { | ||
minSuccesses := uint32(3) | ||
arrayNodeSpec := ArrayNodeSpec{ | ||
MinSuccesses: &minSuccesses, | ||
} | ||
|
||
if *arrayNodeSpec.GetMinSuccesses() != minSuccesses { | ||
t.Errorf("Expected %d, but got %d", minSuccesses, *arrayNodeSpec.GetMinSuccesses()) | ||
} | ||
} | ||
|
||
func TestArrayNodeSpec_GetMinSuccessRatio(t *testing.T) { | ||
minSuccessRatio := float32(0.8) | ||
arrayNodeSpec := ArrayNodeSpec{ | ||
MinSuccessRatio: &minSuccessRatio, | ||
} | ||
|
||
if *arrayNodeSpec.GetMinSuccessRatio() != minSuccessRatio { | ||
t.Errorf("Expected %f, but got %f", minSuccessRatio, *arrayNodeSpec.GetMinSuccessRatio()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
flytepropeller/pkg/apis/flyteworkflow/v1alpha1/error_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core" | ||
) | ||
|
||
func TestExecutionErrorJSONMarshalling(t *testing.T) { | ||
execError := &core.ExecutionError{ | ||
Code: "TestCode", | ||
Message: "Test error message", | ||
ErrorUri: "Test error uri", | ||
} | ||
|
||
execErr := &ExecutionError{ExecutionError: execError} | ||
data, jErr := json.Marshal(execErr) | ||
assert.Nil(t, jErr) | ||
|
||
newExecErr := &ExecutionError{} | ||
uErr := json.Unmarshal(data, newExecErr) | ||
assert.Nil(t, uErr) | ||
|
||
assert.Equal(t, execError.Code, newExecErr.ExecutionError.Code) | ||
assert.Equal(t, execError.Message, newExecErr.ExecutionError.Message) | ||
assert.Equal(t, execError.ErrorUri, newExecErr.ExecutionError.ErrorUri) | ||
} |
186 changes: 186 additions & 0 deletions
186
flytepropeller/pkg/apis/flyteworkflow/v1alpha1/iface_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core" | ||
) | ||
|
||
func TestNodeKindString(t *testing.T) { | ||
tests := []struct { | ||
kind NodeKind | ||
expected string | ||
}{ | ||
{NodeKindTask, "task"}, | ||
{NodeKindBranch, "branch"}, | ||
{NodeKindWorkflow, "workflow"}, | ||
{NodeKindGate, "gate"}, | ||
{NodeKindArray, "array"}, | ||
{NodeKindStart, "start"}, | ||
{NodeKindEnd, "end"}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.expected, func(t *testing.T) { | ||
assert.Equal(t, test.expected, test.kind.String()) | ||
}) | ||
} | ||
} | ||
|
||
func TestNodePhaseString(t *testing.T) { | ||
tests := []struct { | ||
phase NodePhase | ||
expected string | ||
}{ | ||
{NodePhaseNotYetStarted, "NotYetStarted"}, | ||
{NodePhaseQueued, "Queued"}, | ||
{NodePhaseRunning, "Running"}, | ||
{NodePhaseTimingOut, "NodePhaseTimingOut"}, | ||
{NodePhaseTimedOut, "NodePhaseTimedOut"}, | ||
{NodePhaseSucceeding, "Succeeding"}, | ||
{NodePhaseSucceeded, "Succeeded"}, | ||
{NodePhaseFailing, "Failing"}, | ||
{NodePhaseFailed, "Failed"}, | ||
{NodePhaseSkipped, "Skipped"}, | ||
{NodePhaseRetryableFailure, "RetryableFailure"}, | ||
{NodePhaseDynamicRunning, "DynamicRunning"}, | ||
{NodePhaseRecovered, "NodePhaseRecovered"}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.expected, func(t *testing.T) { | ||
assert.Equal(t, test.expected, test.phase.String()) | ||
}) | ||
} | ||
} | ||
|
||
func TestWorkflowPhaseString(t *testing.T) { | ||
tests := []struct { | ||
phase WorkflowPhase | ||
expected string | ||
}{ | ||
{WorkflowPhaseReady, "Ready"}, | ||
{WorkflowPhaseRunning, "Running"}, | ||
{WorkflowPhaseSuccess, "Succeeded"}, | ||
{WorkflowPhaseFailed, "Failed"}, | ||
{WorkflowPhaseFailing, "Failing"}, | ||
{WorkflowPhaseSucceeding, "Succeeding"}, | ||
{WorkflowPhaseAborted, "Aborted"}, | ||
{WorkflowPhaseHandlingFailureNode, "HandlingFailureNode"}, | ||
{-1, "Unknown"}, | ||
// Add more cases as needed | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.expected, func(t *testing.T) { | ||
assert.Equal(t, test.expected, test.phase.String()) | ||
}) | ||
} | ||
} | ||
|
||
func TestBranchNodePhaseString(t *testing.T) { | ||
tests := []struct { | ||
phase BranchNodePhase | ||
expected string | ||
}{ | ||
{BranchNodeNotYetEvaluated, "NotYetEvaluated"}, | ||
{BranchNodeSuccess, "BranchEvalSuccess"}, | ||
{BranchNodeError, "BranchEvalFailed"}, | ||
{-1, "Undefined"}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.expected, func(t *testing.T) { | ||
assert.Equal(t, test.expected, test.phase.String()) | ||
}) | ||
} | ||
} | ||
|
||
func TestWorkflowOnFailurePolicyStringError(t *testing.T) { | ||
_, err := WorkflowOnFailurePolicyString("NON_EXISTENT_POLICY") | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestWorkflowOnFailurePolicyJSONMarshalling(t *testing.T) { | ||
tests := []struct { | ||
policy WorkflowOnFailurePolicy | ||
jsonStr string | ||
}{ | ||
{WorkflowOnFailurePolicy(core.WorkflowMetadata_FAIL_IMMEDIATELY), `"FAIL_IMMEDIATELY"`}, | ||
{WorkflowOnFailurePolicy(core.WorkflowMetadata_FAIL_AFTER_EXECUTABLE_NODES_COMPLETE), `"FAIL_AFTER_EXECUTABLE_NODES_COMPLETE"`}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.jsonStr, func(t *testing.T) { | ||
// Testing marshalling | ||
data, err := json.Marshal(test.policy) | ||
require.NoError(t, err) | ||
assert.Equal(t, test.jsonStr, string(data)) | ||
|
||
// Testing unmarshalling | ||
var unmarshalledPolicy WorkflowOnFailurePolicy | ||
err = json.Unmarshal(data, &unmarshalledPolicy) | ||
require.NoError(t, err) | ||
assert.Equal(t, test.policy, unmarshalledPolicy) | ||
}) | ||
} | ||
|
||
invalidTest := `123` | ||
var policy WorkflowOnFailurePolicy | ||
err := json.Unmarshal([]byte(invalidTest), &policy) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "WorkflowOnFailurePolicy should be a string, got 123") | ||
|
||
} | ||
|
||
func TestGetOutputsFile(t *testing.T) { | ||
tests := []struct { | ||
outputDir DataReference | ||
expected DataReference | ||
}{ | ||
{"dir1", "dir1/outputs.pb"}, | ||
{"dir2", "dir2/outputs.pb"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(string(tt.outputDir), func(t *testing.T) { // Convert DataReference to string here | ||
assert.Equal(t, tt.expected, GetOutputsFile(tt.outputDir)) | ||
}) | ||
} | ||
} | ||
|
||
func TestGetInputsFile(t *testing.T) { | ||
tests := []struct { | ||
inputDir DataReference | ||
expected DataReference | ||
}{ | ||
{"dir1", "dir1/inputs.pb"}, | ||
{"dir2", "dir2/inputs.pb"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(string(tt.inputDir), func(t *testing.T) { | ||
assert.Equal(t, tt.expected, GetInputsFile(tt.inputDir)) | ||
}) | ||
} | ||
} | ||
|
||
func TestGetDeckFile(t *testing.T) { | ||
tests := []struct { | ||
inputDir DataReference | ||
expected DataReference | ||
}{ | ||
{"dir1", "dir1/deck.html"}, | ||
{"dir2", "dir2/deck.html"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(string(tt.inputDir), func(t *testing.T) { | ||
assert.Equal(t, tt.expected, GetDeckFile(tt.inputDir)) | ||
}) | ||
} | ||
} |