From ba2d7ba1a5c38c0e82f63aeddeb937adae09ddf3 Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Sat, 24 Aug 2019 09:23:57 +0200 Subject: [PATCH] Add test cases for including (and not including) repository description in search. Signed-off-by: David Svantesson --- models/fixtures/repository.yml | 1 + models/repo_list_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index f43fae3d67e88..16b0045b2161b 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -165,6 +165,7 @@ owner_id: 14 lower_name: test_repo_14 name: test_repo_14 + description: test_description_14 is_private: false num_issues: 0 num_closed_issues: 0 diff --git a/models/repo_list_test.go b/models/repo_list_test.go index 645de2a59a4df..395004dd147c9 100644 --- a/models/repo_list_test.go +++ b/models/repo_list_test.go @@ -74,6 +74,34 @@ func TestSearchRepositoryByName(t *testing.T) { assert.Empty(t, repos) assert.Equal(t, int64(0), count) + // Test search within description + repos, count, err = SearchRepository(&SearchRepoOptions{ + Keyword: "description_14", + Page: 1, + PageSize: 10, + Collaborate: util.OptionalBoolFalse, + IncludeDescription: true, + }) + + assert.NoError(t, err) + if assert.Len(t, repos, 1) { + assert.Equal(t, "test_repo_14", repos[0].Name) + } + assert.Equal(t, int64(1), count) + + // Test NOT search within description + repos, count, err = SearchRepository(&SearchRepoOptions{ + Keyword: "description_14", + Page: 1, + PageSize: 10, + Collaborate: util.OptionalBoolFalse, + IncludeDescription: false, + }) + + assert.NoError(t, err) + assert.Empty(t, repos) + assert.Equal(t, int64(0), count) + testCases := []struct { name string opts *SearchRepoOptions