From 0061edcbe2b12785513160da47d0ef971c96fe0a Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 8 Dec 2021 23:35:51 +0100 Subject: [PATCH] Remove gopkg.in/yaml.v2 (#583) * rm "gopkg.in/yaml.v2" * fix UnmarshalYAML for Networks & Ulimits --- go.mod | 1 - pipeline/frontend/yaml/types/network.go | 8 ++------ pipeline/frontend/yaml/types/network_test.go | 10 ++++------ pipeline/frontend/yaml/types/ulimit.go | 2 +- pipeline/frontend/yaml/types/ulimit_test.go | 3 +-- vendor/modules.txt | 1 - 6 files changed, 8 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index dad4f6ba6..35f76bdec 100644 --- a/go.mod +++ b/go.mod @@ -54,7 +54,6 @@ require ( google.golang.org/genproto v0.0.0-20211027162914-98a5263abeca // indirect google.golang.org/grpc v1.41.0 google.golang.org/protobuf v1.27.1 - gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b xorm.io/builder v0.3.9 xorm.io/xorm v1.2.5 diff --git a/pipeline/frontend/yaml/types/network.go b/pipeline/frontend/yaml/types/network.go index 5659d376d..2f887c815 100644 --- a/pipeline/frontend/yaml/types/network.go +++ b/pipeline/frontend/yaml/types/network.go @@ -72,16 +72,12 @@ func handleNetwork(name string, value interface{}) (*Network, error) { }, nil } switch v := value.(type) { - case map[interface{}]interface{}: + case map[string]interface{}: network := &Network{ Name: name, } for mapKey, mapValue := range v { - name, ok := mapKey.(string) - if !ok { - return &Network{}, fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name) - } - switch name { + switch mapKey { case "aliases": aliases, ok := mapValue.([]interface{}) if !ok { diff --git a/pipeline/frontend/yaml/types/network_test.go b/pipeline/frontend/yaml/types/network_test.go index 35792aacc..b7911f743 100644 --- a/pipeline/frontend/yaml/types/network_test.go +++ b/pipeline/frontend/yaml/types/network_test.go @@ -3,7 +3,6 @@ package types import ( "testing" - todo_yaml "gopkg.in/yaml.v2" "gopkg.in/yaml.v3" "github.com/stretchr/testify/assert" @@ -16,8 +15,7 @@ func TestMarshalNetworks(t *testing.T) { }{ { networks: Networks{}, - expected: `{} -`, + expected: "{}\n", }, { networks: Networks{ @@ -158,8 +156,8 @@ func TestUnmarshalNetworks(t *testing.T) { } for _, network := range networks { actual := &Networks{} - err := todo_yaml.Unmarshal([]byte(network.yaml), actual) - assert.Nil(t, err) - assert.Equal(t, network.expected, actual, "should be equal") + err := yaml.Unmarshal([]byte(network.yaml), actual) + assert.NoError(t, err) + assert.EqualValues(t, network.expected, actual) } } diff --git a/pipeline/frontend/yaml/types/ulimit.go b/pipeline/frontend/yaml/types/ulimit.go index b7025537e..caaac9888 100644 --- a/pipeline/frontend/yaml/types/ulimit.go +++ b/pipeline/frontend/yaml/types/ulimit.go @@ -37,7 +37,7 @@ func (u *Ulimits) UnmarshalYAML(unmarshal func(interface{}) error) error { case int: soft = int64(mv) hard = int64(mv) - case map[interface{}]interface{}: + case map[string]interface{}: if len(mv) != 2 { return fmt.Errorf("Failed to unmarshal Ulimit: %#v", mapValue) } diff --git a/pipeline/frontend/yaml/types/ulimit_test.go b/pipeline/frontend/yaml/types/ulimit_test.go index 0abd1c700..06903e773 100644 --- a/pipeline/frontend/yaml/types/ulimit_test.go +++ b/pipeline/frontend/yaml/types/ulimit_test.go @@ -3,7 +3,6 @@ package types import ( "testing" - todo_yaml "gopkg.in/yaml.v2" "gopkg.in/yaml.v3" "github.com/stretchr/testify/assert" @@ -119,7 +118,7 @@ nofile: for _, ulimit := range ulimits { actual := &Ulimits{} - err := todo_yaml.Unmarshal([]byte(ulimit.yaml), actual) + err := yaml.Unmarshal([]byte(ulimit.yaml), actual) assert.Nil(t, err) assert.Equal(t, ulimit.expected, actual, "should be equal") diff --git a/vendor/modules.txt b/vendor/modules.txt index eafe9a2d1..c9abeb030 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -812,7 +812,6 @@ google.golang.org/protobuf/types/known/timestamppb # gopkg.in/ini.v1 v1.63.2 gopkg.in/ini.v1 # gopkg.in/yaml.v2 v2.4.0 -## explicit gopkg.in/yaml.v2 # gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ## explicit