Skip to content

Commit 625c6f5

Browse files
authored
Future proof compatibility with newer protovalidate-go (#57)
Update protoyaml tests to adapt a protovalidate.Validator to its own internal Validator type, so if/when functional options are added to protovalidate-go's Validator, we don't break.
1 parent 2f6cae9 commit 625c6f5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

internal/protoyamltest/golden/golden.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ import (
2424
"google.golang.org/protobuf/proto"
2525
)
2626

27+
// protovalidateValidator is a temporary adapter that works with protovalidate-go v0.9.2 and later versions.
28+
// Newer versions (v0.9.3+) take functional options to the validate method so are incompatible w/ protoyaml's Validator.
29+
type protovalidateValidator struct {
30+
validator protovalidate.Validator
31+
}
32+
33+
func (p *protovalidateValidator) Validate(message proto.Message) error {
34+
return p.validator.Validate(message)
35+
}
36+
2737
// GenGoldenContent generates golden content for the given file path and data.
2838
//
2939
// If the data is invalid, the error message is returned as the golden content.
@@ -35,7 +45,7 @@ func GenGoldenContent(filePath string, data []byte) (string, error) {
3545
}
3646

3747
options := protoyaml.UnmarshalOptions{
38-
Validator: validator,
48+
Validator: &protovalidateValidator{validator: validator},
3949
Path: filePath,
4050
}
4151
var val proto.Message

0 commit comments

Comments
 (0)