mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:11:49 +00:00
gitserver: grpc: create proto roundtrip tests for GetObject[Request/Response] (#62564)
Closes https://github.com/sourcegraph/sourcegraph/issues/60411 We didn't have any round trip tests for the GetCommit request or response type. This PR adds them. ## Test plan New unit tests
This commit is contained in:
parent
fdf0bf9a02
commit
74f2e25a0c
@ -32,6 +32,7 @@ go_test(
|
||||
embed = [":protocol"],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/gitserver/gitdomain",
|
||||
"//internal/search/result",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_stretchr_testify//require",
|
||||
|
||||
@ -543,7 +543,6 @@ func (r *GetObjectResponse) FromProto(p *proto.GetObjectResponse) {
|
||||
*r = GetObjectResponse{
|
||||
Object: gitObj,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// IsPerforcePathCloneableRequest is the request to check if a Perforce path is cloneable.
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
"testing/quick"
|
||||
"time"
|
||||
@ -9,6 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
"github.com/sourcegraph/sourcegraph/internal/search/result"
|
||||
)
|
||||
|
||||
@ -79,3 +82,60 @@ func TestCommitMatchProtoRoundtrip(t *testing.T) {
|
||||
roundtripped := CommitMatchFromProto(protoReq)
|
||||
require.Equal(t, req, roundtripped)
|
||||
}
|
||||
|
||||
func TestGetObjectRequestProtoRoundtrip(t *testing.T) {
|
||||
var diff string
|
||||
|
||||
fn := func(original GetObjectRequest) bool {
|
||||
protoReq := original.ToProto()
|
||||
|
||||
var converted GetObjectRequest
|
||||
converted.FromProto(protoReq)
|
||||
|
||||
if diff = cmp.Diff(original, converted); diff != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if err := quick.Check(fn, nil); err != nil {
|
||||
t.Errorf("GetObjectRequest proto roundtrip failed (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetObjectResponseProtoRoundtrip(t *testing.T) {
|
||||
var diff string
|
||||
|
||||
fn := func(id [20]byte, typ fuzzObjectType) bool {
|
||||
original := GetObjectResponse{
|
||||
Object: gitdomain.GitObject{
|
||||
ID: id,
|
||||
Type: gitdomain.ObjectType(typ),
|
||||
},
|
||||
}
|
||||
protoResp := original.ToProto()
|
||||
|
||||
var converted GetObjectResponse
|
||||
converted.FromProto(protoResp)
|
||||
|
||||
if diff = cmp.Diff(original, converted); diff != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if err := quick.Check(fn, nil); err != nil {
|
||||
t.Errorf("GetObjectResponse proto roundtrip failed (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
type fuzzObjectType gitdomain.ObjectType
|
||||
|
||||
func (fuzzObjectType) Generate(r *rand.Rand, _ int) reflect.Value {
|
||||
validValues := []gitdomain.ObjectType{gitdomain.ObjectTypeCommit, gitdomain.ObjectTypeTag, gitdomain.ObjectTypeTree, gitdomain.ObjectTypeBlob}
|
||||
return reflect.ValueOf(fuzzObjectType(validValues[r.Intn(len(validValues))]))
|
||||
}
|
||||
|
||||
var _ quick.Generator = fuzzObjectType(gitdomain.ObjectTypeCommit)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user