From 590cb230c03ade1f04b93e3942a1cb2dd5ed514f Mon Sep 17 00:00:00 2001 From: Alfred Fuller Date: Wed, 8 Nov 2023 14:34:23 -0800 Subject: [PATCH] Update protovalidate deps (#18) to v0.4.0 --- decode.go | 22 ++++++------- encode_test.go | 56 +++++++++++++++++----------------- go.mod | 6 ++-- go.sum | 8 ++--- internal/protoyamltest/fuzz.go | 4 +-- protoyaml_test.go | 7 +++-- 6 files changed, 52 insertions(+), 51 deletions(-) diff --git a/decode.go b/decode.go index 6aa2f87..b41811c 100644 --- a/decode.go +++ b/decode.go @@ -658,8 +658,8 @@ func unmarshalAnyMsg(unm *unmarshaler, node *yaml.Node, message proto.Message) b } if !ok { - return setFieldByName(message, "type_url", protoreflect.ValueOfString(anyVal.TypeUrl)) && - setFieldByName(message, "value", protoreflect.ValueOfBytes(anyVal.Value)) + return setFieldByName(message, "type_url", protoreflect.ValueOfString(anyVal.GetTypeUrl())) && + setFieldByName(message, "value", protoreflect.ValueOfBytes(anyVal.GetValue())) } return true @@ -760,8 +760,8 @@ func unmarshalDurationMsg(unm *unmarshaler, node *yaml.Node, message proto.Messa unm.addErrorf(node, "invalid duration: %v", err) } else if !ok { // Set the fields dynamically. - return setFieldByName(message, "seconds", protoreflect.ValueOfInt64(duration.Seconds)) && - setFieldByName(message, "nanos", protoreflect.ValueOfInt32(duration.Nanos)) + return setFieldByName(message, "seconds", protoreflect.ValueOfInt64(duration.GetSeconds())) && + setFieldByName(message, "nanos", protoreflect.ValueOfInt32(duration.GetNanos())) } return true } @@ -778,8 +778,8 @@ func unmarshalTimestampMsg(unm *unmarshaler, node *yaml.Node, message proto.Mess if err != nil { unm.addErrorf(node, "invalid timestamp: %v", err) } else if !ok { - return setFieldByName(message, "seconds", protoreflect.ValueOfInt64(timestamp.Seconds)) && - setFieldByName(message, "nanos", protoreflect.ValueOfInt32(timestamp.Nanos)) + return setFieldByName(message, "seconds", protoreflect.ValueOfInt64(timestamp.GetSeconds())) && + setFieldByName(message, "nanos", protoreflect.ValueOfInt32(timestamp.GetNanos())) } return true } @@ -798,7 +798,7 @@ func unmarshalWrapperMsg(unm *unmarshaler, node *yaml.Node, message proto.Messag } func dynSetValue(message proto.Message, value *structpb.Value) bool { - switch val := value.Kind.(type) { + switch val := value.GetKind().(type) { case *structpb.Value_NullValue: return setFieldByName(message, "null_value", protoreflect.ValueOfEnum(protoreflect.EnumNumber(val.NullValue))) case *structpb.Value_NumberValue: @@ -831,7 +831,7 @@ func dynSetListValue(message proto.Message, list *structpb.ListValue) bool { return false } values := message.ProtoReflect().Mutable(valuesFld).List() - for _, item := range list.Values { + for _, item := range list.GetValues() { value := values.NewElement() if !dynSetValue(value.Message().Interface(), item) { return false @@ -847,7 +847,7 @@ func dynSetStruct(message proto.Message, structVal *structpb.Struct) bool { return false } fields := message.ProtoReflect().Mutable(fieldsFld).Map() - for key, item := range structVal.Fields { + for key, item := range structVal.GetFields() { value := fields.NewValue() if !dynSetValue(value.Message().Interface(), item) { return false @@ -953,7 +953,7 @@ func unmarshalListValue( for _, itemNode := range node.Content { itemValue := &structpb.Value{} unmarshalValue(unm, itemNode, itemValue, field, true) - list.Values = append(list.Values, itemValue) + list.Values = append(list.GetValues(), itemValue) } } @@ -1005,7 +1005,7 @@ func unmarshalStruct( valueNode := node.Content[i] value := &structpb.Value{} unmarshalValue(unm, valueNode, value, valueDesc, false) - if message.Fields == nil { + if message.GetFields() == nil { message.Fields = make(map[string]*structpb.Value) } message.Fields[keyNode.Value] = value diff --git a/encode_test.go b/encode_test.go index d3f7d89..f1f846e 100644 --- a/encode_test.go +++ b/encode_test.go @@ -38,17 +38,17 @@ func TestFloatJsonEncoding(t *testing.T) { if err := Unmarshal(data, oval); err != nil { t.Fatal(err) } - if len(oval.RepeatedDouble) != 3 { - t.Fatalf("Expected 3 values, got %d", len(oval.RepeatedDouble)) + if len(oval.GetRepeatedDouble()) != 3 { + t.Fatalf("Expected 3 values, got %d", len(oval.GetRepeatedDouble())) } - if !math.IsInf(oval.RepeatedDouble[0], 1) { - t.Fatalf("Expected +Inf, got %f", oval.RepeatedDouble[0]) + if !math.IsInf(oval.GetRepeatedDouble()[0], 1) { + t.Fatalf("Expected +Inf, got %f", oval.GetRepeatedDouble()[0]) } - if !math.IsInf(oval.RepeatedDouble[1], -1) { - t.Fatalf("Expected -Inf, got %f", oval.RepeatedDouble[1]) + if !math.IsInf(oval.GetRepeatedDouble()[1], -1) { + t.Fatalf("Expected -Inf, got %f", oval.GetRepeatedDouble()[1]) } - if !math.IsNaN(oval.RepeatedDouble[2]) { - t.Fatalf("Expected NaN, got %f", oval.RepeatedDouble[2]) + if !math.IsNaN(oval.GetRepeatedDouble()[2]) { + t.Fatalf("Expected NaN, got %f", oval.GetRepeatedDouble()[2]) } } @@ -68,11 +68,11 @@ func TestStringEscaping(t *testing.T) { if err := Unmarshal(data, oval); err != nil { t.Fatal(err) } - if len(oval.RepeatedString) != 1 { - t.Fatalf("Expected 1 value, got %d", len(oval.RepeatedString)) + if len(oval.GetRepeatedString()) != 1 { + t.Fatalf("Expected 1 value, got %d", len(oval.GetRepeatedString())) } - if oval.RepeatedString[0] != ival.RepeatedString[0] { - t.Fatalf("Expected %q, got %q", ival.RepeatedString[0], oval.RepeatedString[0]) + if oval.GetRepeatedString()[0] != ival.GetRepeatedString()[0] { + t.Fatalf("Expected %q, got %q", ival.GetRepeatedString()[0], oval.GetRepeatedString()[0]) } } @@ -92,11 +92,11 @@ func TestBytesEncoding(t *testing.T) { if err := Unmarshal(data, oval); err != nil { t.Fatal(err) } - if len(oval.RepeatedBytes) != 1 { - t.Fatalf("Expected 1 value, got %d", len(oval.RepeatedBytes)) + if len(oval.GetRepeatedBytes()) != 1 { + t.Fatalf("Expected 1 value, got %d", len(oval.GetRepeatedBytes())) } - if string(oval.RepeatedBytes[0]) != string(ival.RepeatedBytes[0]) { - t.Fatalf("Expected %q, got %q", ival.RepeatedBytes[0], oval.RepeatedBytes[0]) + if string(oval.GetRepeatedBytes()[0]) != string(ival.GetRepeatedBytes()[0]) { + t.Fatalf("Expected %q, got %q", ival.GetRepeatedBytes()[0], oval.GetRepeatedBytes()[0]) } } @@ -117,22 +117,22 @@ func TestEnumEncoding(t *testing.T) { t.Fatal(err) } - if len(oval.RepeatedNestedEnum) != 5 { - t.Fatalf("Expected 5 values, got %d", len(oval.RepeatedNestedEnum)) + if len(oval.GetRepeatedNestedEnum()) != 5 { + t.Fatalf("Expected 5 values, got %d", len(oval.GetRepeatedNestedEnum())) } - if oval.RepeatedNestedEnum[0] != ival.RepeatedNestedEnum[0] { - t.Fatalf("Expected %v, got %v", ival.RepeatedNestedEnum[0], oval.RepeatedNestedEnum[0]) + if oval.GetRepeatedNestedEnum()[0] != ival.GetRepeatedNestedEnum()[0] { + t.Fatalf("Expected %v, got %v", ival.GetRepeatedNestedEnum()[0], oval.GetRepeatedNestedEnum()[0]) } - if oval.RepeatedNestedEnum[1] != ival.RepeatedNestedEnum[1] { - t.Fatalf("Expected %v, got %v", ival.RepeatedNestedEnum[1], oval.RepeatedNestedEnum[1]) + if oval.GetRepeatedNestedEnum()[1] != ival.GetRepeatedNestedEnum()[1] { + t.Fatalf("Expected %v, got %v", ival.GetRepeatedNestedEnum()[1], oval.GetRepeatedNestedEnum()[1]) } - if oval.RepeatedNestedEnum[2] != ival.RepeatedNestedEnum[2] { - t.Fatalf("Expected %v, got %v", ival.RepeatedNestedEnum[2], oval.RepeatedNestedEnum[2]) + if oval.GetRepeatedNestedEnum()[2] != ival.GetRepeatedNestedEnum()[2] { + t.Fatalf("Expected %v, got %v", ival.GetRepeatedNestedEnum()[2], oval.GetRepeatedNestedEnum()[2]) } - if oval.RepeatedNestedEnum[3] != ival.RepeatedNestedEnum[3] { - t.Fatalf("Expected %v, got %v", ival.RepeatedNestedEnum[3], oval.RepeatedNestedEnum[3]) + if oval.GetRepeatedNestedEnum()[3] != ival.GetRepeatedNestedEnum()[3] { + t.Fatalf("Expected %v, got %v", ival.GetRepeatedNestedEnum()[3], oval.GetRepeatedNestedEnum()[3]) } - if oval.RepeatedNestedEnum[4] != ival.RepeatedNestedEnum[4] { - t.Fatalf("Expected %v, got %v", ival.RepeatedNestedEnum[4], oval.RepeatedNestedEnum[4]) + if oval.GetRepeatedNestedEnum()[4] != ival.GetRepeatedNestedEnum()[4] { + t.Fatalf("Expected %v, got %v", ival.GetRepeatedNestedEnum()[4], oval.GetRepeatedNestedEnum()[4]) } } diff --git a/go.mod b/go.mod index f8c12f3..8fd3fdd 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module github.com/bufbuild/protoyaml-go -go 1.19 +go 1.21 require ( - github.com/bufbuild/protovalidate-go v0.3.2 + github.com/bufbuild/protovalidate-go v0.4.0 google.golang.org/protobuf v1.31.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -19,6 +19,6 @@ require ( ) require ( - buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20230914171853-63dfe56cc2c4.1 + buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231106192134-1baebb0a1518.2 github.com/google/go-cmp v0.5.9 ) diff --git a/go.sum b/go.sum index 9ef992e..90a6af5 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,9 @@ -buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20230914171853-63dfe56cc2c4.1 h1:2gmp+PRca1fqQHf/WMKOgu9inVb0R0N07TucgY3QZCQ= -buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20230914171853-63dfe56cc2c4.1/go.mod h1:xafc+XIsTxTy76GJQ1TKgvJWsSugFBqMaN27WhUblew= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231106192134-1baebb0a1518.2 h1:iRWpWLm1nrsCHBVhibqPJQB3iIf3FRsAXioJVU8m6w0= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231106192134-1baebb0a1518.2/go.mod h1:xafc+XIsTxTy76GJQ1TKgvJWsSugFBqMaN27WhUblew= github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 h1:goHVqTbFX3AIo0tzGr14pgfAW2ZfPChKO21Z9MGf/gk= github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM= -github.com/bufbuild/protovalidate-go v0.3.2 h1:7sG1R83PkCzOZb3P187gAchWFLHY6LQ8aVoUw6Wp9es= -github.com/bufbuild/protovalidate-go v0.3.2/go.mod h1:ywZqKUjMhQA8fmhsc+0DUlMfan8/umJ+5mKvjdxAD3M= +github.com/bufbuild/protovalidate-go v0.4.0 h1:ModSkCLEW07fiyGtdtMXKY+Gz3oPFKSfiaSCgL+FtpU= +github.com/bufbuild/protovalidate-go v0.4.0/go.mod h1:QqeUPLVYEKQc+/rkoUXFqXW03zPBfrEfIbX+zmA0VxA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/protoyamltest/fuzz.go b/internal/protoyamltest/fuzz.go index 02f4361..63daa5e 100644 --- a/internal/protoyamltest/fuzz.go +++ b/internal/protoyamltest/fuzz.go @@ -43,8 +43,8 @@ func populateMessage(rnd *rand.Rand, msg proto.Message, depth int) { msg.Seconds = rnd.Int63n(631152000000) - 315576000000 // Valid values are between 0 and +999,999,999 inclusive. msg.Nanos = rnd.Int31n(1000000000) - if msg.Seconds < 0 { - msg.Nanos = -msg.Nanos + if msg.GetSeconds() < 0 { + msg.Nanos = -msg.GetNanos() } return case *timestamppb.Timestamp: diff --git a/protoyaml_test.go b/protoyaml_test.go index 8c890fa..7351cfb 100644 --- a/protoyaml_test.go +++ b/protoyaml_test.go @@ -17,6 +17,7 @@ package protoyaml import ( "fmt" "reflect" + "strconv" "testing" "github.com/bufbuild/protoyaml-go/internal/gen/proto/bufext/cel/expr/conformance/proto3" @@ -52,7 +53,7 @@ func TestParseFieldPath(t *testing.T) { {Path: `foo["b.ar"].baz`, Expect: []string{"foo", "b.ar", "baz"}}, } { testCase := testCase - t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + t.Run(strconv.Itoa(i), func(t *testing.T) { t.Parallel() result, err := parseFieldPath(testCase.Path) if err != nil { @@ -184,7 +185,7 @@ func TestCombinatorial(t *testing.T) { cases := protoyamltest.InterestingTestValues() for i, c := range cases { c := c - t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + t.Run(strconv.Itoa(i), func(t *testing.T) { t.Parallel() testRoundTrip(t, c) }) @@ -195,7 +196,7 @@ func TestFuzz(t *testing.T) { t.Parallel() for i := int64(0); i < 100; i++ { i := i - t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + t.Run(strconv.FormatInt(i, 10), func(t *testing.T) { t.Parallel() msg := &proto3.TestAllTypes{} protoyamltest.PopulateMessage(msg, i)