Skip to content

Commit

Permalink
Merge pull request #19 from deqenq/Add_support_for_reporting_HTTP_errors
Browse files Browse the repository at this point in the history
Adds support for reporting HTTP errors (#8)
  • Loading branch information
ecampidoglio authored Feb 24, 2019
2 parents bcdea1a + 52ed319 commit 89e2235
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Cake.Curl.Tests/CurlDownloadFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,38 @@ public void Should_Not_Set_The_Location_Option_As_Argument()
// Then
Assert.DoesNotContain("--location", result.Args);
}

[Fact]
public void Should_Set_The_Fail_Option_As_Argument()
{
// Given
var fixture = new CurlDownloadFileFixture
{
Settings = { Fail = true }
};

// When
var result = fixture.Run();

// Then
Assert.Contains("--fail", result.Args);
}

[Fact]
public void Should_Not_Set_The_Fail_Option_As_Argument()
{
// Given
var fixture = new CurlDownloadFileFixture
{
Settings = { Fail = false }
};

// When
var result = fixture.Run();

// Then
Assert.DoesNotContain("--fail", result.Args);
}
}
}
}
32 changes: 32 additions & 0 deletions src/Cake.Curl.Tests/CurlDownloadMultipleFilesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,38 @@ public void Should_Not_Set_The_Location_Option_As_Argument()
// Then
Assert.DoesNotContain("--location", result.Args);
}

[Fact]
public void Should_Set_The_Fail_Option_As_Argument()
{
// Given
var fixture = new CurlDownloadMultipleFilesFixture
{
Settings = { Fail = true }
};

// When
var result = fixture.Run();

// Then
Assert.Contains("--fail", result.Args);
}

[Fact]
public void Should_Not_Set_The_Fail_Option_As_Argument()
{
// Given
var fixture = new CurlDownloadFileFixture
{
Settings = { Fail = false }
};

// When
var result = fixture.Run();

// Then
Assert.DoesNotContain("--fail", result.Args);
}
}
}
}
32 changes: 32 additions & 0 deletions src/Cake.Curl.Tests/CurlUploadFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,38 @@ public void Should_Not_Set_The_Location_Option_As_Argument()
// Then
Assert.DoesNotContain("--location", result.Args);
}

[Fact]
public void Should_Set_The_Fail_Option_As_Argument()
{
// Given
var fixture = new CurlUploadFileFixture
{
Settings = { Fail = true }
};

// When
var result = fixture.Run();

// Then
Assert.Contains("--fail", result.Args);
}

[Fact]
public void Should_Not_Set_The_Fail_Option_As_Argument()
{
// Given
var fixture = new CurlDownloadFileFixture
{
Settings = { Fail = false }
};

// When
var result = fixture.Run();

// Then
Assert.DoesNotContain("--fail", result.Args);
}
}
}
}
5 changes: 5 additions & 0 deletions src/Cake.Curl/ArgumentsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ internal static void AppendSettings(
{
arguments.Append("--location");
}

if (settings.Fail)
{
arguments.Append("--fail");
}
}
}
}
13 changes: 13 additions & 0 deletions src/Cake.Curl/CurlSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,18 @@ public class CurlSettings : ToolSettings
/// as the one specified in the original request.
/// </remarks>
public bool FollowRedirects { get; set; }

/// <summary>
/// Gets or sets a value indicating whether HTTP errors above 400 should result in return code 22.
/// </summary>
/// <remarks>
/// (HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable scripts etc
/// to better deal with failed attempts.
/// In normal cases when an HTTP server fails to deliver a document, it returns an HTML document stating so
/// (which often also describes why and more). This flag will prevent curl from outputting that and return error 22.
/// This method is not fail-safe and there are occasions where non-successful response codes will slip through,
/// especially when authentication is involved(response codes 401 and 407).
/// </remarks>
public bool Fail { get; set; }
}
}

0 comments on commit 89e2235

Please sign in to comment.