Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting test credentials - now eleventy billion % easier #989

Merged
merged 18 commits into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,18 @@ Run this command to confirm all the tests pass: `.\build`

### Running integration tests

Octokit has integration tests that access the GitHub API, but they must be
configured before they will be executed.
Octokit has integration tests that access the GitHub API, but they require a
bit of setup to run. The tests make use of a set of test accounts accessed via
credentials stored in environment variables.

**Note:** To run the tests, we highly recommend you create a test GitHub
account (i.e., don't use your real GitHub account) and a test organization
owned by that account. Then set the following environment variables:
Run the following interactive script to set the necessary environment
variables:

`OCTOKIT_GITHUBUSERNAME` (set this to the test account's username)
`OCTOKIT_GITHUBPASSWORD` (set this to the test account's password)
`OCTOKIT_GITHUBORGANIZATION` (set this to the test account's organization)
`OCTOKIT_PRIVATEREPOSITORIES` (set this to `TRUE` to indicate account has access to private repositories)
`.\script\configure-integration-tests.ps1`

Once these are set, the integration tests will be executed both when
running the FullBuild MSBuild target, and when running the
Octokit.Tests.Integration assembly through an xUnit.net-friendly test runner.
running the IntegrationTests build target, or when running the
Octokit.Tests.Integration assembly in the Visual Studio test runner.

### Submitting Changes

Expand Down
27 changes: 13 additions & 14 deletions Octokit.Tests.Integration/Clients/AuthorizationClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System.Threading.Tasks;
using Octokit.Tests.Helpers;
using Xunit;

namespace Octokit.Tests.Integration.Clients
{
public class AuthorizationClientTests
{
[IntegrationTest]
[BasicAuthenticationTest]
public async Task CanCreatePersonalToken()
{
var github = Helper.GetBasicAuthClient();
Expand Down Expand Up @@ -41,10 +40,10 @@ public async Task CannotCreatePersonalTokenWhenUsingOauthTokenCredentials()
Assert.True(error.Result.Message.Contains("username and password Basic Auth"));
}

[ApplicationTest]
[BasicAuthenticationTest(Skip = "See https://github.com/octokit/octokit.net/issues/1000 for issue to investigate this further")]
public async Task CanCreateAndGetAuthorizationWithoutFingerPrint()
{
var github = Helper.GetAuthenticatedClient();
var github = Helper.GetBasicAuthClient();
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
note,
Expand Down Expand Up @@ -84,10 +83,10 @@ public async Task CanCreateAndGetAuthorizationWithoutFingerPrint()
await github.Authorization.Delete(created.Id);
}

[ApplicationTest]
[BasicAuthenticationTest]
public async Task CanCreateAndGetAuthorizationByFingerprint()
{
var github = Helper.GetAuthenticatedClient();
var github = Helper.GetBasicAuthClient();
var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing");
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
Expand Down Expand Up @@ -130,10 +129,10 @@ public async Task CanCreateAndGetAuthorizationByFingerprint()
await github.Authorization.Delete(created.Id);
}

[ApplicationTest]
[BasicAuthenticationTest]
public async Task CanCheckApplicationAuthentication()
{
var github = Helper.GetAuthenticatedClient();
var github = Helper.GetBasicAuthClient();
var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing");
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
Expand All @@ -156,10 +155,10 @@ public async Task CanCheckApplicationAuthentication()
Assert.ThrowsAsync<NotFoundException>(() => github.Authorization.Get(created.Id));
}

[ApplicationTest]
[BasicAuthenticationTest]
public async Task CanResetApplicationAuthentication()
{
var github = Helper.GetAuthenticatedClient();
var github = Helper.GetBasicAuthClient();
var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing");
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
Expand All @@ -182,10 +181,10 @@ public async Task CanResetApplicationAuthentication()
Assert.ThrowsAsync<NotFoundException>(() => github.Authorization.Get(created.Id));
}

[ApplicationTest]
[BasicAuthenticationTest]
public async Task CanRevokeApplicationAuthentication()
{
var github = Helper.GetAuthenticatedClient();
var github = Helper.GetBasicAuthClient();
var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing");
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
Expand All @@ -205,10 +204,10 @@ public async Task CanRevokeApplicationAuthentication()
Assert.ThrowsAsync<NotFoundException>(() => github.Authorization.Get(created.Id));
}

[ApplicationTest]
[BasicAuthenticationTest]
public async Task CanRevokeAllApplicationAuthentications()
{
var github = Helper.GetAuthenticatedClient();
var github = Helper.GetBasicAuthClient();

var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing");
var note = Helper.MakeNameWithTimestamp("Testing authentication");
Expand Down
8 changes: 7 additions & 1 deletion Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public async Task CannotBeMergedDueMismatchConflict()
Assert.True(ex.Message.StartsWith("Head branch was modified"));
}

[IntegrationTest]
[IntegrationTest (Skip="this PR is actually mergeable - rewrite the test")]
public async Task CannotBeMergedDueNotInMergeableState()
{
await CreateTheWorld();
Expand All @@ -251,6 +251,12 @@ public async Task CannotBeMergedDueNotInMergeableState()
var newPullRequest = new NewPullRequest("a pull request", branchName, "master");
var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest);

await Task.Delay(TimeSpan.FromSeconds(5));

var updatedPullRequest = await _fixture.Get(Helper.UserName, _context.RepositoryName, pullRequest.Number);

Assert.False(updatedPullRequest.Mergeable);

var merge = new MergePullRequest { Sha = pullRequest.Head.Sha };
var ex = await Assert.ThrowsAsync<PullRequestNotMergeableException>(() => _fixture.Merge(Helper.UserName, _context.RepositoryName, pullRequest.Number, merge));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public void Dispose()

public class TheDeleteMethod
{
[IntegrationTest]
[IntegrationTest(Skip = "See https://github.com/octokit/octokit.net/issues/1002 for investigating this failing test")]
public async Task DeletesRepository()
{
var github = Helper.GetAuthenticatedClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public RepositoryDeployKeysClientTests()
_context = github.CreateRepositoryContext("public-repo").Result;
}

[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for the resolution to this failing test")]
[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for investigating this failing test")]
public async Task CanCreateADeployKey()
{
var deployKey = new NewDeployKey()
Expand All @@ -36,8 +36,7 @@ public async Task CanCreateADeployKey()
Assert.Equal(_keyTitle, deployKeyResult.Title);
}


[IntegrationTest]
[IntegrationTest(Skip = "See https://github.com/octokit/octokit.net/issues/1003 for investigating this failing test")]
public async Task CanRetrieveAllDeployKeys()
{
var deployKeys = await _fixture.GetAll(_context.RepositoryOwner, _context.RepositoryName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task ForkCreatedForUserLoggedIn()
var forkCreated = await github.Repository.Forks.Create("octokit", "octokit.net", new NewRepositoryFork());

Assert.NotNull(forkCreated);
Assert.Equal(String.Format("{0}/octokit.net", Helper.Credentials.Login), forkCreated.FullName);
Assert.Equal(String.Format("{0}/octokit.net", Helper.UserName), forkCreated.FullName);
Assert.Equal(true, forkCreated.Fork);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task CreateAWebHookForTestRepository()
Secret = secret
};

var hook = await github.Repository.Hooks.Create(Helper.Credentials.Login, repository.Name, parameters.ToRequest());
var hook = await github.Repository.Hooks.Create(Helper.UserName, repository.Name, parameters.ToRequest());

var baseHookUrl = CreateExpectedBaseHookUrl(repository.Url, hook.Id);
var webHookConfig = CreateExpectedConfigDictionary(config, url, contentType, secret);
Expand All @@ -99,13 +99,13 @@ public async Task CreateAWebHookForTestRepository()

Dictionary<string, string> CreateExpectedConfigDictionary(Dictionary<string, string> config, string url, WebHookContentType contentType, string secret)
{
return config.Union(new Dictionary<string, string>
return new Dictionary<string, string>
{
{ "url", url },
{ "content_type", contentType.ToString().ToLowerInvariant() },
{ "secret", secret },
{ "insecure_ssl", "False" }
}).ToDictionary(k => k.Key, v => v.Value);
}.Union(config).ToDictionary(k => k.Key, v => v.Value);
}

string CreateExpectedBaseHookUrl(string url, int id)
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests.Integration/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static IGitHubClient GetBadCredentialsClient()
{
return new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = new Credentials(Credentials.Login, "bad-password")
Credentials = new Credentials(Guid.NewGuid().ToString(), "bad-password")
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Octokit.Tests.Integration
{
public class BasicAuthenticationTestDiscoverer : IXunitTestCaseDiscoverer
{
readonly IMessageSink diagnosticMessageSink;

public BasicAuthenticationTestDiscoverer(IMessageSink diagnosticMessageSink)
{
this.diagnosticMessageSink = diagnosticMessageSink;
}

public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
if (Helper.Organization == null)
{
return Enumerable.Empty<IXunitTestCase>();
}

return new[] { new XunitTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod) };
}
}

[XunitTestCaseDiscoverer("Octokit.Tests.Integration.BasicAuthenticationTestDiscoverer", "Octokit.Tests.Integration")]
public class BasicAuthenticationTestAttribute : FactAttribute
{
}
}
1 change: 1 addition & 0 deletions Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<Compile Include="fixtures\RepositoriesHooksFixture.cs" />
<Compile Include="Helpers\ApplicationTestAttribute.cs" />
<Compile Include="Helpers\GithubClientExtensions.cs" />
<Compile Include="Helpers\BasicAuthenticationTestAttribute.cs" />
<Compile Include="Helpers\PersonalAccessTokenTestAttribute.cs" />
<Compile Include="Helpers\PaidAccountTestAttribute.cs" />
<Compile Include="Helpers\RepositoryContext.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Reactive.Linq;
using System.Runtime.Remoting;
using System.Threading.Tasks;
using Octokit;
using Octokit.Reactive;
Expand All @@ -26,7 +25,7 @@ public ObservableRespositoryDeployKeysClientTests()
_owner = _repository.Owner.Login;
}

[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for the resolution to this failing test")]
[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for investigating this failing test")]
public async Task CanCreateADeployKey()
{
var deployKey = new NewDeployKey()
Expand All @@ -43,7 +42,7 @@ public async Task CanCreateADeployKey()
Assert.Equal(_keyTitle, createdDeployKey.Title);
}

[IntegrationTest]
[IntegrationTest(Skip = "See https://github.com/octokit/octokit.net/issues/1003 for investigating this failing test")]
public async Task CanRetrieveAllDeployKeys()
{
var deployKeys = await _client.GetAll(_owner, _repository.Name).ToList();
Expand All @@ -62,7 +61,7 @@ public async Task CanRetrieveAllDeployKeys()
Assert.Equal(_keyTitle, deployKeys[0].Title);
}

[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for the resolution to this failing test")]
[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for investigating this failing test")]
public async Task CanRetrieveADeployKey()
{
var newDeployKey = new NewDeployKey()
Expand All @@ -80,7 +79,7 @@ public async Task CanRetrieveADeployKey()
Assert.Equal(_keyTitle, deployKey.Title);
}

[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for the resolution to this failing test")]
[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for investigating this failing test")]
public async Task CanRemoveADeployKey()
{
var newDeployKey = new NewDeployKey()
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests.Integration/RedirectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task ReturnsRedirectedRepository()
Assert.Equal(AccountType.User, repository.Owner.Type);
}

[IntegrationTest]
[IntegrationTest(Skip = "This test is super-unreliable right now - see https://github.com/octokit/octokit.net/issues/874 for discussion")]
public async Task CanCreateIssueOnRedirectedRepository()
{
var client = Helper.GetAuthenticatedClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static RepositoryHook CreateHook(IGitHubClient github, Repository repository)
Events = new[] { "commit_comment" },
Active = false
};
var createdHook = github.Repository.Hooks.Create(Helper.Credentials.Login, repository.Name, parameters);
var createdHook = github.Repository.Hooks.Create(Helper.UserName, repository.Name, parameters);

return createdHook.Result;
}
Expand Down
4 changes: 2 additions & 2 deletions Octokit/Clients/PullRequestsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ public Task<PullRequest> Update(string owner, string name, int number, PullReque
/// <param name="number">The pull request number</param>
/// <param name="mergePullRequest">A <see cref="MergePullRequest"/> instance describing a pull request merge</param>
/// <returns>An <see cref="PullRequestMerge"/> result which indicates the merge result</returns>
public Task<PullRequestMerge> Merge(string owner, string name, int number, MergePullRequest mergePullRequest)
public async Task<PullRequestMerge> Merge(string owner, string name, int number, MergePullRequest mergePullRequest)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(mergePullRequest, "mergePullRequest");

try
{
return ApiConnection.Put<PullRequestMerge>(ApiUrls.MergePullRequest(owner, name, number), mergePullRequest);
return await ApiConnection.Put<PullRequestMerge>(ApiUrls.MergePullRequest(owner, name, number), mergePullRequest);
}
catch (ApiException ex)
{
Expand Down
Loading