-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Begin implementation of Enterprise ManagementConsole API #1269
Changes from 12 commits
3b34c01
676ea3b
d4f1a9c
e23400f
4177441
46495e1
bdaf56f
1b772f3
d9fec7e
1313348
644898e
5d2bc5e
9f0704d
567db46
b75573c
4a94554
579d20d
83c25f0
17e4102
8a42bb0
fc0aa33
19ab15b
47c9525
6de9ade
cddf3ba
20b217a
e11f275
b31eac4
c5d220f
2a08269
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Octokit.Reactive | ||
{ | ||
/// <summary> | ||
/// A client for GitHub's Enterprise Management Console API | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/enterprise/management_console/">Enterprise Management Console API documentation</a> for more information. | ||
/// </remarks> | ||
public interface IObservableEnterpriseManagementConsoleClient | ||
{ | ||
/// <summary> | ||
/// Gets GitHub Enterprise Maintenance Mode Status | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status | ||
/// </remarks> | ||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns> | ||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] | ||
IObservable<MaintenanceModeResponse> GetMaintenanceMode(string managementConsolePassword); | ||
|
||
/// <summary> | ||
/// Sets GitHub Enterprise Maintenance Mode | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status | ||
/// </remarks> | ||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns> | ||
IObservable<MaintenanceModeResponse> EditMaintenanceMode(UpdateMaintenanceRequest maintenance, string managementConsolePassword); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Reactive.Threading.Tasks; | ||
|
||
namespace Octokit.Reactive | ||
{ | ||
/// <summary> | ||
/// A client for GitHub's Enterprise Management Console API | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/enterprise/management_console/">Enterprise Management Console API documentation</a> for more information. | ||
/// </remarks> | ||
public class ObservableEnterpriseManagementConsoleClient : IObservableEnterpriseManagementConsoleClient | ||
{ | ||
readonly IEnterpriseManagementConsoleClient _client; | ||
|
||
public ObservableEnterpriseManagementConsoleClient(IGitHubClient client) | ||
{ | ||
Ensure.ArgumentNotNull(client, "client"); | ||
|
||
_client = client.Enterprise.ManagementConsole; | ||
} | ||
|
||
/// <summary> | ||
/// Gets GitHub Enterprise Maintenance Mode Status | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status | ||
/// </remarks> | ||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns> | ||
public IObservable<MaintenanceModeResponse> GetMaintenanceMode(string managementConsolePassword) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(managementConsolePassword, "managementConsolePassword"); | ||
|
||
return _client.GetMaintenanceMode(managementConsolePassword).ToObservable(); | ||
} | ||
|
||
/// <summary> | ||
/// Sets GitHub Enterprise Maintenance Mode | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status | ||
/// </remarks> | ||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns> | ||
public IObservable<MaintenanceModeResponse> EditMaintenanceMode(UpdateMaintenanceRequest maintenance, string managementConsolePassword) | ||
{ | ||
Ensure.ArgumentNotNull(maintenance, "maintenance"); | ||
Ensure.ArgumentNotNullOrEmptyString(managementConsolePassword, "managementConsolePassword"); | ||
|
||
return _client.EditMaintenanceMode(maintenance, managementConsolePassword).ToObservable(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Octokit; | ||
using Octokit.Tests.Integration; | ||
using Xunit; | ||
|
||
public class EnterpriseManagementConsoleClientTests | ||
{ | ||
readonly IGitHubClient _github; | ||
|
||
public EnterpriseManagementConsoleClientTests() | ||
{ | ||
_github = EnterpriseHelper.GetAuthenticatedClient(); | ||
} | ||
|
||
[GitHubEnterpriseTest] | ||
public async Task CanGetMaintenanceMode() | ||
{ | ||
var maintenance = await _github.Enterprise.ManagementConsole.GetMaintenanceMode("Password01"); | ||
|
||
Assert.NotNull(maintenance); | ||
} | ||
|
||
[GitHubEnterpriseTest] | ||
public async Task CanSetMaintenanceModeOff() | ||
{ | ||
// Set maintenance mode OFF now | ||
var maintenance = await | ||
_github.Enterprise.ManagementConsole.EditMaintenanceMode( | ||
new UpdateMaintenanceRequest(), | ||
EnterpriseHelper.ManagementConsolePassword); | ||
|
||
Assert.NotNull(maintenance); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 - the next assert will cover this |
||
Assert.Equal(maintenance.Status, MaintenanceModeStatus.Off); | ||
} | ||
|
||
[GitHubEnterpriseTest] | ||
public async Task CanSetMaintenanceModeOnNow() | ||
{ | ||
// Set maintenance mode ON now | ||
var maintenance = await | ||
_github.Enterprise.ManagementConsole.EditMaintenanceMode( | ||
new UpdateMaintenanceRequest(true, MaintenanceDate.Now()), | ||
EnterpriseHelper.ManagementConsolePassword); | ||
|
||
Assert.NotNull(maintenance); | ||
Assert.Equal(maintenance.Status, MaintenanceModeStatus.On); | ||
|
||
// Ensure maintenance mode is OFF | ||
await _github.Enterprise.ManagementConsole.EditMaintenanceMode( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't seem to be doing any asserting here? Will the request will fail here if the GHE server is not in the right state? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From memory I wrote these tests to always return maintenance mode status back to a consistent state afterwards, so this was just ensuring matinenance mode was OFF after the test which turned it ON. Or are you saying we should actually assert this here anyway? Or potentially do it using a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm neutral on this, but I guess if "ensure maintenance mode is off" needs to be done with each test it should be done in teardown. Just me misreading the test a bit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should you need me do? |
||
new UpdateMaintenanceRequest(), | ||
EnterpriseHelper.ManagementConsolePassword); | ||
} | ||
|
||
[GitHubEnterpriseTest] | ||
public async Task CanScheduleMaintenanceModeOnWithDateTime() | ||
{ | ||
// Schedule maintenance mode ON in 5 minutes | ||
var scheduledTime = DateTimeOffset.Now.AddMinutes(5); | ||
var maintenance = await | ||
_github.Enterprise.ManagementConsole.EditMaintenanceMode( | ||
new UpdateMaintenanceRequest(true, MaintenanceDate.FromDateTimeOffset(scheduledTime)), | ||
EnterpriseHelper.ManagementConsolePassword); | ||
|
||
Assert.NotNull(maintenance); | ||
Assert.Equal(maintenance.Status, MaintenanceModeStatus.Scheduled); | ||
|
||
// Ensure maintenance mode is OFF | ||
await _github.Enterprise.ManagementConsole.EditMaintenanceMode( | ||
new UpdateMaintenanceRequest(), | ||
EnterpriseHelper.ManagementConsolePassword); | ||
} | ||
|
||
[GitHubEnterpriseTest] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these tests need a specific attribute that verifies the existence of |
||
public async Task CanScheduleMaintenanceModeOnWithPhrase() | ||
{ | ||
// Schedule maintenance mode ON | ||
var maintenance = await | ||
_github.Enterprise.ManagementConsole.EditMaintenanceMode( | ||
new UpdateMaintenanceRequest(true, MaintenanceDate.FromChronicValue("tomorrow at 5pm")), | ||
EnterpriseHelper.ManagementConsolePassword); | ||
|
||
Assert.NotNull(maintenance); | ||
Assert.Equal(maintenance.Status, MaintenanceModeStatus.Scheduled); | ||
|
||
// Ensure maintenance mode is OFF | ||
await _github.Enterprise.ManagementConsole.EditMaintenanceMode( | ||
new UpdateMaintenanceRequest(), | ||
EnterpriseHelper.ManagementConsolePassword); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this string be
EnterpriseHelper.ManagementConsolePassword
?