-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added BasicVerifier for Tasks (#1324)
* Added BuildVerifier for Tasks * Added unit test for BuildVerifier Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
- Loading branch information
1 parent
da8b654
commit def4bf4
Showing
4 changed files
with
140 additions
and
2 deletions.
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
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,29 @@ | ||
package task | ||
|
||
import ( | ||
"github.com/kudobuilder/kudo/pkg/engine/task" | ||
|
||
"github.com/kudobuilder/kudo/pkg/kudoctl/packages" | ||
"github.com/kudobuilder/kudo/pkg/kudoctl/packages/verifier" | ||
) | ||
|
||
// BuildVerifier verifies tasks producing errors for tasks referenced in plans that do not exist and warnings for tasks which are not used in a plan | ||
type BuildVerifier struct{} | ||
|
||
func (BuildVerifier) Verify(pf *packages.Files) verifier.Result { | ||
res := verifier.NewResult() | ||
res.Merge(tasksWellDefined(pf)) | ||
return res | ||
} | ||
|
||
func tasksWellDefined(pf *packages.Files) verifier.Result { | ||
result := verifier.NewResult() | ||
for _, tt := range pf.Operator.Tasks { | ||
tt := tt | ||
|
||
if _, err := task.Build(&tt); err != nil { | ||
result.AddErrors(err.Error()) | ||
} | ||
} | ||
return result | ||
} |
108 changes: 108 additions & 0 deletions
108
pkg/kudoctl/packages/verifier/task/verify_build_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,108 @@ | ||
package task | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1" | ||
"github.com/kudobuilder/kudo/pkg/kudoctl/packages" | ||
) | ||
|
||
func TestTaskBasicsVerifier(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
task v1beta1.Task | ||
errors []string | ||
warnings []string | ||
}{ | ||
{name: "An Apply task without resources", task: v1beta1.Task{ | ||
Name: "Task", | ||
Kind: "Apply", | ||
Spec: v1beta1.TaskSpec{}, | ||
}, errors: []string{"task validation error: apply task 'Task' has an empty resource list. if that's what you need, use a Dummy task instead"}, warnings: []string{}}, | ||
{name: "An Apply task with resources", task: v1beta1.Task{ | ||
Name: "Task", | ||
Kind: "Apply", | ||
Spec: v1beta1.TaskSpec{ | ||
ResourceTaskSpec: v1beta1.ResourceTaskSpec{Resources: []string{"someResource"}}, | ||
}, | ||
}, errors: []string{}, warnings: []string{}}, | ||
{name: "An Delete task without resources", task: v1beta1.Task{ | ||
Name: "Task", | ||
Kind: "Delete", | ||
Spec: v1beta1.TaskSpec{}, | ||
}, errors: []string{"task validation error: delete task 'Task' has an empty resource list. if that's what you need, use a Dummy task instead"}, warnings: []string{}}, | ||
{name: "An Delete task with resources", task: v1beta1.Task{ | ||
Name: "Task", | ||
Kind: "Delete", | ||
Spec: v1beta1.TaskSpec{ | ||
ResourceTaskSpec: v1beta1.ResourceTaskSpec{Resources: []string{"someResource"}}, | ||
}, | ||
}, errors: []string{}, warnings: []string{}}, | ||
|
||
// More detailed tests are in engine/task/task_test.go | ||
{name: "An empty pipe task", task: v1beta1.Task{ | ||
Name: "Task", | ||
Kind: "Pipe", | ||
Spec: v1beta1.TaskSpec{}, | ||
}, errors: []string{"task validation error: pipe task has an empty pipe files list"}, warnings: []string{}}, | ||
{name: "A valid pipe task", task: v1beta1.Task{ | ||
Name: "Task", | ||
Kind: "Pipe", | ||
Spec: v1beta1.TaskSpec{ | ||
PipeTaskSpec: v1beta1.PipeTaskSpec{ | ||
Pod: "", | ||
Pipe: []v1beta1.PipeSpec{ | ||
{ | ||
Kind: "ConfigMap", | ||
File: "someFile", | ||
Key: "someKey", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, errors: []string{}, warnings: []string{}}, | ||
} | ||
verifier := BuildVerifier{} | ||
|
||
for _, test := range tests { | ||
test := test | ||
pf := packageFilesFromWithTask(test.task) | ||
res := verifier.Verify(&pf) | ||
|
||
assert.Equal(t, test.errors, res.Errors, test.name) | ||
assert.Equal(t, test.warnings, res.Warnings, test.name) | ||
} | ||
} | ||
|
||
func packageFilesFromWithTask(task v1beta1.Task) packages.Files { | ||
steps := []v1beta1.Step{{ | ||
Name: "cat-in-hat", | ||
Tasks: []string{"thingOne"}, | ||
}, { | ||
Name: "mayham", | ||
Tasks: []string{"thingThree"}, | ||
}} | ||
|
||
phases := []v1beta1.Phase{{ | ||
Name: "parents leave", | ||
Strategy: "serial", | ||
Steps: steps, | ||
}} | ||
|
||
plans := make(map[string]v1beta1.Plan) | ||
plans["boring-rainy"] = v1beta1.Plan{ | ||
Strategy: "serial", | ||
Phases: phases, | ||
} | ||
|
||
operator := packages.OperatorFile{ | ||
Tasks: []v1beta1.Task{task}, | ||
Plans: plans, | ||
} | ||
|
||
return packages.Files{ | ||
Operator: &operator, | ||
} | ||
} |