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 <mvasek@redhat.com>
  • Loading branch information
matejvasek committed Nov 1, 2023
1 parent 2ba9004 commit 3119564
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pkg/pipelines/tekton/task_defs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package tekton_test

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) {

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 3119564

Please sign in to comment.