Skip to content

Commit

Permalink
Update protovalidate deps (#18)
Browse files Browse the repository at this point in the history
to v0.4.0
  • Loading branch information
Alfus authored Nov 8, 2023
1 parent 5ba42e5 commit 590cb23
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 51 deletions.
22 changes: 11 additions & 11 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down
56 changes: 28 additions & 28 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

Expand All @@ -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])
}
}

Expand All @@ -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])
}
}

Expand All @@ -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])
}
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
Expand All @@ -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
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
4 changes: 2 additions & 2 deletions internal/protoyamltest/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions protoyaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package protoyaml
import (
"fmt"
"reflect"
"strconv"
"testing"

"github.com/bufbuild/protoyaml-go/internal/gen/proto/bufext/cel/expr/conformance/proto3"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
})
Expand All @@ -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)
Expand Down

0 comments on commit 590cb23

Please sign in to comment.