Begin implementation of Enterprise ManagementConsole API, redux (#2010)

* Initial implementation of ManagementConsole - maintenance mode

* Add environment var support for management console password for integration tests

* Add reactive client and unit tests

* Update some xmlDoc

* I think this is a better way to setup the underlying baseUri on IConneciton, to achieve managemet console access rather than requiring a specific GitHubClient that cant call normal API's
Instead, the management client methods can check the base Url and if it contains /api/v3/ they can set their relative endpoint Uri to include a leading "/" which will cause the /api/v3/ to be removed.

* Update EnterpriseClient.cs

Fix xml comments

* Update IEnterpriseClient.cs

Fix xml comments

* Still trying to get the xmDoc perfect, thanks app veyor :)

* XmlDoc'ing my way to success

* Add specific test attribute for management console tests

* check chronic string empty/null

* Use helper's password field in test

* Tidy up maintenance mode tests by using a context/destructor to manage the initial/end state of maintenance mode

* make internal and tidy up URL concatenation

* move GHE endpoint fixup inside ApiUrls methods

* Rework request object to be the correct structure so SimpleJsonSerializer can be used to serialize it.  Remove MaintenanceDate class and just pass in the Date/string for when
Still need to use UrlFormEncoding rather than json in the POST body though...

* Create abstract base class for FormUrlEncoded parameters (similar to existing RequetParameters) and inherit from it in UpdateMaintenanceRequest

* Fix maintenance context logic - destructor should always turn maintenance OFF regardless of initial requested state

* Fix xml comment

* Fix Xml comment

* Those pesky xml comments!

* Fine, I give up!

* Fix string.Format

* fix bad rebase

* fix failing convention tests

* restore missing whitespace

* writing some docs

* some edits

* edit
This commit is contained in:
Brendan Forster
2019-09-22 15:09:56 -03:00
committed by GitHub
parent fafbf33b78
commit 8cd0b341dd
37 changed files with 965 additions and 40 deletions
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Octokit.Tests.Integration
{
public class GitHubEnterpriseManagementConsoleTestDiscoverer : IXunitTestCaseDiscoverer
{
readonly IMessageSink diagnosticMessageSink;
public GitHubEnterpriseManagementConsoleTestDiscoverer(IMessageSink diagnosticMessageSink)
{
this.diagnosticMessageSink = diagnosticMessageSink;
}
public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
if (Helper.Credentials == null)
return Enumerable.Empty<IXunitTestCase>();
if (!EnterpriseHelper.IsGitHubEnterpriseEnabled)
return Enumerable.Empty<IXunitTestCase>();
if (String.IsNullOrEmpty(EnterpriseHelper.ManagementConsolePassword))
return Enumerable.Empty<IXunitTestCase>();
return new[] { new XunitTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod) };
}
}
[XunitTestCaseDiscoverer("Octokit.Tests.Integration.GitHubEnterpriseManagementConsoleTestDiscoverer", "Octokit.Tests.Integration")]
public class GitHubEnterpriseManagementConsoleTestAttribute : FactAttribute
{
}
}
@@ -79,5 +79,10 @@ VO/+BCBsaoT4g1FFOmJhbBAD3G72yslBnUJmqKP/39pi
return new GpgKeyContext(client.Connection, key);
}
internal static MaintenanceModeContext CreateMaintenanceModeContext(this IGitHubClient client, bool enabled)
{
return new MaintenanceModeContext(client.Connection, enabled);
}
}
}
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Octokit.Reactive;
namespace Octokit.Tests.Integration.Helpers
{
internal sealed class MaintenanceModeContext : IDisposable
{
internal MaintenanceModeContext(IConnection connection, bool enabled)
{
_connection = connection;
// Ensure maintenance mode is in the desired initial state
EnterpriseHelper.SetMaintenanceMode(_connection, enabled);
}
private IConnection _connection;
public void Dispose()
{
// Ensure maintenance mode is OFF
EnterpriseHelper.SetMaintenanceMode(_connection, false);
}
}
}