From 79320d34d4b817c740ad2551d60a496a297ac0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E3=81=AE=E3=81=8B=E3=81=88=E3=81=A7?= Date: Wed, 13 Jul 2022 21:21:32 +0800 Subject: [PATCH] Chore: bump gopkg.in/yaml.v2 to gopkg.in/yaml.v3 (#1828) * Chore: bump gopkg.in/yaml.v2 to gopkg.in/yaml.v3 * Test: fix YAML test * Test: refine json_test style --- go.mod | 3 +-- go.sum | 3 ++- infra/conf/json/json_test.go | 19 +++++++++++++++++++ infra/conf/json/toml_test.go | 4 +++- infra/conf/json/yaml.go | 2 +- infra/conf/json/yaml_test.go | 19 ++++--------------- main/commands/all/jsonv4/convert.go | 2 +- 7 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 infra/conf/json/json_test.go diff --git a/go.mod b/go.mod index 03a860db5..ea833c9d3 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( golang.org/x/sys v0.0.0-20220325203850-36772127a21f google.golang.org/grpc v1.46.0 google.golang.org/protobuf v1.28.0 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.1 h12.io/socks v1.0.3 inet.af/netaddr v0.0.0-20211027220019-c74959edd3b6 ) @@ -73,5 +73,4 @@ require ( golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 7b4b734f7..9a8431ebd 100644 --- a/go.sum +++ b/go.sum @@ -677,8 +677,9 @@ 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/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= h12.io/socks v1.0.3 h1:Ka3qaQewws4j4/eDQnOdpr4wXsC//dXtWvftlIcCQUo= h12.io/socks v1.0.3/go.mod h1:AIhxy1jOId/XCz9BO+EIgNL2rQiPTBNnOfnVnQ+3Eck= diff --git a/infra/conf/json/json_test.go b/infra/conf/json/json_test.go new file mode 100644 index 000000000..ea24c542e --- /dev/null +++ b/infra/conf/json/json_test.go @@ -0,0 +1,19 @@ +package json_test + +import ( + "encoding/json" + "reflect" + "testing" +) + +func assertResult(t *testing.T, value map[string]interface{}, expected string) { + e := make(map[string]interface{}) + err := json.Unmarshal([]byte(expected), &e) + if err != nil { + t.Error(err) + } + if !reflect.DeepEqual(value, e) { + bs, _ := json.Marshal(value) + t.Fatalf("expected:\n%s\n\nactual:\n%s", expected, string(bs)) + } +} diff --git a/infra/conf/json/toml_test.go b/infra/conf/json/toml_test.go index 2c3c27332..cc5b795ae 100644 --- a/infra/conf/json/toml_test.go +++ b/infra/conf/json/toml_test.go @@ -1,8 +1,10 @@ -package json +package json_test import ( "encoding/json" "testing" + + . "github.com/v2fly/v2ray-core/v5/infra/conf/json" ) func TestTOMLToJSON_V2Style(t *testing.T) { diff --git a/infra/conf/json/yaml.go b/infra/conf/json/yaml.go index 55180573d..5fd94575f 100644 --- a/infra/conf/json/yaml.go +++ b/infra/conf/json/yaml.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) // FromYAML convert yaml to json diff --git a/infra/conf/json/yaml_test.go b/infra/conf/json/yaml_test.go index 1d5f36ead..9f14f4fa5 100644 --- a/infra/conf/json/yaml_test.go +++ b/infra/conf/json/yaml_test.go @@ -1,9 +1,10 @@ -package json +package json_test import ( "encoding/json" - "reflect" "testing" + + . "github.com/v2fly/v2ray-core/v5/infra/conf/json" ) func TestYMLToJSON_V2Style(t *testing.T) { @@ -116,7 +117,7 @@ TRUE: TRUE "parent": null }, "string": ["哈哈", "Hello world", "newline newline2"], - "date": ["2018-02-17"], + "date": ["2018-02-17T00:00:00Z"], "datetime": ["2018-02-17T15:02:31+08:00"], "mixed": [true,false,1,0,null,"hello"], "1": 0, @@ -132,15 +133,3 @@ TRUE: TRUE json.Unmarshal(bs, &m) assertResult(t, m, expected) } - -func assertResult(t *testing.T, value map[string]interface{}, expected string) { - e := make(map[string]interface{}) - err := json.Unmarshal([]byte(expected), &e) - if err != nil { - t.Error(err) - } - if !reflect.DeepEqual(value, e) { - bs, _ := json.Marshal(value) - t.Fatalf("expected:\n%s\n\nactual:\n%s", expected, string(bs)) - } -} diff --git a/main/commands/all/jsonv4/convert.go b/main/commands/all/jsonv4/convert.go index 8bf8ce969..dbda70932 100644 --- a/main/commands/all/jsonv4/convert.go +++ b/main/commands/all/jsonv4/convert.go @@ -8,7 +8,7 @@ import ( "github.com/pelletier/go-toml" "google.golang.org/protobuf/proto" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" core "github.com/v2fly/v2ray-core/v5" "github.com/v2fly/v2ray-core/v5/infra/conf/jsonpb"