Merge pull request #29 from octokit/half-ogre/automation-settings

Keep automation settings in the environment
This commit is contained in:
Drew Miller
2013-09-17 09:54:48 -07:00
8 changed files with 120 additions and 26 deletions
@@ -1,6 +1,5 @@
using System.Threading.Tasks;
using FluentAssertions;
using Octokit.Http;
using Xunit;
namespace Octokit.Tests.Integration
@@ -9,12 +8,12 @@ namespace Octokit.Tests.Integration
{
public class TheGetEmojisMethod
{
[Fact]
[IntegrationTest]
public async Task GetsAllTheEmojis()
{
var github = new GitHubClient
{
Credentials = new Credentials("xapitestaccountx", "octocat11")
Credentials = AutomationSettings.Current.GitHubCredentials
};
var emojis = await github.AutoComplete.GetEmojis();
@@ -0,0 +1,61 @@
using System;
using Octokit.Http;
namespace Octokit.Tests.Integration
{
/// <summary>
/// Settings for executing automated tests.
/// </summary>
public class AutomationSettings
{
static readonly Lazy<AutomationSettings> automationSettingsThunk = new Lazy<AutomationSettings>(() =>
{
var githubUsername = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBUSERNAME");
var githubPassword = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBPASSWORD");
return new AutomationSettings(githubUsername, githubPassword);
});
/// <summary>
/// The current automation settings.
/// </summary>
public static AutomationSettings Current
{
get
{
return automationSettingsThunk.Value;
}
}
/// <summary>
/// Creates a new instance of settings for executing automated tests.
/// </summary>
/// <param name="githubUsername">Username of a GitHub test account (DO NOT USE A "REAL" ACCOUNT)</param>
/// <param name="githubPassword">Password for a GitHub test account (DO NOT USE A "REAL" ACCOUNT)</param>
public AutomationSettings(string githubUsername, string githubPassword)
{
GitHubUsername = githubUsername;
GitHubPassword = githubPassword;
if (GitHubUsername != null && GitHubPassword != null)
GitHubCredentials = new Credentials(
GitHubUsername,
GitHubPassword);
}
/// <summary>
/// <see cref="Octokit.Http.Credentials"/> for a GitHub test account (DO NOT USE A "REAL" ACCOUNT).
/// </summary>
public Credentials GitHubCredentials { get; private set; }
/// <summary>
/// Password for a GitHub test account (DO NOT USE A "REAL" ACCOUNT).
/// </summary>
public string GitHubPassword { get; private set; }
/// <summary>
/// Username of a GitHub test account (DO NOT USE A "REAL" ACCOUNT).
/// </summary>
public string GitHubUsername { get; private set; }
}
}
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using Xunit;
using Xunit.Sdk;
namespace Octokit.Tests.Integration
{
public class IntegrationTestAttribute : FactAttribute
{
protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo testMethod)
{
if (AutomationSettings.Current.GitHubCredentials == null)
yield return new SkipCommand(testMethod, MethodUtility.GetDisplayName(testMethod), "Automation settings not configured. Please set the OCTOKIT_GITHUBUSERNAME and OCTOKIT_GITHUBPASSWORD environment variables to a GitHub test account (i.e, DO NOT USE A \"REAL\" ACCOUNT).");
else
yield return new FactCommand(testMethod);
}
}
}
@@ -50,6 +50,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AutoCompleteClientTests.cs" />
<Compile Include="AutomationSettings.cs" />
<Compile Include="IntegrationTestAttribute.cs" />
<Compile Include="RepositoriesClientTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UsersClientTests.cs" />
@@ -1,6 +1,5 @@
using System.Threading.Tasks;
using FluentAssertions;
using Octokit.Http;
using Xunit;
namespace Octokit.Tests.Integration
@@ -9,12 +8,12 @@ namespace Octokit.Tests.Integration
{
public class TheGetAsyncMethod
{
[Fact]
[IntegrationTest]
public async Task ReturnsSpecifiedUser()
{
var github = new GitHubClient
{
Credentials = new Credentials("xapitestaccountx", "octocat11")
Credentials = AutomationSettings.Current.GitHubCredentials
};
var repository = await github.Repository.Get("ReactiveCocoa", "ReactiveCocoa");
@@ -25,12 +24,12 @@ namespace Octokit.Tests.Integration
public class TheGetAllForOrgMethod
{
[Fact]
[IntegrationTest]
public async Task ReturnsAllRepositoriesForOrganization()
{
var github = new GitHubClient
{
Credentials = new Credentials("xapitestaccountx", "octocat11")
Credentials = AutomationSettings.Current.GitHubCredentials
};
var repositories = await github.Repository.GetAllForOrg("github");
@@ -41,12 +40,12 @@ namespace Octokit.Tests.Integration
public class TheGetReadmeMethod
{
[Fact]
[IntegrationTest]
public async Task ReturnsReadmeForOctokit()
{
var github = new GitHubClient
{
Credentials = new Credentials("xapitestaccountx", "octocat11")
Credentials = AutomationSettings.Current.GitHubCredentials
};
// TODO: Change this to request github/Octokit.net once we make this OSS.
+13 -15
View File
@@ -1,6 +1,4 @@
using System;
using System.Net;
using System.Net.Http;
using System.Net;
using System.Threading.Tasks;
using FluentAssertions;
using Octokit.Http;
@@ -13,12 +11,12 @@ namespace Octokit.Tests.Integration
{
public class TheGetMethod
{
[Fact]
[IntegrationTest]
public async Task ReturnsSpecifiedUser()
{
var github = new GitHubClient
{
Credentials = new Credentials("xapitestaccountx", "octocat11")
Credentials = AutomationSettings.Current.GitHubCredentials
};
// Get a user by username
@@ -30,29 +28,29 @@ namespace Octokit.Tests.Integration
public class TheCurrentMethod
{
[Fact]
[IntegrationTest]
public async Task ReturnsSpecifiedUser()
{
var github = new GitHubClient
{
Credentials = new Credentials("xapitestaccountx", "octocat11")
Credentials = AutomationSettings.Current.GitHubCredentials
};
var user = await github.User.Current();
user.Login.Should().Be("xapitestaccountx");
user.Login.Should().Be(AutomationSettings.Current.GitHubUsername);
}
}
public class TheUpdateMethod
{
[Fact]
[IntegrationTest]
public async Task FailsWhenNotAuthenticated()
{
var github = new GitHubClient();
var userUpdate = new UserUpdate
{
Name = "xapitestaccountx",
{
Name = AutomationSettings.Current.GitHubUsername,
Bio = "UPDATED BIO"
};
@@ -61,16 +59,16 @@ namespace Octokit.Tests.Integration
e.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
}
[Fact]
[IntegrationTest]
public async Task FailsWhenAuthenticatedWithBadCredentials()
{
var github = new GitHubClient
{
Credentials = new Credentials("xapitestaccountx", "bad-password")
Credentials = new Credentials(AutomationSettings.Current.GitHubUsername, "bad-password")
};
var userUpdate = new UserUpdate
{
Name = "xapitestaccountx",
{
Name = AutomationSettings.Current.GitHubUsername,
Bio = "UPDATED BIO"
};
+7 -1
View File
@@ -17,9 +17,15 @@
<xunit Assembly=".\Octokit.Tests\bin\$(Configuration)\Octokit.Tests.dll" Xml="Octokit.Tests.results.xml" />
</Target>
<Target Name="RunIntegrationTests" DependsOnTargets="Build">
<Target Name="RunIntegrationTests" DependsOnTargets="Build; DoNotSkipIntegrationTests; SkipIntegrationTests" />
<Target Name="DoNotSkipIntegrationTests" DependsOnTargets="Build" Condition=" '$(OCTOKIT_GITHUBUSERNAME)'!='' And '$(OCTOKIT_GITHUBPASSWORD)'!='' " >
<xunit Assembly=".\Octokit.Tests.Integration\bin\$(Configuration)\Octokit.Tests.Integration.dll" Xml="Octokit.Tests.Integration.results.xml" />
</Target>
<Target Name="SkipIntegrationTests" DependsOnTargets="Build" Condition=" '$(OCTOKIT_GITHUBUSERNAME)'=='' Or '$(OCTOKIT_GITHUBPASSWORD)'=='' ">
<Warning Text ="The integration tests were skipped because the OCTOKIT_GITHUBUSERNAME and OCTOKIT_GITHUBUSERNAME environment variables are not set. Please configure these environment variables for a GitHub test account (DO NOT USE A &quot;REAL&quot; ACCOUNT)." />
</Target>
<Target Name="FullBuild" DependsOnTargets="RunUnitTests; RunIntegrationTests" />
</Project>
+12
View File
@@ -38,6 +38,18 @@ cd Octokit
.\build.cmd
```
## Integration Tests
Octokit has integration tests that access the GitHub API, but they must be configured before they will be executed.
To configure the tests, create a test GitHub account (i.e., **don't use your real GitHub account**) and then set
the following two environment variables:
- `OCTOKIT_GITHUBUSERNAME` (set this to the test account's username)
- `OCTOKIT_GITHUBPASSWORD` (set this to the test account's password)
Once both of 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.
## Problems?
Octokit is 100% certified to be bug free. If you find an issue with our