diff options
author | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2018-05-18 12:16:55 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2018-05-18 12:16:55 +0300 |
commit | b5a8572cacf1ce973353150fce3a9105676c85f8 (patch) | |
tree | 357180b8a758a81e63b6c2c07c8ca1934f61e837 | |
parent | 2d2695b2fb946c409a0f315bb2c2282085594a46 (diff) | |
parent | 08efed6273d689cc8dc821303f12cc0c47764a10 (diff) |
Merge branch 'fix-search-files-by-content-buf' into 'master'
Fix bug in SearchFilesByContent
See merge request gitlab-org/gitaly!722
-rw-r--r-- | changelogs/unreleased/fix-search-files-by-content-buf.yml | 5 | ||||
-rw-r--r-- | internal/service/repository/search_files.go | 9 | ||||
-rw-r--r-- | internal/service/repository/search_files_test.go | 24 |
3 files changed, 34 insertions, 4 deletions
diff --git a/changelogs/unreleased/fix-search-files-by-content-buf.yml b/changelogs/unreleased/fix-search-files-by-content-buf.yml new file mode 100644 index 000000000..615184528 --- /dev/null +++ b/changelogs/unreleased/fix-search-files-by-content-buf.yml @@ -0,0 +1,5 @@ +--- +title: Fix matching bug in SearchFilesByContent +merge_request: 722 +author: +type: fixed diff --git a/internal/service/repository/search_files.go b/internal/service/repository/search_files.go index 479ccff78..35ab1cb42 100644 --- a/internal/service/repository/search_files.go +++ b/internal/service/repository/search_files.go @@ -57,7 +57,7 @@ func (s *server) SearchFilesByContent(req *pb.SearchFilesByContentRequest, strea buf = append(buf, obj...) } } - if len(matches) > 1 { + if len(matches) > 0 { err = stream.Send(&pb.SearchFilesByContentResponse{Matches: matches}) matches = nil return err @@ -69,8 +69,11 @@ func (s *server) SearchFilesByContent(req *pb.SearchFilesByContentRequest, strea if err != nil { return helper.DecorateError(codes.Internal, err) } - if len(buf) > 1 { - return stream.Send(&pb.SearchFilesByContentResponse{Matches: [][]byte{buf}}) + if len(buf) > 0 { + matches = append(matches, buf) + } + if len(matches) > 0 { + return stream.Send(&pb.SearchFilesByContentResponse{Matches: matches}) } return nil } diff --git a/internal/service/repository/search_files_test.go b/internal/service/repository/search_files_test.go index 042b929cb..2679e4715 100644 --- a/internal/service/repository/search_files_test.go +++ b/internal/service/repository/search_files_test.go @@ -54,6 +54,22 @@ var ( []byte(""), }, []byte{'\n'}), } + contentCoffeeLines = [][]byte{ + bytes.Join([][]byte{ + []byte("many_files:CONTRIBUTING.md\x0092\x001. [Ruby style guide](https://github.com/bbatsov/ruby-style-guide)"), + []byte("many_files:CONTRIBUTING.md\x0093\x001. [Rails style guide](https://github.com/bbatsov/rails-style-guide)"), + []byte("many_files:CONTRIBUTING.md\x0094\x001. [CoffeeScript style guide](https://github.com/polarmobile/coffeescript-style-guide)"), + []byte("many_files:CONTRIBUTING.md\x0095\x001. [Shell command guidelines](doc/development/shell_commands.md)"), + []byte(""), + }, []byte{'\n'}), + bytes.Join([][]byte{ + []byte("many_files:files/js/application.js\x001\x00// This is a manifest file that'll be compiled into including all the files listed below."), + []byte("many_files:files/js/application.js\x002\x00// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically"), + []byte("many_files:files/js/application.js\x003\x00// be included in the compiled file accessible from http://example.com/assets/application.js"), + []byte("many_files:files/js/application.js\x004\x00// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the"), + []byte(""), + }, []byte{'\n'}), + } ) func TestSearchFilesByContentSuccessful(t *testing.T) { @@ -82,11 +98,17 @@ func TestSearchFilesByContentSuccessful(t *testing.T) { output: contentOutputLines, }, { - desc: "multi file in many_files", + desc: "single files, multiple matches", query: "backup", ref: "many_files", output: contentMultiLines, }, + { + desc: "multiple files, multiple matches", + query: "coffee", + ref: "many_files", + output: contentCoffeeLines, + }, } for _, tc := range testCases { |