prysm-pulse/shared/testutil/json_to_pb_converter_test.go
Raul Jordan 8cfbf0309d
Resolve Proto Lint Issues (#3044)
* skip proto lint

* golang ci lint no -t flag

* regenerate protos to match schema

* move to compatibility folder

* build file compatibility

* foo
2019-07-22 14:10:17 -05:00

66 lines
1.1 KiB
Go

package testutil
import (
"testing"
pb "github.com/prysmaticlabs/prysm/proto/testing"
)
const baz = "baz"
const foo = "foo"
func TestOverrideSpecName(t *testing.T) {
input := struct {
Foo string `json:"foo"`
Baz string `json:"baz"`
}{
Foo: "foo",
Baz: "baz",
}
output := &pb.TestMessage{}
if err := ConvertToPb(input, output); err != nil {
t.Fatal(err)
}
if output.Foo != foo {
t.Error("Expected output.Foo to be foo")
}
if output.Bar != baz {
t.Errorf("Expected output.Bar to be baz")
}
}
func TestOverrideSpecName_NestedProto(t *testing.T) {
input := struct {
Fuzz string `json:"fuzz"`
Msg struct {
Foo string `json:"foo"`
Baz string `json:"baz"`
}
}{
Fuzz: "fuzz",
Msg: struct {
Foo string `json:"foo"`
Baz string `json:"baz"`
}{
Foo: "foo",
Baz: "baz",
},
}
output := &pb.TestNestedMessage{}
if err := ConvertToPb(input, output); err != nil {
t.Fatal(err)
}
if output.Fuzz != "fuzz" {
t.Error("Expected output.fuzz to be fuzz")
}
if output.Msg.Foo != foo {
t.Error("Expected output.Msg.Foo to be foo")
}
if output.Msg.Bar != baz {
t.Errorf("Expected output.Msg.Bar to be baz")
}
}