Skip to content

Commit

Permalink
fix buf lint violations
Browse files Browse the repository at this point in the history
  • Loading branch information
ggilmore committed Sep 6, 2023
1 parent 4c7500e commit de3f7cb
Show file tree
Hide file tree
Showing 12 changed files with 1,262 additions and 1,053 deletions.
30 changes: 23 additions & 7 deletions api_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ func (lfm *LineFragmentMatch) ToProto() *proto.LineFragmentMatch {

func FlushReasonFromProto(p proto.FlushReason) FlushReason {
switch p {
case proto.FlushReason_TIMER_EXPIRED:
case proto.FlushReason_FLUSH_REASON_TIMER_EXPIRED:
return FlushReasonTimerExpired
case proto.FlushReason_FINAL_FLUSH:
case proto.FlushReason_FLUSH_REASON_FINAL_FLUSH:
return FlushReasonFinalFlush
case proto.FlushReason_MAX_SIZE:
case proto.FlushReason_FLUSH_REASON_MAX_SIZE:
return FlushReasonMaxSize
default:
return FlushReason(0)
Expand All @@ -257,13 +257,13 @@ func FlushReasonFromProto(p proto.FlushReason) FlushReason {
func (fr FlushReason) ToProto() proto.FlushReason {
switch fr {
case FlushReasonTimerExpired:
return proto.FlushReason_TIMER_EXPIRED
return proto.FlushReason_FLUSH_REASON_TIMER_EXPIRED
case FlushReasonFinalFlush:
return proto.FlushReason_FINAL_FLUSH
return proto.FlushReason_FLUSH_REASON_FINAL_FLUSH
case FlushReasonMaxSize:
return proto.FlushReason_MAX_SIZE
return proto.FlushReason_FLUSH_REASON_MAX_SIZE
default:
return proto.FlushReason_UNKNOWN
return proto.FlushReason_FLUSH_REASON_UNKNOWN_UNSPECIFIED
}
}

Expand Down Expand Up @@ -345,6 +345,14 @@ func (p *Progress) ToProto() *proto.Progress {
}
}

func SearchResultFromStreamProto(p *proto.StreamSearchResponse, repoURLs, lineFragments map[string]string) *SearchResult {
if p == nil {
return nil
}

return SearchResultFromProto(p.GetResponseChunk(), repoURLs, lineFragments)
}

func SearchResultFromProto(p *proto.SearchResponse, repoURLs, lineFragments map[string]string) *SearchResult {
if p == nil {
return nil
Expand Down Expand Up @@ -384,6 +392,14 @@ func (sr *SearchResult) ToProto() *proto.SearchResponse {
}
}

func (sr *SearchResult) ToStreamProto() *proto.StreamSearchResponse {
if sr == nil {
return nil
}

return &proto.StreamSearchResponse{ResponseChunk: sr.ToProto()}
}

func RepositoryBranchFromProto(p *proto.RepositoryBranch) RepositoryBranch {
return RepositoryBranch{
Name: p.GetName(),
Expand Down
48 changes: 35 additions & 13 deletions api_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,45 @@ func TestProtoRoundtrip(t *testing.T) {
})

t.Run("SearchResult", func(t *testing.T) {
f := func(f1 *SearchResult) bool {
var repoURLs map[string]string
var lineFragments map[string]string
t.Run("unary", func(t *testing.T) {
f := func(f1 *SearchResult) bool {
var repoURLs map[string]string
var lineFragments map[string]string

if f1 != nil {
repoURLs = f1.RepoURLs
lineFragments = f1.LineFragments
}

if f1 != nil {
repoURLs = f1.RepoURLs
lineFragments = f1.LineFragments
p1 := f1.ToProto()
f2 := SearchResultFromProto(p1, repoURLs, lineFragments)

return reflect.DeepEqual(f1, f2)
}
if err := quick.Check(f, nil); err != nil {
t.Fatal(err)
}
})

p1 := f1.ToProto()
f2 := SearchResultFromProto(p1, repoURLs, lineFragments)
t.Run("stream", func(t *testing.T) {
f := func(f1 *SearchResult) bool {
var repoURLs map[string]string
var lineFragments map[string]string

return reflect.DeepEqual(f1, f2)
}
if err := quick.Check(f, nil); err != nil {
t.Fatal(err)
}
if f1 != nil {
repoURLs = f1.RepoURLs
lineFragments = f1.LineFragments
}

p1 := f1.ToStreamProto()
f2 := SearchResultFromStreamProto(p1, repoURLs, lineFragments)

return reflect.DeepEqual(f1, f2)
}
if err := quick.Check(f, nil); err != nil {
t.Fatal(err)
}
})
})

t.Run("Repository", func(t *testing.T) {
Expand Down
Loading

0 comments on commit de3f7cb

Please sign in to comment.