From 7134b924e0837cc86521a3d5166ed8bc8ec2eb63 Mon Sep 17 00:00:00 2001 From: Malte Meister Date: Fri, 9 Apr 2021 15:37:20 +0200 Subject: [PATCH] fix tests relying on "X-Total-Pages" and "X-Total" headers that have been removed --- .../java/org/gitlab4j/api/TestCommitsApi.java | 7 +++- src/test/java/org/gitlab4j/api/TestPager.java | 36 ++++++++++++++----- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/gitlab4j/api/TestCommitsApi.java b/src/test/java/org/gitlab4j/api/TestCommitsApi.java index f4f5379fa..655a89977 100644 --- a/src/test/java/org/gitlab4j/api/TestCommitsApi.java +++ b/src/test/java/org/gitlab4j/api/TestCommitsApi.java @@ -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 diff --git a/src/test/java/org/gitlab4j/api/TestPager.java b/src/test/java/org/gitlab4j/api/TestPager.java index 9ccb724c7..3cae548d2 100644 --- a/src/test/java/org/gitlab4j/api/TestPager.java +++ b/src/test/java/org/gitlab4j/api/TestPager.java @@ -178,16 +178,25 @@ public void testAll() throws GitLabApiException { Pager 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 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 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()); } }