Skip to content

Commit

Permalink
refactor: use gopkg.in/yaml.v2 for validation
Browse files Browse the repository at this point in the history
instead of k8s.io/apimachinery/pkg/util/yaml.
  • Loading branch information
tricktron authored and chmouel committed Dec 6, 2024
1 parent 2d4d7b0 commit 13749f6
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/provider/bitbucketcloud/bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 == "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/bitbucketserver/bitbucketserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/provider/gitea/gitea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/provider/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/provider/gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"strings"

"k8s.io/apimachinery/pkg/util/yaml"
"gopkg.in/yaml.v2"
)

var (
Expand Down

0 comments on commit 13749f6

Please sign in to comment.