2020-12-02 15:09:37 +00:00
|
|
|
package gitaly
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-10-11 09:09:08 +00:00
|
|
|
"github.com/golang/protobuf/proto" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab/-/issues/324868
|
2020-12-02 15:09:37 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-06-30 09:10:05 +00:00
|
|
|
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
|
2020-12-02 15:09:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUnmarshalJSON(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
in string
|
2021-10-11 09:09:08 +00:00
|
|
|
out *gitalypb.Repository
|
2020-12-02 15:09:37 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "basic example",
|
|
|
|
in: `{"relative_path":"foo/bar.git"}`,
|
2021-10-11 09:09:08 +00:00
|
|
|
out: &gitalypb.Repository{RelativePath: "foo/bar.git"},
|
2020-12-02 15:09:37 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "unknown field",
|
|
|
|
in: `{"relative_path":"foo/bar.git","unknown_field":12345}`,
|
2021-10-11 09:09:08 +00:00
|
|
|
out: &gitalypb.Repository{RelativePath: "foo/bar.git"},
|
2020-12-02 15:09:37 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.desc, func(t *testing.T) {
|
2021-10-11 09:09:08 +00:00
|
|
|
result := &gitalypb.Repository{}
|
|
|
|
require.NoError(t, UnmarshalJSON(tc.in, result))
|
|
|
|
require.True(t, proto.Equal(tc.out, result))
|
2020-12-02 15:09:37 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|