Skip to content

Commit

Permalink
(Tests) Add unit tests (#140)
Browse files Browse the repository at this point in the history
* Remove Fluxzy directory from codecov ignore list

The 'src/Fluxzy' directory was mistakenly added to the codecov ignore list. This commit corrects this by removing it from the list, ensuring that this directory is now considered in the code coverage reports.

* Add Fluxzy component to codecov.yml

This commit includes the Fluxzy main component in the codecov file, defining its paths for tracking. It helps to accurately measure the test coverage for the overall Fluxzy project.

* Add new test data

* Add unit tests for SearchTextFilter

New tests have been added for SearchTextFilter in the Fluxzy application. These tests assess a variety of scenarios, including searching in the request body, request header, response body, and response header.

* Add 'with-request-payload.fxzy' to Fluxzy.Tests

This update includes the addition of 'with-request-payload.fxzy' to the Fluxzy.Tests project. The file has been marked to preserve the newest copy when it is output.

* Remove LegacyPcapWriter class

The LegacyPcapWriter class was removed from the Fluxzy.Core.Pcap project. This was a deprecated class handling specific pcap writing activities, which are now handled by more efficient or updated components within the system. This aims to improve the overall efficiency and maintainability of the code.

* Add NSubstitute package to Fluxzy.Tests.csproj
.

* Refactor ResponseSuggestedExtension method in HeaderUtility class

The ResponseSuggestedExtension method in HeaderUtility.cs file was refactored to avoid redundant code and promote reusability. The response type check was replaced with a call to a new method that performs the same task, reducing code length and improving readability.

* Fix bad GetHashCode that prevents equality
.

* Add HeaderUtility unit tests

This commit introduces unit tests for the HeaderUtility class in the Fluxzy.Tests project. These tests utilize example content types and validate returns for the following methods: GetRequestSuggestedExtension, GetResponseSuggestedExtension, and GetSimplifiedContentType.

* Add equality tests for various classes

This commit introduces specific equality tests for `Authority`, `FluxzyEndPoint`, `ProxyBindPoint`, `SystemProxySetting` and `Tag` classes. These tests utilize a base testing class `EqualityTesterBase` which provides a standard test structure and enforces equality and non-equality checks for each class.

* Update codecov.yml to ignore debugging code

In the updated configuration for Codecov, debugging related files under "src/Fluxzy.Core/Clients" and "src/Fluxzy.Core/Misc/Streams" directories are added to be ignored. This means these files are no longer considered in code coverage statistics.

* Add ArchiveReader unit tests

This commit introduces unit tests for ArchiveReader in the Fluxzy.Tests project. Each test thoroughly inspects different aspects of the ArchiveReader's functionality and assures that all components are properly working. Separate tests have been also created for FluxzyArchiveReader and DirectoryArchiveReader.

* Add additional assertions in EqualityTesterBase unit tests

These changes refine the unit tests by adding more assertions for equality and inequality in the EqualityTesterBase class. This includes checks for object equivalence and verifies that a string labeled "notEqual" is also recognized as not equal.

* Add ClientErrorEquality unit test
.

* Remove BOM

* Add ImportEngineProvider unit tests

A new ImportEngineProvider unit test file has been added to improve the code coverage. Changes also include minor adjustments in the Fluxzy.Tests.csproj and ImportEngineProvider.cs files, such as copy-to-output directory options and coding style.

* Add unit tests for Agent and AuthorityInfo equality

This commit introduces two new unit tests. These tests are for the equality operators of the Agent and AuthorityInfo classes. They ensure that instances of these classes are properly evaluated for their equivalence or lack thereof.

* Increase timeouts in proxy and OS detection

The timeout in AddHocConfigurableProxy has been increased from 20 to 40 to allow for more flexibility. Timeout for OS detection under OSX platform has also been extended from 40 to 60, allowing more time for slower systems and preventing premature termination.

---------

Co-authored-by: fluxzy-ci <admin@fluxzy.io>
  • Loading branch information
haga-rak and fluxzy-ci authored Jan 9, 2024
1 parent 18ce7be commit 4da7514
Show file tree
Hide file tree
Showing 30 changed files with 759 additions and 251 deletions.
10 changes: 9 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ component_management:
name: Fluxzy.Core
paths:
- src/Fluxzy.Core/**
- component_id: Fluxzy
name: Fluxzy
paths:
- src/Fluxzy/**
ignore:
- "src/Fluxzy.Core.Pcap/**"
- "src/Fluxzy.Core.Pcap.Cli/**"
- "src/Fluxzy.Core.Pcap/**"
- "src/Fluxzy.Extensions/**"
- "src/Fluxzy.Tools.DocGen/**"
- "src/Fluxzy/**"

# Ignore debugging code
- "src/Fluxzy.Core/Clients/H2Logger.cs"
- "src/Fluxzy.Core/Clients/H1Logger.cs"
- "src/Fluxzy.Core/Misc/Streams/DebugFileStream.cs"
201 changes: 0 additions & 201 deletions src/Fluxzy.Core.Pcap/LegacyPcapWriter.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Fluxzy.Core/Archiving/Readers/ImportEngineProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ImportEngineProvider(FxzyDirectoryPackager directoryPackager)

public IReadOnlyCollection<IImportEngine> Engines { get; }

public IImportEngine? GetImportEngine(string fileName)
public IImportEngine? GetImportEngine(string fileName)
{
return Engines.FirstOrDefault(r => r.IsFormat(fileName));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fluxzy.Core/Core/Proxy/SystemProxySetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override bool Equals(object? obj)

public override int GetHashCode()
{
return HashCode.Combine(BoundHost, ListenPort, ByPassHosts);
return HashCode.Combine(BoundHost, ListenPort);
}
}
}
4 changes: 2 additions & 2 deletions src/Fluxzy.Core/Core/ProxyOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ await exchange.Context.BreakPointContext.RequestHeaderCompletion
if (exchange.Context.HasRequestBodySubstitution) {
originalRequestBodyStream = exchange.Request.Body;
exchange.Request.Body = await
exchange.Context.GetSubstitutedRequestBody(exchange.Request.Body, exchange);
exchange.Context.GetSubstitutedRequestBody(exchange.Request.Body!, exchange);
}

exchange.Request.Body = new DispatchStream(exchange.Request.Body,
exchange.Request.Body = new DispatchStream(exchange.Request.Body!,
true,
_archiveWriter.CreateRequestBodyStream(exchange.Id));
}
Expand Down
49 changes: 6 additions & 43 deletions src/Fluxzy.Core/Utils/HeaderUtility.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2021 - Haga Rakotoharivelo - https://github.com/haga-rak

using System;
using System.Buffers;
using System.Linq;
using Fluxzy.Clients.H2.Encoder.Utils;

Expand All @@ -16,6 +15,11 @@ public static string GetResponseSuggestedExtension(IExchange exchange)
?.Where(r => r.Name.Span.Equals("content-type", StringComparison.OrdinalIgnoreCase))
.LastOrDefault();

return ResponseSuggestedExtension(contentTypeHeader);
}

internal static string ResponseSuggestedExtension(HeaderFieldInfo? contentTypeHeader)
{
if (contentTypeHeader == null)
return "data";

Expand Down Expand Up @@ -67,48 +71,7 @@ public static string GetRequestSuggestedExtension(IExchange exchange)
?.Where(r => r.Name.Span.Equals("content-type", StringComparison.OrdinalIgnoreCase))
.LastOrDefault();

if (contentTypeHeader == null)
return "data";

if (contentTypeHeader.Value.Span.Contains("json", StringComparison.OrdinalIgnoreCase))
return "json";

if (contentTypeHeader.Value.Span.Contains("html", StringComparison.OrdinalIgnoreCase))
return "html";

if (contentTypeHeader.Value.Span.Contains("css", StringComparison.OrdinalIgnoreCase))
return "css";

if (contentTypeHeader.Value.Span.Contains("xml", StringComparison.OrdinalIgnoreCase))
return "xml";

if (contentTypeHeader.Value.Span.Contains("javascript", StringComparison.OrdinalIgnoreCase))
return "js";

if (contentTypeHeader.Value.Span.Contains("font", StringComparison.OrdinalIgnoreCase))
return "font";

if (contentTypeHeader.Value.Span.Contains("png", StringComparison.OrdinalIgnoreCase))
return "png";

if (contentTypeHeader.Value.Span.Contains("jpeg", StringComparison.OrdinalIgnoreCase)
|| contentTypeHeader.Value.Span.Contains("jpg", StringComparison.OrdinalIgnoreCase)
)
return "jpeg";

if (contentTypeHeader.Value.Span.Contains("gif", StringComparison.OrdinalIgnoreCase))
return "gif";

if (contentTypeHeader.Value.Span.Contains("svg", StringComparison.OrdinalIgnoreCase))
return "svg";

if (contentTypeHeader.Value.Span.Contains("pdf", StringComparison.OrdinalIgnoreCase))
return "pdf";

if (contentTypeHeader.Value.Span.Contains("text", StringComparison.OrdinalIgnoreCase))
return "txt";

return "data";
return ResponseSuggestedExtension(contentTypeHeader);
}

public static string? GetSimplifiedContentType(IExchange exchange)
Expand Down
6 changes: 6 additions & 0 deletions src/Fluxzy.Core/Utils/SubdomainUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public static bool TryGetSubDomain(string host, out string? subDomain)
return true;
}

if (splittedHost.Length == 2) {
subDomain = host;

return true;
}

subDomain = null;

return false;
Expand Down
10 changes: 10 additions & 0 deletions test/Fluxzy.Tests/Fluxzy.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@
<ItemGroup>
<None Remove="_Files\Headers\Req001.txt.bin" />
<None Remove="_Files\Headers\Resp001.txt.bin" />
<None Update="_Files\Archives\minimal.saz">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="_Files\Archives\pink-floyd.fxzy">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="_Files\Archives\testarchive.saz">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="_Files\Archives\with-request-payload.fxzy">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="_Files\Certificates\fluxzytest.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -40,6 +49,7 @@
<ItemGroup>
<PackageReference Include="fluxzy.sandbox.models" Version="1.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="System.Threading.AccessControl" Version="8.0.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
Expand Down
2 changes: 1 addition & 1 deletion test/Fluxzy.Tests/TimeoutConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static int Regular {
get
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
return 40;
return 60;
}
else {
return 15;
Expand Down
Loading

0 comments on commit 4da7514

Please sign in to comment.