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
This commit is contained in:
秋のかえで 2022-07-13 21:21:32 +08:00 committed by GitHub
parent b71598d461
commit 79320d34d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 21 deletions

3
go.mod
View File

@ -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
)

3
go.sum
View File

@ -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=

View File

@ -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))
}
}

View File

@ -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) {

View File

@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)
// FromYAML convert yaml to json

View File

@ -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))
}
}

View File

@ -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"