From 13749f6cc31f2ff0b4041f856813c1e768fc2ec2 Mon Sep 17 00:00:00 2001 From: Thibault Gagnaux Date: Thu, 5 Dec 2024 10:08:31 +0100 Subject: [PATCH] refactor: use gopkg.in/yaml.v2 for validation instead of k8s.io/apimachinery/pkg/util/yaml. --- pkg/provider/bitbucketcloud/bitbucket_test.go | 4 ++-- pkg/provider/bitbucketserver/bitbucketserver_test.go | 2 +- pkg/provider/gitea/gitea_test.go | 4 ++-- pkg/provider/github/github_test.go | 4 ++-- pkg/provider/gitlab/gitlab_test.go | 4 ++-- pkg/provider/provider.go | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/provider/bitbucketcloud/bitbucket_test.go b/pkg/provider/bitbucketcloud/bitbucket_test.go index ca044ee34..98c4584df 100644 --- a/pkg/provider/bitbucketcloud/bitbucket_test.go +++ b/pkg/provider/bitbucketcloud/bitbucket_test.go @@ -59,7 +59,7 @@ func TestGetTektonDir(t *testing.T) { name: "Bad yaml files in there", event: bbcloudtest.MakeEvent(nil), testDirPath: "../../pipelineascode/testdata/bad_yaml/.tekton", - wantErr: "error unmarshalling yaml file .tekton/badyaml.yaml: error converting YAML to JSON: yaml: line 2: did not find expected key", + wantErr: "error unmarshalling yaml file .tekton/badyaml.yaml: yaml: line 2: did not find expected key", }, { name: "No yaml files in there", @@ -80,7 +80,7 @@ func TestGetTektonDir(t *testing.T) { content, err := v.GetTektonDir(ctx, tt.event, ".tekton", tt.provenance) if tt.wantErr != "" { assert.Assert(t, err != nil, "expected error %s, got %v", tt.wantErr, err) - assert.Equal(t, err.Error(), tt.wantErr) + assert.ErrorContains(t, err, tt.wantErr) return } if tt.contentContains == "" { diff --git a/pkg/provider/bitbucketserver/bitbucketserver_test.go b/pkg/provider/bitbucketserver/bitbucketserver_test.go index c2241b981..de872060c 100644 --- a/pkg/provider/bitbucketserver/bitbucketserver_test.go +++ b/pkg/provider/bitbucketserver/bitbucketserver_test.go @@ -54,7 +54,7 @@ func TestGetTektonDir(t *testing.T) { event: bbtest.MakeEvent(nil), path: ".tekton", testDirPath: "../../pipelineascode/testdata/bad_yaml/.tekton", - wantErr: "error unmarshalling yaml file .tekton/badyaml.yaml: error converting YAML to JSON: yaml: line 2: did not find expected key", + wantErr: "error unmarshalling yaml file .tekton/badyaml.yaml: yaml: line 2: did not find expected key", }, } for _, tt := range tests { diff --git a/pkg/provider/gitea/gitea_test.go b/pkg/provider/gitea/gitea_test.go index f0b4193e6..5e0a934d0 100644 --- a/pkg/provider/gitea/gitea_test.go +++ b/pkg/provider/gitea/gitea_test.go @@ -492,7 +492,7 @@ func TestGetTektonDir(t *testing.T) { SHA: "123", }, treepath: "testdata/tree/badyaml", - wantErr: "error unmarshalling yaml file badyaml.yaml: error converting YAML to JSON: yaml: line 2: did not find expected key", + wantErr: "error unmarshalling yaml file badyaml.yaml: yaml: line 2: did not find expected key", }, } for _, tt := range testGetTektonDir { @@ -517,7 +517,7 @@ func TestGetTektonDir(t *testing.T) { got, err := gvcs.GetTektonDir(ctx, tt.event, ".tekton", tt.provenance) if tt.wantErr != "" { assert.Assert(t, err != nil, "we should have get an error here") - assert.Equal(t, tt.wantErr, err.Error()) + assert.ErrorContains(t, err, tt.wantErr) return } assert.NilError(t, err) diff --git a/pkg/provider/github/github_test.go b/pkg/provider/github/github_test.go index c04443c9d..f456e4492 100644 --- a/pkg/provider/github/github_test.go +++ b/pkg/provider/github/github_test.go @@ -275,7 +275,7 @@ func TestGetTektonDir(t *testing.T) { }, expectedString: "FROMSUBTREE", treepath: "testdata/tree/badyaml", - wantErr: "error unmarshalling yaml file badyaml.yaml: error converting YAML to JSON: yaml: line 2: did not find expected key", + wantErr: "error unmarshalling yaml file badyaml.yaml: yaml: line 2: did not find expected key", }, } for _, tt := range testGetTektonDir { @@ -300,7 +300,7 @@ func TestGetTektonDir(t *testing.T) { got, err := gvcs.GetTektonDir(ctx, tt.event, ".tekton", tt.provenance) if tt.wantErr != "" { assert.Assert(t, err != nil, "we should have get an error here") - assert.Equal(t, tt.wantErr, err.Error()) + assert.ErrorContains(t, err, tt.wantErr) return } assert.NilError(t, err) diff --git a/pkg/provider/gitlab/gitlab_test.go b/pkg/provider/gitlab/gitlab_test.go index b678a92b0..9265b15a8 100644 --- a/pkg/provider/gitlab/gitlab_test.go +++ b/pkg/provider/gitlab/gitlab_test.go @@ -314,7 +314,7 @@ func TestGetTektonDir(t *testing.T) { sourceProjectID: 10, }, prcontent: "bad:\n- yaml\nfoo", - wantErr: "error unmarshalling yaml file pr.yaml: error converting YAML to JSON: yaml: line 4: could not find expected ':'", + wantErr: "error unmarshalling yaml file pr.yaml: yaml: line 4: could not find expected ':'", }, { name: "list tekton dir", @@ -392,7 +392,7 @@ func TestGetTektonDir(t *testing.T) { got, err := v.GetTektonDir(ctx, tt.args.event, tt.args.path, tt.args.provenance) if tt.wantErr != "" { assert.Assert(t, err != nil, "expected error %s, got %v", tt.wantErr, err) - assert.Equal(t, err.Error(), tt.wantErr) + assert.ErrorContains(t, err, tt.wantErr) return } if tt.wantStr != "" { diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index ed5989674..ef822595b 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -6,7 +6,7 @@ import ( "regexp" "strings" - "k8s.io/apimachinery/pkg/util/yaml" + "gopkg.in/yaml.v2" ) var (