Merge pull request #1107 from akashRindhe/feat/1076

(refactor) Rename gitHubBeforeAfter to nonRecordingGitHub #1076
This commit is contained in:
Liam Newman
2021-04-19 10:08:35 -07:00
committed by GitHub
19 changed files with 36 additions and 36 deletions

View File

@@ -41,7 +41,7 @@ Once you have credentials setup, you add new test classes and test methods as yo
Keep `useProxy` enabled and iterate on your tests as needed. With `useProxy` enabled your tests will interact with
GitHub - you will need to clean up your server-state between runs. This can be done manually to start with.
Once your test code is somewhat stable, use `getGitHubBeforeAfter()` to get a `GitHub` instance for test setup and cleanup.
Once your test code is somewhat stable, use `getNonRecordingGitHub()` to get a `GitHub` instance for test setup and cleanup.
Interactions with that `GitHub` instance will not be recorded as part of the test, keeping the test data files to a minimum.
#### Running tests against your personal GitHub user account

View File

@@ -45,7 +45,7 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
*/
protected GitHub gitHub;
private GitHub gitHubBeforeAfter;
private GitHub nonRecordingGitHub;
protected final String baseFilesClassPath = this.getClass().getName().replace('.', '/');
protected final String baseRecordPath = "src/test/resources/" + baseFilesClassPath + "/wiremock";
@@ -115,9 +115,9 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
}
if (mockGitHub.isUseProxy()) {
gitHubBeforeAfter = getGitHubBuilder().withEndpoint("https://api.github.com/").build();
nonRecordingGitHub = getGitHubBuilder().withEndpoint("https://api.github.com/").build();
} else {
gitHubBeforeAfter = null;
nonRecordingGitHub = null;
}
}
@@ -210,7 +210,7 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
if (mockGitHub.isUseProxy()) {
tempGitHubRepositories.add(fullName);
try {
GHRepository repository = getGitHubBeforeAfter().getRepository(fullName);
GHRepository repository = getNonRecordingGitHub().getRepository(fullName);
if (repository != null) {
repository.delete();
}
@@ -227,22 +227,22 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
*
* @return a github instance after checking Authentication
*/
public GitHub getGitHubBeforeAfter() {
verifyAuthenticated(gitHubBeforeAfter);
return gitHubBeforeAfter;
public GitHub getNonRecordingGitHub() {
verifyAuthenticated(nonRecordingGitHub);
return nonRecordingGitHub;
}
protected void kohsuke() {
// No-op for now
// Generally this means the test is doing something that requires additional access rights
// Not always clear which ones.
// TODO: Add helpers that assert the expected rights using gitHubBeforeAfter and only when proxy is enabled
// TODO: Add helpers that assert the expected rights using nonRecordingGitHub and only when proxy is enabled
// String login = getUserTest().getLogin();
// assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));
}
private GHCreateRepositoryBuilder getCreateBuilder(String name) throws IOException {
GitHub github = getGitHubBeforeAfter();
GitHub github = getNonRecordingGitHub();
if (mockGitHub.isTestWithOrg()) {
return github.getOrganization(GITHUB_API_TEST_ORG).createRepository(name);

View File

@@ -91,7 +91,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
private void cleanupUserRepository(final String name) throws IOException {
if (mockGitHub.isUseProxy()) {
cleanupRepository(getUser(getGitHubBeforeAfter()).getLogin() + "/" + name);
cleanupRepository(getUser(getNonRecordingGitHub()).getLogin() + "/" + name);
}
}
@@ -585,7 +585,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
// System.out.println(hook);
} finally {
if (mockGitHub.isUseProxy()) {
r = getGitHubBeforeAfter().getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api");
r = getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api");
for (GHHook h : r.getHooks()) {
h.delete();
}
@@ -1063,7 +1063,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
void cleanupLabel(String name) {
if (mockGitHub.isUseProxy()) {
try {
GHLabel t = getGitHubBeforeAfter().getRepository("hub4j-test-org/test-labels").getLabel(name);
GHLabel t = getNonRecordingGitHub().getRepository("hub4j-test-org/test-labels").getLabel(name);
t.delete();
} catch (IOException e) {

View File

@@ -29,7 +29,7 @@ public class GHContentIntegrationTest extends AbstractGitHubWireMockTest {
@After
public void cleanup() throws Exception {
if (mockGitHub.isUseProxy()) {
repo = getGitHubBeforeAfter().getRepository("hub4j-test-org/GHContentIntegrationTest");
repo = getNonRecordingGitHub().getRepository("hub4j-test-org/GHContentIntegrationTest");
try {
GHContent content = repo.getFileContent(createdFilename);
if (content != null) {

View File

@@ -26,7 +26,7 @@ public class GHDiscussionTest extends AbstractGitHubWireMockTest {
public void cleanupDiscussions() throws Exception {
// only need to clean up if we're pointing to the live site
if (mockGitHub.isUseProxy()) {
for (GHDiscussion discussion : getGitHubBeforeAfter().getOrganization(GITHUB_API_TEST_ORG)
for (GHDiscussion discussion : getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG)
.getTeamBySlug(TEAM_SLUG)
.listDiscussions()) {
discussion.delete();

View File

@@ -20,7 +20,7 @@ public class GHMilestoneTest extends AbstractGitHubWireMockTest {
return;
}
for (GHMilestone milestone : getRepository(getGitHubBeforeAfter()).listMilestones(GHIssueState.ALL)) {
for (GHMilestone milestone : getRepository(getNonRecordingGitHub()).listMilestones(GHIssueState.ALL)) {
if ("Original Title".equals(milestone.getTitle()) || "Updated Title".equals(milestone.getTitle())
|| "Unset Test Milestone".equals(milestone.getTitle())) {
milestone.delete();

View File

@@ -25,7 +25,7 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
return;
}
GHTeam team = getGitHubBeforeAfter().getOrganization(GITHUB_API_TEST_ORG).getTeamByName(TEAM_NAME_CREATE);
GHTeam team = getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).getTeamByName(TEAM_NAME_CREATE);
if (team != null) {
team.delete();
}

View File

@@ -74,7 +74,7 @@ public class GHProjectCardTest extends AbstractGitHubWireMockTest {
public void after() throws IOException {
if (mockGitHub.isUseProxy()) {
if (card != null) {
card = getGitHubBeforeAfter().getProjectCard(card.getId());
card = getNonRecordingGitHub().getProjectCard(card.getId());
try {
card.delete();
card = null;
@@ -83,7 +83,7 @@ public class GHProjectCardTest extends AbstractGitHubWireMockTest {
}
}
if (column != null) {
column = getGitHubBeforeAfter().getProjectColumn(column.getId());
column = getNonRecordingGitHub().getProjectColumn(column.getId());
try {
column.delete();
column = null;
@@ -92,7 +92,7 @@ public class GHProjectCardTest extends AbstractGitHubWireMockTest {
}
}
if (project != null) {
project = getGitHubBeforeAfter().getProject(project.getId());
project = getNonRecordingGitHub().getProject(project.getId());
try {
project.delete();
project = null;

View File

@@ -48,7 +48,7 @@ public class GHProjectColumnTest extends AbstractGitHubWireMockTest {
public void after() throws IOException {
if (mockGitHub.isUseProxy()) {
if (column != null) {
column = getGitHubBeforeAfter().getProjectColumn(column.getId());
column = getNonRecordingGitHub().getProjectColumn(column.getId());
try {
column.delete();
column = null;
@@ -57,7 +57,7 @@ public class GHProjectColumnTest extends AbstractGitHubWireMockTest {
}
}
if (project != null) {
project = getGitHubBeforeAfter().getProject(project.getId());
project = getNonRecordingGitHub().getProject(project.getId());
try {
project.delete();
project = null;

View File

@@ -69,7 +69,7 @@ public class GHProjectTest extends AbstractGitHubWireMockTest {
public void after() throws IOException {
if (mockGitHub.isUseProxy()) {
if (project != null) {
project = getGitHubBeforeAfter().getProject(project.getId());
project = getNonRecordingGitHub().getProject(project.getId());
try {
project.delete();
project = null;

View File

@@ -31,7 +31,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
return;
}
for (GHPullRequest pr : getRepository(this.getGitHubBeforeAfter()).getPullRequests(GHIssueState.OPEN)) {
for (GHPullRequest pr : getRepository(this.getNonRecordingGitHub()).getPullRequests(GHIssueState.OPEN)) {
pr.close();
}
}

View File

@@ -25,7 +25,7 @@ public class GHTagTest extends AbstractGitHubWireMockTest {
}
try {
GHRef ref = getRepository(this.getGitHubBeforeAfter()).getRef("tags/create_tag_test");
GHRef ref = getRepository(this.getNonRecordingGitHub()).getRef("tags/create_tag_test");
if (ref != null) {
ref.delete();
}

View File

@@ -35,7 +35,7 @@ public class GHTreeBuilderTest extends AbstractGitHubWireMockTest {
@After
public void cleanup() throws Exception {
if (mockGitHub.isUseProxy()) {
repo = getGitHubBeforeAfter().getRepository(REPO_NAME);
repo = getNonRecordingGitHub().getRepository(REPO_NAME);
Arrays.asList(PATH_SCRIPT, PATH_README, PATH_DATA1, PATH_DATA2).forEach(path -> {
try {
GHContent content = repo.getFileContent(path);

View File

@@ -371,7 +371,7 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
return;
}
GHRepository nonRecordingRepo = getGitHubBeforeAfter().getRepository(REPO_NAME);
GHRepository nonRecordingRepo = getNonRecordingGitHub().getRepository(REPO_NAME);
Awaitility.await().pollInterval(Duration.ofSeconds(5)).atMost(Duration.ofSeconds(60)).until(() -> {
return condition.apply(nonRecordingRepo);

View File

@@ -23,7 +23,7 @@ public class GHWorkflowTest extends AbstractGitHubWireMockTest {
@After
public void cleanup() throws Exception {
if (mockGitHub.isUseProxy()) {
repo = getGitHubBeforeAfter().getRepository(REPO_NAME);
repo = getNonRecordingGitHub().getRepository(REPO_NAME);
// we need to make sure the workflow is enabled before the tests
GHWorkflow workflow = repo.getWorkflow("test-workflow.yml");

View File

@@ -43,11 +43,11 @@ public class GitHubCachingTest extends AbstractGitHubWireMockTest {
@Before
public void setupRepo() throws Exception {
if (mockGitHub.isUseProxy()) {
for (GHPullRequest pr : getRepository(this.getGitHubBeforeAfter()).getPullRequests(GHIssueState.OPEN)) {
for (GHPullRequest pr : getRepository(this.getNonRecordingGitHub()).getPullRequests(GHIssueState.OPEN)) {
pr.close();
}
try {
GHRef ref = getRepository(this.getGitHubBeforeAfter()).getRef(testRefName);
GHRef ref = getRepository(this.getNonRecordingGitHub()).getRef(testRefName);
ref.delete();
} catch (IOException e) {
}

View File

@@ -73,7 +73,7 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest {
@Before
public void setupRepo() throws Exception {
if (mockGitHub.isUseProxy()) {
GHRepository repo = getRepository(getGitHubBeforeAfter());
GHRepository repo = getRepository(getNonRecordingGitHub());
repo.setDescription("Resetting");
// Let things settle a bit between tests when working against the live site
@@ -252,7 +252,7 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest {
// Get Tricky - make a change via a different client
if (mockGitHub.isUseProxy()) {
GHRepository altRepo = getRepository(getGitHubBeforeAfter());
GHRepository altRepo = getRepository(getNonRecordingGitHub());
altRepo.setDescription("Tricky");
}

View File

@@ -45,11 +45,11 @@ public class GitHubCachingTest extends AbstractGitHubWireMockTest {
@Before
public void setupRepo() throws Exception {
if (mockGitHub.isUseProxy()) {
for (GHPullRequest pr : getRepository(this.getGitHubBeforeAfter()).getPullRequests(GHIssueState.OPEN)) {
for (GHPullRequest pr : getRepository(this.getNonRecordingGitHub()).getPullRequests(GHIssueState.OPEN)) {
pr.close();
}
try {
GHRef ref = getRepository(this.getGitHubBeforeAfter()).getRef(testRefName);
GHRef ref = getRepository(this.getNonRecordingGitHub()).getRef(testRefName);
ref.delete();
} catch (IOException e) {
}

View File

@@ -79,7 +79,7 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest {
@Before
public void setupRepo() throws Exception {
if (mockGitHub.isUseProxy()) {
GHRepository repo = getRepository(getGitHubBeforeAfter());
GHRepository repo = getRepository(getNonRecordingGitHub());
repo.setDescription("Resetting");
// Let things settle a bit between tests when working against the live site
@@ -261,7 +261,7 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest {
// Get Tricky - make a change via a different client
if (mockGitHub.isUseProxy()) {
GHRepository altRepo = getRepository(getGitHubBeforeAfter());
GHRepository altRepo = getRepository(getNonRecordingGitHub());
altRepo.setDescription("Tricky");
}