Made the test case runnable, at least for me

This commit is contained in:
Kohsuke Kawaguchi
2017-01-09 16:26:58 -08:00
parent 5b69a2925f
commit 911e8d21a7
3 changed files with 31 additions and 26 deletions

View File

@@ -1,10 +1,12 @@
package org.kohsuke.github;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.kohsuke.randname.RandomNameGenerator;
import java.io.File;
import java.io.IOException;
/**
* @author Kohsuke Kawaguchi
@@ -25,5 +27,18 @@ public abstract class AbstractGitHubApiTestBase extends Assert {
}
}
protected GHUser getUser() {
try {
return gitHub.getMyself();
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
protected void kohsuke() {
String login = getUser().getLogin();
Assume.assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));
}
protected static final RandomNameGenerator rnd = new RandomNameGenerator();
}

View File

@@ -173,14 +173,6 @@ public class AppTest extends AbstractGitHubApiTestBase {
return repository;
}
private GHUser getUser() {
try {
return gitHub.getMyself();
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
@Test
public void testListIssues() throws IOException {
GHUser u = getUser();
@@ -928,9 +920,4 @@ public class AppTest extends AbstractGitHubApiTestBase {
assertThat(content,containsString("FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR"));
assertThat(content.length(),is(1104));
}
private void kohsuke() {
String login = getUser().getLogin();
Assume.assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));
}
}

View File

@@ -1,11 +1,10 @@
package org.kohsuke.github;
import java.io.FileNotFoundException;
import org.junit.Test;
import org.kohsuke.github.GHRepository.Contributor;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.junit.Ignore;
/**
* @author Kohsuke Kawaguchi
@@ -42,19 +41,12 @@ public class RepositoryTest extends AbstractGitHubApiTestBase {
assertTrue(kohsuke);
}
@Ignore("depends on who runs this test whether it can pass or not")
@Test
public void getPermission() throws Exception {
GHRepository r = gitHub.getOrganization("cloudbeers").getRepository("yolo");
assertEquals("admin", r.getPermission("jglick").getPermission());
assertEquals("read", r.getPermission("dude").getPermission());
r = gitHub.getOrganization("cloudbees").getRepository("private-repo-not-writable-by-me");
try {
r.getPermission("jglick");
fail();
} catch (FileNotFoundException x) {
x.printStackTrace(); // good
}
kohsuke();
GHRepository r = gitHub.getRepository("github-api-test-org/test-permission");
assertEquals(GHPermissionType.ADMIN, r.getPermission("kohsuke"));
assertEquals(GHPermissionType.READ, r.getPermission("dude"));
r = gitHub.getOrganization("apache").getRepository("groovy");
try {
r.getPermission("jglick");
@@ -63,6 +55,17 @@ public class RepositoryTest extends AbstractGitHubApiTestBase {
x.printStackTrace(); // good
assertEquals(403, x.getResponseCode());
}
if (false) {
// can't easily test this; there's no private repository visible to the test user
r = gitHub.getOrganization("cloudbees").getRepository("private-repo-not-writable-by-me");
try {
r.getPermission("jglick");
fail();
} catch (FileNotFoundException x) {
x.printStackTrace(); // good
}
}
}
private GHRepository getRepository() throws IOException {