From de29d64b278a0e1aa1ea7e1761ab86b08ef46b83 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Mon, 14 Dec 2015 14:42:30 +1000 Subject: [PATCH] Add support to run integration tests against GitHub Enterprise If environment variable "OCTOKIT_GITHUBENTERPRISEURL" is set, this is used on the configured clients, otherwise the default GitHub URL is used --- Octokit.Tests.Integration/Helper.cs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index 17815e34..7c8b12ab 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -48,7 +48,17 @@ namespace Octokit.Tests.Integration return null; return new Credentials(githubUsername, githubPassword); - }); + }); + + static readonly Lazy _gitHubEnterpriseUrl = new Lazy(() => + { + string uri = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBENTERPRISEURL"); + + if (uri != null) + return new Uri(uri); + + return null; + }); static Helper() { @@ -67,6 +77,8 @@ namespace Octokit.Tests.Integration public static Credentials BasicAuthCredentials { get { return _basicAuthCredentials.Value; } } + public static Uri GitHubEnterpriseUrl { get { return _gitHubEnterpriseUrl.Value; } } + public static bool IsUsingToken { get @@ -128,7 +140,7 @@ namespace Octokit.Tests.Integration public static IGitHubClient GetAuthenticatedClient() { - return new GitHubClient(new ProductHeaderValue("OctokitTests")) + return new GitHubClient(new ProductHeaderValue("OctokitTests"), GitHubEnterpriseUrl ?? GitHubClient.GitHubApiUrl) { Credentials = Credentials }; @@ -136,7 +148,7 @@ namespace Octokit.Tests.Integration public static IGitHubClient GetBasicAuthClient() { - return new GitHubClient(new ProductHeaderValue("OctokitTests")) + return new GitHubClient(new ProductHeaderValue("OctokitTests"), GitHubEnterpriseUrl ?? GitHubClient.GitHubApiUrl) { Credentials = BasicAuthCredentials }; @@ -144,7 +156,7 @@ namespace Octokit.Tests.Integration public static GitHubClient GetAuthenticatedApplicationClient() { - return new GitHubClient(new ProductHeaderValue("OctokitTests")) + return new GitHubClient(new ProductHeaderValue("OctokitTests"), GitHubEnterpriseUrl ?? GitHubClient.GitHubApiUrl) { Credentials = ApplicationCredentials }; @@ -152,12 +164,12 @@ namespace Octokit.Tests.Integration 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(Credentials.Login, "bad-password") };