-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently, failure to access http://example.com causes failure of the Networking Diagnostic portion of the diagnose command. To improve the experience for users who are unable to access http://example.com, this change: 1. Adds a fallback URI - if accessing http://example.com throws an exception, we now try http://httpforever.com. 2. Prints a warning when either the primary or both the primary and fallback uris throw an exception (instead of failing the Networking Diagnostic).
- Loading branch information
1 parent
0d70623
commit 303996a
Showing
3 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Text; | ||
using GitCredentialManager.Diagnostics; | ||
using GitCredentialManager.Tests.Objects; | ||
using Xunit; | ||
|
||
namespace Core.Tests.Commands; | ||
|
||
public class DiagnoseCommandTests | ||
{ | ||
[Theory] | ||
[InlineData(false, false, 0, "Sending HEAD request to http://example.com... OK\n")] | ||
[InlineData(true, false, 1, "Sending HEAD request to http://example.com... warning: HEAD request failed.\n" + | ||
"Sending HEAD request to http://httpforever.com... OK\n")] | ||
[InlineData(false, true, 1, "Sending HEAD request to http://example.com... warning: HEAD request failed.\n" + | ||
"Sending HEAD request to http://httpforever.com... warning: HEAD request failed.\n")] | ||
public void NetworkingDiagnostic_SendHttpRequest(bool simulatePrimaryUriFailure, bool simulateNoNetwork, | ||
int expectedBackupCalls, string expectedOutput) | ||
{ | ||
var primaryUriString = "http://example.com"; | ||
var backupUriString = "http://httpforever.com"; | ||
var sb = new StringBuilder(); | ||
var context = new TestCommandContext(); | ||
var networkingDiagnostic = new NetworkingDiagnostic(context); | ||
var primaryUri = new Uri(primaryUriString); | ||
var backupUri = new Uri(backupUriString); | ||
var httpHandler = new TestHttpMessageHandler | ||
{ | ||
SimulatePrimaryUriFailure = simulatePrimaryUriFailure, | ||
SimulateNoNetwork = simulateNoNetwork | ||
}; | ||
var httpResponse = new HttpResponseMessage(); | ||
|
||
httpHandler.Setup(HttpMethod.Head, primaryUri, httpResponse); | ||
httpHandler.Setup(HttpMethod.Head, backupUri, httpResponse); | ||
|
||
networkingDiagnostic.SendHttpRequest(sb, new HttpClient(httpHandler)); | ||
|
||
httpHandler.AssertRequest(HttpMethod.Head, primaryUri, expectedNumberOfCalls: 1); | ||
httpHandler.AssertRequest(HttpMethod.Head, backupUri, expectedNumberOfCalls: expectedBackupCalls); | ||
Assert.Equal(expectedOutput, sb.ToString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters