Skip to content

Commit

Permalink
Drop gopkg.in/yaml.v2 dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed Sep 4, 2023
1 parent 76371d6 commit 54e2719
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
11 changes: 7 additions & 4 deletions collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
)

func TestNewCollection(t *testing.T) {
Expand Down Expand Up @@ -47,9 +46,9 @@ func TestCollectionMarshalling(t *testing.T) {
})

t.Run("YAML", func(t *testing.T) {
yamlData, err := yaml.Marshal(c)
yamlData, err := c.MarshalYAML()
assert.NoError(t, err)
assert.Equal(t, "- v1.0.0+k0s.0\n- v1.0.1+k0s.0\n", string(yamlData))
assert.Equal(t, []string{`"v1.0.0+k0s.0"`, `"v1.0.1+k0s.0"`}, yamlData)
})
}

Expand All @@ -64,7 +63,11 @@ func TestCollectionUnmarshalling(t *testing.T) {

t.Run("YAML", func(t *testing.T) {
var c Collection
err := yaml.Unmarshal([]byte("- v1.0.0+k0s.1\n- v1.0.1+k0s.1\n"), &c)

err := c.UnmarshalYAML(func(i interface{}) error {
*(i.(*[]string)) = []string{"v1.0.0+k0s.1", "v1.0.1+k0s.1"}
return nil
})
assert.NoError(t, err)
assert.Equal(t, "v1.0.0+k0s.1", c[0].String())
assert.Equal(t, "v1.0.1+k0s.1", c[1].String())
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.17
require (
github.com/hashicorp/go-version v1.4.0
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 7 additions & 5 deletions version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
)

func TestNewVersion(t *testing.T) {
Expand Down Expand Up @@ -58,9 +57,9 @@ func TestMarshalling(t *testing.T) {
})

t.Run("YAML", func(t *testing.T) {
yamlData, err := yaml.Marshal(v)
yamlData, err := v.MarshalYAML()
assert.NoError(t, err)
assert.Equal(t, "v1.0.0+k0s.0\n", string(yamlData))
assert.Equal(t, "v1.0.0+k0s.0", yamlData)
})
}

Expand All @@ -73,8 +72,11 @@ func TestUnmarshalling(t *testing.T) {
})

t.Run("YAML", func(t *testing.T) {
var v Version
err := yaml.Unmarshal([]byte("v1.0.0+k0s.1\n"), &v)
v := &Version{}
err := v.UnmarshalYAML(func(i interface{}) error {
*(i.(*string)) = "v1.0.0+k0s.1"
return nil
})
assert.NoError(t, err)
assert.Equal(t, "v1.0.0+k0s.1", v.String())
})
Expand Down

0 comments on commit 54e2719

Please sign in to comment.