Skip to content

Commit

Permalink
fix for GH Enterprise which does not have rate limit reset field
Browse files Browse the repository at this point in the history
  • Loading branch information
MerkushevKirill committed Jun 11, 2015
1 parent b976e0e commit c7b8c65
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;

import org.apache.commons.codec.binary.Base64;

Expand Down Expand Up @@ -248,6 +249,7 @@ public GHRateLimit getRateLimit() throws IOException {
// see issue #78
GHRateLimit r = new GHRateLimit();
r.limit = r.remaining = 1000000;
r.reset = new Date(System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1));
return r;
}
}
Expand Down
30 changes: 22 additions & 8 deletions src/test/java/org/kohsuke/github/GitHubTest.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
package org.kohsuke.github;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import junit.framework.TestCase;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

/**
* Unit test for {@link GitHub}.
*/
public class GitHubTest extends TestCase {

public class GitHubTest {
@Test
public void testGitHubServerWithHttp() throws Exception {
GitHub hub = GitHub.connectToEnterprise("http://enterprise.kohsuke.org/api/v3", "bogus","bogus");
assertEquals("http://enterprise.kohsuke.org/api/v3/test", hub.getApiURL("/test").toString());
}

@Test
public void testGitHubServerWithHttps() throws Exception {
GitHub hub = GitHub.connectToEnterprise("https://enterprise.kohsuke.org/api/v3", "bogus","bogus");
assertEquals("https://enterprise.kohsuke.org/api/v3/test", hub.getApiURL("/test").toString());
}

@Test
public void testGitHubServerWithoutServer() throws Exception {
GitHub hub = GitHub.connectUsingPassword("kohsuke", "bogus");
assertEquals("https://api.github.com/test", hub.getApiURL("/test").toString());
}

@Test
public void testGitHubBuilderFromEnvironment() throws IOException {

Map<String, String>props = new HashMap<String, String>();
Expand Down Expand Up @@ -86,7 +92,7 @@ private void setupEnvironment(Map<String, String> newenv) {
e1.printStackTrace();
}
}

@Test
public void testGitHubBuilderFromCustomEnvironment() throws IOException {
Map<String, String> props = new HashMap<String, String>();

Expand All @@ -105,4 +111,12 @@ public void testGitHubBuilderFromCustomEnvironment() throws IOException {
assertEquals("bogusEndpoint", builder.endpoint);
}

@Test
public void testGitHubEnterpriseDoesNotHaveRateLimit() throws IOException {
GitHub github = spy(new GitHubBuilder().build());
when(github.retrieve()).thenThrow(FileNotFoundException.class);

GHRateLimit rateLimit = github.getRateLimit();
assertThat(rateLimit.getResetDate(), notNullValue());
}
}

0 comments on commit c7b8c65

Please sign in to comment.