diff options
author | zeripath <art27@cantab.net> | 2019-05-15 16:24:39 +0100 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-05-15 11:24:39 -0400 |
commit | 56ae539bed7d822980ebaae8db316a0177fc028c (patch) | |
tree | ee63a75ba156002cb6c40975c1c35b032954f913 /integrations | |
parent | 5fb1ad70113d3272232c266b4ff58e9f7f646594 (diff) | |
download | gitea-56ae539bed7d822980ebaae8db316a0177fc028c.tar.gz gitea-56ae539bed7d822980ebaae8db316a0177fc028c.zip |
SearchRepositoryByName improvements and unification (#6897)
Diffstat (limited to 'integrations')
-rw-r--r-- | integrations/api_repo_test.go | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/integrations/api_repo_test.go b/integrations/api_repo_test.go index d03ddcb353..8dedfd1ae0 100644 --- a/integrations/api_repo_test.go +++ b/integrations/api_repo_test.go @@ -69,40 +69,41 @@ func TestAPISearchRepo(t *testing.T) { name, requestURL string expectedResults }{ - {name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50", expectedResults: expectedResults{ + {name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{ nil: {count: 21}, user: {count: 21}, user2: {count: 21}}, }, - {name: "RepositoriesMax10", requestURL: "/api/v1/repos/search?limit=10", expectedResults: expectedResults{ + {name: "RepositoriesMax10", requestURL: "/api/v1/repos/search?limit=10&private=false", expectedResults: expectedResults{ nil: {count: 10}, user: {count: 10}, user2: {count: 10}}, }, - {name: "RepositoriesDefaultMax10", requestURL: "/api/v1/repos/search?default", expectedResults: expectedResults{ + {name: "RepositoriesDefaultMax10", requestURL: "/api/v1/repos/search?default&private=false", expectedResults: expectedResults{ nil: {count: 10}, user: {count: 10}, user2: {count: 10}}, }, - {name: "RepositoriesByName", requestURL: fmt.Sprintf("/api/v1/repos/search?q=%s", "big_test_"), expectedResults: expectedResults{ + {name: "RepositoriesByName", requestURL: fmt.Sprintf("/api/v1/repos/search?q=%s&private=false", "big_test_"), expectedResults: expectedResults{ nil: {count: 7, repoName: "big_test_"}, user: {count: 7, repoName: "big_test_"}, user2: {count: 7, repoName: "big_test_"}}, }, {name: "RepositoriesAccessibleAndRelatedToUser", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user.ID), expectedResults: expectedResults{ - nil: {count: 4}, - user: {count: 8, includesPrivate: true}, - user2: {count: 4}}, + nil: {count: 5}, + user: {count: 9, includesPrivate: true}, + user2: {count: 5, includesPrivate: true}}, }, {name: "RepositoriesAccessibleAndRelatedToUser2", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user2.ID), expectedResults: expectedResults{ nil: {count: 1}, - user: {count: 1}, - user2: {count: 2, includesPrivate: true}}, + user: {count: 2, includesPrivate: true}, + user2: {count: 2, includesPrivate: true}, + user4: {count: 1}}, }, {name: "RepositoriesAccessibleAndRelatedToUser3", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user3.ID), expectedResults: expectedResults{ nil: {count: 1}, - user: {count: 1}, - user2: {count: 1}, + user: {count: 4, includesPrivate: true}, + user2: {count: 2, includesPrivate: true}, user3: {count: 4, includesPrivate: true}}, }, {name: "RepositoriesOwnedByOrganization", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", orgUser.ID), expectedResults: expectedResults{ @@ -112,12 +113,12 @@ func TestAPISearchRepo(t *testing.T) { }, {name: "RepositoriesAccessibleAndRelatedToUser4", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user4.ID), expectedResults: expectedResults{ nil: {count: 3}, - user: {count: 3}, - user4: {count: 6, includesPrivate: true}}}, + user: {count: 4, includesPrivate: true}, + user4: {count: 7, includesPrivate: true}}}, {name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeSource", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s", user4.ID, "source"), expectedResults: expectedResults{ nil: {count: 0}, - user: {count: 0}, - user4: {count: 0, includesPrivate: true}}}, + user: {count: 1, includesPrivate: true}, + user4: {count: 1, includesPrivate: true}}}, {name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeFork", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s", user4.ID, "fork"), expectedResults: expectedResults{ nil: {count: 1}, user: {count: 1}, @@ -136,8 +137,8 @@ func TestAPISearchRepo(t *testing.T) { user4: {count: 2, includesPrivate: true}}}, {name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeCollaborative", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s", user4.ID, "collaborative"), expectedResults: expectedResults{ nil: {count: 0}, - user: {count: 0}, - user4: {count: 0, includesPrivate: true}}}, + user: {count: 1, includesPrivate: true}, + user4: {count: 1, includesPrivate: true}}}, } for _, testCase := range testCases { @@ -164,14 +165,19 @@ func TestAPISearchRepo(t *testing.T) { var body api.SearchResults DecodeJSON(t, response, &body) - assert.Len(t, body.Data, expected.count) + repoNames := make([]string, 0, len(body.Data)) + for _, repo := range body.Data { + repoNames = append(repoNames, fmt.Sprintf("%d:%s:%t", repo.ID, repo.FullName, repo.Private)) + } + assert.Len(t, repoNames, expected.count) for _, repo := range body.Data { r := getRepo(t, repo.ID) hasAccess, err := models.HasAccess(userID, r) - assert.NoError(t, err) - assert.True(t, hasAccess) + assert.NoError(t, err, "Error when checking if User: %d has access to %s: %v", userID, repo.FullName, err) + assert.True(t, hasAccess, "User: %d does not have access to %s", userID, repo.FullName) assert.NotEmpty(t, repo.Name) + assert.Equal(t, repo.Name, r.Name) if len(expected.repoName) > 0 { assert.Contains(t, repo.Name, expected.repoName) @@ -182,7 +188,7 @@ func TestAPISearchRepo(t *testing.T) { } if !expected.includesPrivate { - assert.False(t, repo.Private) + assert.False(t, repo.Private, "User: %d not expecting private repository: %s", userID, repo.FullName) } } }) |