-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add forest validation for pipelines. Fixes #1002 #1063
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
06abfb2
feat: add forest validation for pipelines
dpadhiar eeaaa11
Merge branch 'main' into forest-validation
dpadhiar ec29b86
test: update test case
dpadhiar e8e99dd
feat: update comments and method names
dpadhiar 816178a
feat: add test case for valid pl with multiple sinks/sources
dpadhiar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -163,6 +163,57 @@ var ( | |
}, | ||
}, | ||
} | ||
|
||
testForestPipeline = &dfv1.Pipeline{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-pl", | ||
Namespace: "test-ns", | ||
}, | ||
Spec: dfv1.PipelineSpec{ | ||
Vertices: []dfv1.AbstractVertex{ | ||
{ | ||
Name: "input", | ||
Source: &dfv1.Source{ | ||
UDTransformer: &dfv1.UDTransformer{ | ||
Builtin: &dfv1.Transformer{Name: "filter"}, | ||
}}, | ||
}, | ||
{ | ||
Name: "input-1", | ||
Source: &dfv1.Source{ | ||
UDTransformer: &dfv1.UDTransformer{ | ||
Builtin: &dfv1.Transformer{Name: "filter"}, | ||
}}, | ||
}, | ||
{ | ||
Name: "p1", | ||
UDF: &dfv1.UDF{ | ||
Builtin: &dfv1.Function{Name: "cat"}, | ||
}, | ||
}, | ||
{ | ||
Name: "p2", | ||
UDF: &dfv1.UDF{ | ||
Builtin: &dfv1.Function{Name: "cat"}, | ||
}, | ||
}, | ||
{ | ||
Name: "output", | ||
Sink: &dfv1.Sink{}, | ||
}, | ||
{ | ||
Name: "output-1", | ||
Sink: &dfv1.Sink{}, | ||
}, | ||
}, | ||
Edges: []dfv1.Edge{ | ||
{From: "input", To: "p1"}, | ||
{From: "p1", To: "output"}, | ||
{From: "input-1", To: "p2"}, | ||
{From: "p2", To: "output-1"}, | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
func TestValidatePipeline(t *testing.T) { | ||
|
@@ -273,6 +324,52 @@ func TestValidatePipeline(t *testing.T) { | |
assert.Contains(t, err.Error(), "can not specify both builtin function, and a customized image") | ||
}) | ||
|
||
t.Run("forest - two pipelines with 1 source/sink", func(t *testing.T) { | ||
testObj := testForestPipeline.DeepCopy() | ||
err := ValidatePipeline(testObj) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "invalid pipeline") | ||
}) | ||
|
||
t.Run("forest - second pipeline has no sink", func(t *testing.T) { | ||
testObj := testForestPipeline.DeepCopy() | ||
testObj.Spec.Vertices[5].Sink = nil | ||
testObj.Spec.Vertices[5].UDF = &dfv1.UDF{} | ||
err := ValidatePipeline(testObj) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "invalid vertex") | ||
}) | ||
|
||
t.Run("forest - two pipelines with multiple sources/sinks", func(t *testing.T) { | ||
testObj := testForestPipeline.DeepCopy() | ||
testObj.Spec.Vertices = append(testObj.Spec.Vertices, dfv1.AbstractVertex{Name: "input-2", Source: &dfv1.Source{}}) | ||
testObj.Spec.Vertices = append(testObj.Spec.Vertices, dfv1.AbstractVertex{Name: "output-2", Sink: &dfv1.Sink{}}) | ||
testObj.Spec.Edges = append(testObj.Spec.Edges, dfv1.Edge{From: "input-2", To: "p1"}) | ||
testObj.Spec.Edges = append(testObj.Spec.Edges, dfv1.Edge{From: "p2", To: "output-2"}) | ||
err := ValidatePipeline(testObj) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "invalid pipeline") | ||
}) | ||
|
||
t.Run("forest - pipelines have cycles", func(t *testing.T) { | ||
testObj := testForestPipeline.DeepCopy() | ||
testObj.Spec.Edges = append(testObj.Spec.Edges, dfv1.Edge{From: "p1", To: "p1"}) | ||
testObj.Spec.Edges = append(testObj.Spec.Edges, dfv1.Edge{From: "p2", To: "p2"}) | ||
err := ValidatePipeline(testObj) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "invalid pipeline") | ||
}) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like some good test cases for invalid pipelines. I wonder if we should add one for an "interesting" valid pipeline - something with multiple sources and multiple sinks? |
||
t.Run("valid pipeline with multiple sinks/sources", func(t *testing.T) { | ||
testObj := testPipeline.DeepCopy() | ||
testObj.Spec.Vertices = append(testObj.Spec.Vertices, dfv1.AbstractVertex{Name: "input-1", Source: &dfv1.Source{}}) | ||
testObj.Spec.Vertices = append(testObj.Spec.Vertices, dfv1.AbstractVertex{Name: "output-1", Sink: &dfv1.Sink{}}) | ||
testObj.Spec.Edges = append(testObj.Spec.Edges, dfv1.Edge{From: "input-1", To: "p1"}) | ||
testObj.Spec.Edges = append(testObj.Spec.Edges, dfv1.Edge{From: "p1", To: "output-1"}) | ||
err := ValidatePipeline(testObj) | ||
assert.NoError(t, err) | ||
}) | ||
|
||
t.Run("edge - invalid vertex name", func(t *testing.T) { | ||
testObj := testPipeline.DeepCopy() | ||
testObj.Spec.Edges = append(testObj.Spec.Edges, dfv1.Edge{From: "a", To: "b"}) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be useful to have a comment for this function to go over how it works