Skip to content

Commit

Permalink
Merge pull request #1004 from TattsGroup/github-enterprise-testhelper
Browse files Browse the repository at this point in the history
Add support to run integration tests against GitHub Enterprise
  • Loading branch information
shiftkey committed Dec 20, 2015
2 parents 05ff6af + 7f69669 commit 4c8b7be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 18 additions & 6 deletions Octokit.Tests.Integration/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ public static class Helper
return null;

return new Credentials(githubUsername, githubPassword);
});
});

static readonly Lazy<Uri> _gitHubEnterpriseUrl = new Lazy<Uri>(() =>
{
string uri = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBENTERPRISEURL");

if (uri != null)
return new Uri(uri);

return null;
});

static Helper()
{
Expand All @@ -67,6 +77,8 @@ static Helper()

public static Credentials BasicAuthCredentials { get { return _basicAuthCredentials.Value; } }

public static Uri GitHubEnterpriseUrl { get { return _gitHubEnterpriseUrl.Value; } }

public static bool IsUsingToken
{
get
Expand Down Expand Up @@ -128,36 +140,36 @@ public static Stream LoadFixture(string fileName)

public static IGitHubClient GetAuthenticatedClient()
{
return new GitHubClient(new ProductHeaderValue("OctokitTests"))
return new GitHubClient(new ProductHeaderValue("OctokitTests"), GitHubEnterpriseUrl ?? GitHubClient.GitHubApiUrl)
{
Credentials = Credentials
};
}

public static IGitHubClient GetBasicAuthClient()
{
return new GitHubClient(new ProductHeaderValue("OctokitTests"))
return new GitHubClient(new ProductHeaderValue("OctokitTests"), GitHubEnterpriseUrl ?? GitHubClient.GitHubApiUrl)
{
Credentials = BasicAuthCredentials
};
}

public static GitHubClient GetAuthenticatedApplicationClient()
{
return new GitHubClient(new ProductHeaderValue("OctokitTests"))
return new GitHubClient(new ProductHeaderValue("OctokitTests"), GitHubEnterpriseUrl ?? GitHubClient.GitHubApiUrl)
{
Credentials = ApplicationCredentials
};
}

public static IGitHubClient GetAnonymousClient()
{
return new GitHubClient(new ProductHeaderValue("OctokitTests"));
return new GitHubClient(new ProductHeaderValue("OctokitTests"), GitHubEnterpriseUrl ?? GitHubClient.GitHubApiUrl);
}

public static IGitHubClient GetBadCredentialsClient()
{
return new GitHubClient(new ProductHeaderValue("OctokitTests"))
return new GitHubClient(new ProductHeaderValue("OctokitTests"), GitHubEnterpriseUrl ?? GitHubClient.GitHubApiUrl)
{
Credentials = new Credentials(Guid.NewGuid().ToString(), "bad-password")
};
Expand Down
2 changes: 2 additions & 0 deletions script/configure-integration-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@ AskYesNoQuestion "Do you have private repositories associated with your test acc

VerifyEnvironmentVariable "organization name" "OCTOKIT_GITHUBORGANIZATION" $true

VerifyEnvironmentVariable "GitHub Enterprise Server URL" "OCTOKIT_GITHUBENTERPRISEURL" $true

VerifyEnvironmentVariable "application ClientID" "OCTOKIT_CLIENTID" $true
VerifyEnvironmentVariable "application Secret" "OCTOKIT_CLIENTSECRET" $true

0 comments on commit 4c8b7be

Please sign in to comment.