Skip to content

Commit

Permalink
test: tkn tasks in yaml and Go code as the same
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Vasek <[email protected]>
  • Loading branch information
matejvasek committed Nov 1, 2023
1 parent 2ba9004 commit 8d7210c
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions pkg/pipelines/tekton/task_defs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package tekton_test

Check failure on line 1 in pkg/pipelines/tekton/task_defs_test.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/pkg/pipelines/tekton/task_defs_test.go b/pkg/pipelines/tekton/task_defs_test.go index f41d1a9..3f7a6e3 100644 --- a/pkg/pipelines/tekton/task_defs_test.go +++ b/pkg/pipelines/tekton/task_defs_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" k8sYaml "k8s.io/apimachinery/pkg/util/yaml" - + "knative.dev/func/pkg/pipelines/tekton" )

import (
"os"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
k8sYaml "k8s.io/apimachinery/pkg/util/yaml"

"knative.dev/func/pkg/pipelines/tekton"
)

func TestTaskMatch(t *testing.T) {
for _, tt := range []struct {
path string
task v1beta1.Task
}{
{
path: "../resources/tekton/task/func-buildpacks/0.2/func-buildpacks.yaml",
task: tekton.BuildpackTask,
},
{
path: "../resources/tekton/task/func-s2i/0.2/func-s2i.yaml",
task: tekton.S2ITask,
},
{
path: "../resources/tekton/task/func-deploy/0.1/func-deploy.yaml",
task: tekton.DeployTask,
},
} {
t.Run(tt.task.Name, func(t *testing.T) {
t.Log(tt.task.Name)

f, err := os.Open(tt.path)
if err != nil {
t.Fatal(err)
}
defer f.Close()

dec := k8sYaml.NewYAMLToJSONDecoder(f)
var taskFromYaml v1beta1.Task
err = dec.Decode(&taskFromYaml)
if err != nil {
t.Fatal(err)
}
if d := cmp.Diff(tt.task, taskFromYaml); d != "" {
t.Error("output missmatch (-want, +got):", d)
}
})
}
}

0 comments on commit 8d7210c

Please sign in to comment.