From 8d7210c25ae5e93697bed64bf1087db80f1c203b Mon Sep 17 00:00:00 2001 From: Matej Vasek Date: Wed, 1 Nov 2023 14:37:31 +0100 Subject: [PATCH] test: tkn tasks in yaml and Go code as the same Signed-off-by: Matej Vasek --- pkg/pipelines/tekton/task_defs_test.go | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 pkg/pipelines/tekton/task_defs_test.go diff --git a/pkg/pipelines/tekton/task_defs_test.go b/pkg/pipelines/tekton/task_defs_test.go new file mode 100644 index 0000000000..f41d1a9a9e --- /dev/null +++ b/pkg/pipelines/tekton/task_defs_test.go @@ -0,0 +1,52 @@ +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) { + 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) + } + }) + } +}