Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix tests relying on "X-Total-Pages" and "X-Total" headers that have been removed #685

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/test/java/org/gitlab4j/api/TestCommitsApi.java
Original file line number Diff line number Diff line change
@@ -147,7 +147,12 @@ public void testCommitsSince() throws GitLabApiException, ParseException {

pager = gitLabApi.getCommitsApi().getCommits(testProject.getId(), null, since, null, 10);
assertNotNull(pager);
assertTrue(pager.getTotalItems() > 0);

/*
Since 13.5 the commits API no longer returns "X-Total-Pages" and "X-Total" headers
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/43159
*/
// assertTrue(pager.getTotalItems() > 0);
}

@Test
36 changes: 28 additions & 8 deletions src/test/java/org/gitlab4j/api/TestPager.java
Original file line number Diff line number Diff line change
@@ -178,16 +178,25 @@ public void testAll() throws GitLabApiException {
Pager<Commit> pager = gitLabApi.getCommitsApi().getCommits(project, 1);
assertNotNull(pager);
assertEquals(1, pager.getItemsPerPage());
assertTrue(0 < pager.getTotalPages());

int numCommits = pager.getTotalItems();
assertTrue(0 < numCommits);
/*
Since 13.5 the commits API no longer returns "X-Total-Pages" and "X-Total" headers
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/43159
*/
// assertTrue(0 < pager.getTotalPages());
//
// int numCommits = pager.getTotalItems();
// assertTrue(0 < numCommits);

List<Commit> allCommits = pager.all();
System.out.println("All commits:");
allCommits.stream().map(Commit::getId).forEach(System.out::println);

assertEquals(numCommits, allCommits.size());
/*
A more deterministic approach, creating a known no. of commits within the scope of this test, is needed if the
total no. of commits should be tested
*/
// assertEquals(numCommits, allCommits.size());
}

@Test
@@ -199,12 +208,23 @@ public void testStream() throws GitLabApiException {
Pager<Commit> pager = gitLabApi.getCommitsApi().getCommits(project, 1);
assertNotNull(pager);
assertEquals(1, pager.getItemsPerPage());
assertTrue(0 < pager.getTotalPages());

int numCommits = pager.getTotalItems();
assertTrue(0 < numCommits);
/*
Since 13.5 the commits API no longer returns "X-Total-Pages" and "X-Total" headers
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/43159
*/
// assertTrue(0 < pager.getTotalPages());
//
// int numCommits = pager.getTotalItems();
// assertTrue(0 < numCommits);

System.out.println("Streamed commits:");
assertEquals(numCommits, pager.stream().map(Commit::getId).peek(System.out::println).count());
pager.stream().map(Commit::getId).peek(System.out::println);

/*
A more deterministic approach, creating a known no. of commits within the scope of this test, is needed if the
total no. of commits should be tested
*/
// assertEquals(numCommits, pager.stream().map(Commit::getId).peek(System.out::println).count());
}
}