From 54e2719394fbbfa0900c342f6053b8ce61afe0e7 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Mon, 4 Sep 2023 15:24:38 +0300 Subject: [PATCH] Drop gopkg.in/yaml.v2 dependency Signed-off-by: Kimmo Lehto --- collection_test.go | 11 +++++++---- go.mod | 1 - go.sum | 2 -- version_test.go | 12 +++++++----- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/collection_test.go b/collection_test.go index f397f16..a5f8104 100644 --- a/collection_test.go +++ b/collection_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "gopkg.in/yaml.v2" ) func TestNewCollection(t *testing.T) { @@ -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) }) } @@ -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()) diff --git a/go.mod b/go.mod index 3752091..d178e9a 100644 --- a/go.mod +++ b/go.mod @@ -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 ( diff --git a/go.sum b/go.sum index 3ccfa33..ebae1e4 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/version_test.go b/version_test.go index 2c79c43..4ca853a 100644 --- a/version_test.go +++ b/version_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "gopkg.in/yaml.v2" ) func TestNewVersion(t *testing.T) { @@ -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) }) } @@ -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()) })