Skip to content

Commit 6fdf9e4

Browse files
bschaatsbergenjamengual
authored andcommitted
revert: "convert gopkg.in/yaml.v3 to goccy/go-yaml (runatlantis#5579)" (runatlantis#5683)
Co-authored-by: PePe Amengual <2208324+jamengual@users.noreply.github.com> Signed-off-by: Ramon Vermeulen <ramonvermeulen98@gmail.com>
1 parent c43d92c commit 6fdf9e4

File tree

10 files changed

+26
-59
lines changed

10 files changed

+26
-59
lines changed

cmd/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424
"strings"
2525
"testing"
2626

27-
yaml "github.com/goccy/go-yaml"
2827
homedir "github.com/mitchellh/go-homedir"
2928
"github.com/spf13/cobra"
3029
"github.com/spf13/viper"
30+
"gopkg.in/yaml.v3"
3131

3232
"github.com/runatlantis/atlantis/server"
3333
"github.com/runatlantis/atlantis/server/events/vcs/testdata"

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ require (
1414
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
1515
github.com/go-playground/validator/v10 v10.26.0
1616
github.com/go-test/deep v1.1.1
17-
github.com/goccy/go-yaml v1.17.1
1817
github.com/gofri/go-github-ratelimit v1.1.1
1918
github.com/golang-jwt/jwt/v5 v5.2.2
2019
github.com/google/go-github/v71 v71.0.0
@@ -52,6 +51,7 @@ require (
5251
go.uber.org/zap v1.27.0
5352
golang.org/x/term v0.31.0
5453
golang.org/x/text v0.24.0
54+
gopkg.in/yaml.v3 v3.0.1
5555
)
5656

5757
require (
@@ -141,5 +141,4 @@ require (
141141
golang.org/x/time v0.8.0 // indirect
142142
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
143143
google.golang.org/protobuf v1.36.1 // indirect
144-
gopkg.in/yaml.v3 v3.0.1 // indirect
145144
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
170170
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
171171
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
172172
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
173-
github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY=
174-
github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
175173
github.com/gofri/go-github-ratelimit v1.1.1 h1:5TCOtFf45M2PjSYU17txqbiYBEzjOuK1+OhivbW69W0=
176174
github.com/gofri/go-github-ratelimit v1.1.1/go.mod h1:wGZlBbzHmIVjwDR3pZgKY7RBTV6gsQWxLVkpfwhcMJM=
177175
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=

server/core/config/parser_validator.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
validation "github.com/go-ozzo/ozzo-validation"
1414
shlex "github.com/google/shlex"
1515

16-
yaml "github.com/goccy/go-yaml"
1716
"github.com/runatlantis/atlantis/server/core/config/raw"
1817
"github.com/runatlantis/atlantis/server/core/config/valid"
18+
yaml "gopkg.in/yaml.v3"
1919
)
2020

2121
// ParserValidator parses and validates server-side repo config files and
@@ -57,7 +57,8 @@ func (p *ParserValidator) ParseRepoCfg(absRepoDir string, globalCfg valid.Global
5757
func (p *ParserValidator) ParseRepoCfgData(repoCfgData []byte, globalCfg valid.GlobalCfg, repoID string, branch string) (valid.RepoCfg, error) {
5858
var rawConfig raw.RepoCfg
5959

60-
decoder := yaml.NewDecoder(bytes.NewReader(repoCfgData), yaml.Strict())
60+
decoder := yaml.NewDecoder(bytes.NewReader(repoCfgData))
61+
decoder.KnownFields(true)
6162

6263
err := decoder.Decode(&rawConfig)
6364
if err != nil && !errors.Is(err, io.EOF) {
@@ -118,7 +119,8 @@ func (p *ParserValidator) ParseGlobalCfg(configFile string, defaultCfg valid.Glo
118119

119120
var rawCfg raw.GlobalCfg
120121

121-
decoder := yaml.NewDecoder(bytes.NewReader(configData), yaml.Strict())
122+
decoder := yaml.NewDecoder(bytes.NewReader(configData))
123+
decoder.KnownFields(true)
122124

123125
err = decoder.Decode(&rawCfg)
124126
if err != nil && !errors.Is(err, io.EOF) {

server/core/config/parser_validator_test.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ func TestParseCfgs_InvalidYAML(t *testing.T) {
8484
{
8585
"random characters",
8686
"slkjds",
87-
"string was used where mapping is expected",
87+
"yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `slkjds` into",
8888
},
8989
{
9090
"just a colon",
9191
":",
92-
"unexpected key name",
92+
"yaml: did not find expected key",
9393
},
9494
}
9595

@@ -670,12 +670,7 @@ projects:
670670
version: 3
671671
projects:
672672
- unknown: value`,
673-
expErr: `[4:3] unknown field "unknown"
674-
2 | version: 3
675-
3 | projects:
676-
> 4 | - unknown: value
677-
^
678-
`,
673+
expErr: "yaml: unmarshal errors:\n line 4: field unknown not found in type raw.Project",
679674
},
680675
{
681676
description: "referencing workflow that doesn't exist",
@@ -1277,11 +1272,8 @@ func TestParseGlobalCfg(t *testing.T) {
12771272
expErr: "file <tmp> was empty",
12781273
},
12791274
"invalid fields": {
1280-
input: "invalid: key",
1281-
expErr: `[1:1] unknown field "invalid"
1282-
> 1 | invalid: key
1283-
^
1284-
`,
1275+
input: "invalid: key",
1276+
expErr: "yaml: unmarshal errors:\n line 1: field invalid not found in type raw.GlobalCfg",
12851277
},
12861278
"no id specified": {
12871279
input: `repos:

server/core/config/raw/policies_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package raw_test
33
import (
44
"testing"
55

6-
yaml "github.com/goccy/go-yaml"
76
"github.com/hashicorp/go-version"
87
"github.com/runatlantis/atlantis/server/core/config/raw"
98
"github.com/runatlantis/atlantis/server/core/config/valid"
109
. "github.com/runatlantis/atlantis/testing"
10+
yaml "gopkg.in/yaml.v3"
1111
)
1212

1313
func TestPolicySetsConfig_YAMLMarshalling(t *testing.T) {

server/core/config/raw/raw_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"errors"
88

9-
yaml "github.com/goccy/go-yaml"
9+
"gopkg.in/yaml.v3"
1010
)
1111

1212
// Bool is a helper routine that allocates a new bool value
@@ -23,7 +23,8 @@ func String(v string) *string { return &v }
2323

2424
// Helper function to unmarshal from strings
2525
func unmarshalString(in string, out interface{}) error {
26-
decoder := yaml.NewDecoder(strings.NewReader(in), yaml.Strict())
26+
decoder := yaml.NewDecoder(strings.NewReader(in))
27+
decoder.KnownFields(true)
2728

2829
err := decoder.Decode(out)
2930
if errors.Is(err, io.EOF) {

server/core/config/raw/repo_cfg_test.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) {
4545
Projects: nil,
4646
Workflows: nil,
4747
},
48-
expErr: `[1:1] unknown field "invalid"
49-
> 1 | invalid: key
50-
^
51-
`,
48+
expErr: "yaml: unmarshal errors:\n line 1: field invalid not found in type raw.RepoCfg",
5249
},
5350
{
5451
description: "version set to 2",
@@ -94,11 +91,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) {
9491
Projects: nil,
9592
Workflows: nil,
9693
},
97-
expErr: `[2:6] mapping was used where sequence is expected
98-
1 | projects:
99-
> 2 | key: value
100-
^
101-
`,
94+
expErr: "yaml: unmarshal errors:\n line 2: cannot unmarshal !!map into []raw.Project",
10295
},
10396
{
10497
description: "projects with a scalar",
@@ -108,10 +101,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) {
108101
Projects: nil,
109102
Workflows: nil,
110103
},
111-
expErr: `[1:11] string was used where sequence is expected
112-
> 1 | projects: value
113-
^
114-
`,
104+
expErr: "yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `value` into []raw.Project",
115105
},
116106
{
117107
description: "automerge not a boolean",
@@ -121,11 +111,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) {
121111
Projects: nil,
122112
Workflows: nil,
123113
},
124-
expErr: `[2:12] cannot unmarshal string into Go struct field RepoCfg.Automerge of type bool
125-
1 | version: 3
126-
> 2 | automerge: notabool
127-
^
128-
`,
114+
expErr: "yaml: unmarshal errors:\n line 2: cannot unmarshal !!str `notabool` into bool",
129115
},
130116
{
131117
description: "parallel apply not a boolean",
@@ -135,11 +121,8 @@ func TestConfig_UnmarshalYAML(t *testing.T) {
135121
Projects: nil,
136122
Workflows: nil,
137123
},
138-
expErr: `[2:17] cannot unmarshal string into Go struct field RepoCfg.ParallelApply of type bool
139-
1 | version: 3
140-
> 2 | parallel_apply: notabool
141-
^
142-
`},
124+
expErr: "yaml: unmarshal errors:\n line 2: cannot unmarshal !!str `notabool` into bool",
125+
},
143126
{
144127
description: "should use values if set",
145128
input: `

server/core/config/raw/step_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package raw_test
33
import (
44
"testing"
55

6-
yaml "github.com/goccy/go-yaml"
76
"github.com/runatlantis/atlantis/server/core/config/raw"
87
"github.com/runatlantis/atlantis/server/core/config/valid"
98
. "github.com/runatlantis/atlantis/testing"
9+
yaml "gopkg.in/yaml.v3"
1010
)
1111

1212
func TestStepConfig_YAMLMarshalling(t *testing.T) {
@@ -148,11 +148,7 @@ key: value`,
148148
key:
149149
- value:
150150
another: map`,
151-
expErr: `[3:2] sequence was used where mapping is expected
152-
2 | key:
153-
> 3 | - value:
154-
^
155-
4 | another: map`,
151+
expErr: "yaml: unmarshal errors:\n line 3: cannot unmarshal !!seq into map[string]interface {}",
156152
},
157153
}
158154

server/core/config/raw/workflow_step_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package raw_test
33
import (
44
"testing"
55

6-
yaml "github.com/goccy/go-yaml"
76
"github.com/runatlantis/atlantis/server/core/config/raw"
87
"github.com/runatlantis/atlantis/server/core/config/valid"
98
. "github.com/runatlantis/atlantis/testing"
9+
yaml "gopkg.in/yaml.v3"
1010
)
1111

1212
func TestWorkflowHook_YAMLMarshalling(t *testing.T) {
@@ -47,11 +47,7 @@ key: value`,
4747
key:
4848
value:
4949
another: map`,
50-
expErr: `[3:8] cannot unmarshal map[string]interface {} into Go value of type string
51-
2 | key:
52-
> 3 | value:
53-
^
54-
4 | another: map`,
50+
expErr: "yaml: unmarshal errors:\n line 3: cannot unmarshal !!map into string",
5551
},
5652
}
5753

0 commit comments

Comments
 (0)