Skip to content
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

Update pipeline: use ubuntu instead of windows, fix code bugs that happen in ubuntu #20

Merged
merged 35 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
18c9652
Update pipeline: use ubuntu instead of windows, use the latest action…
AlanCS May 28, 2024
49b03cd
fixes
AlanCS May 28, 2024
9da9745
fixes
AlanCS May 28, 2024
fc59fe2
latest fixes
AlanCS May 28, 2024
546aa18
try access environment variable
AlanCS May 28, 2024
a2539e2
another attempt
AlanCS May 28, 2024
c262d03
another try
AlanCS May 28, 2024
8193674
another try
AlanCS May 28, 2024
1a2daf2
another try
AlanCS May 28, 2024
05aa696
another try
AlanCS May 28, 2024
ca3b012
Changes to work in ubuntu
AlanCS May 28, 2024
fc4851f
Better handling new lines for windows and linux
AlanCS May 28, 2024
30b693f
another attempt around linux line breaks
AlanCS May 28, 2024
b18d33f
Handling linux new line formatting
AlanCS May 28, 2024
b6399cc
another try
AlanCS May 28, 2024
d412be9
another try
AlanCS May 28, 2024
901b945
another try
AlanCS May 28, 2024
4909ae6
another test
AlanCS May 28, 2024
cf6a296
another try
AlanCS May 28, 2024
eff19f2
another try
AlanCS May 28, 2024
c4ef94e
another one
AlanCS May 28, 2024
2ece53e
another try
AlanCS May 28, 2024
d41e0ce
adding test report
AlanCS May 28, 2024
41ce08f
Another try
AlanCS May 28, 2024
262097b
improving error messages
AlanCS May 28, 2024
27791a5
adjust folder paths
AlanCS May 28, 2024
63efd84
fixing file path
AlanCS May 28, 2024
218f57a
another test
AlanCS May 28, 2024
680c726
Improving logging is so overwhelming
AlanCS May 28, 2024
e735e59
improving pipeline
AlanCS May 28, 2024
ef268dc
again
AlanCS May 28, 2024
9038106
another
AlanCS May 28, 2024
11f4cfc
Updating tests to work well with ubuntu
AlanCS May 28, 2024
62db48c
more
AlanCS May 28, 2024
325b99e
one more
AlanCS May 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 27 additions & 35 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,55 +29,47 @@ env:

jobs:
build:
runs-on: windows-latest
runs-on: ubuntu-latest

steps:

- name: Set version
id: versioner
run: |
if($env:GITHUB_EVENT_NAME -like "release") {
#example refs/tags/v2.0.33
$parts = $env:GITHUB_REF.Split("/")
$version=$parts[2]
# remove the V from the version, .net builder doesn't accept strings
$version = $version.Replace("v", "")
SET $version=%version:~1%
}
else {
$version="0.0.$env:GITHUB_RUN_NUMBER"
}
echo "::set-output name=VERSION::$version"
Write-Host "$env:GITHUB_EVENT_NAME ($env:GITHUB_REF) generated version $version"
if [[ ${{ github.event_name }} == 'release' ]]; then
version="${github.ref##*/}"
version="${version/[^0-9.]/}"
else
version="0.0.${{ github.run_number }}"
# Add your commands for non-release events (command B)
fi

echo "${{ github.event_name }} ${{ github.ref }} generated version $version"
echo "Version=${version}" >> $GITHUB_OUTPUT

- name: Setup .NET core 3.1.x
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: '3.1.x'
- uses: actions/checkout@v2
- name: Create folder
run: mkdir BuildReports
- uses: actions/checkout@v4
- name: Install dependencies
run: dotnet restore --verbosity m > BuildReports/Restore.txt
run: dotnet restore --verbosity m
- name: Build
run: |
Write-Host "Version ${{steps.versioner.outputs.VERSION}}"
dotnet build --no-restore --verbosity m --configuration Release /p:Version=${{ steps.versioner.outputs.VERSION }} > BuildReports/Build.txt
run: dotnet build --no-restore --verbosity m --configuration Release /p:Version=${{ steps.versioner.outputs.Version }}
- name: Test
run: dotnet test --no-build --configuration Release > BuildReports/Tests.txt
run: dotnet test --no-build --configuration Release --verbosity quiet --logger "trx" --results-directory "TestResults"
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Tests Reports
path: TestResults/*
reporter: dotnet-trx
- name: Copy generated nuget file
shell: bash
run: find . -name "SystemTestingTools*.nupkg" -exec cp "{}" ./ \;
- name: Set build report artifacts
if: ${{ always() }} # run this step even if previous steps failed
uses: actions/upload-artifact@v2
with:
name: BuildReports
path: |
BuildReports/**
retention-days: 7
if-no-files-found: error
- name: Set nuget package artifact
if: ${{ success() }} # run this step even if previous steps failed
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: NugetPackage
path: SystemTestingTools*.nupkg
Expand All @@ -89,7 +81,7 @@ jobs:
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: NugetPackage
- name: Push to NuGet Feed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public async Task When_UserAsksForMovie_ButWrongUrl_Then_FindResponseInPreApprov
// arrange
var client = Fixture.Server.CreateClient();
client.CreateSession();
string errorMessage = "GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=matrix received exception [No such host is known.]";

var possibleErrorMessages = new string[] { "GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=matrix received exception [No such host is known.]", // windows
"GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=matrix received exception [Name or service not known]" }; // ubuntu


// act
var httpResponse = await client.GetAsync("/api/movie/matrix");
Expand All @@ -37,7 +40,7 @@ public async Task When_UserAsksForMovie_ButWrongUrl_Then_FindResponseInPreApprov
// assert logs
var logs = client.GetSessionLogs();
logs.Should().HaveCount(1);
logs[0].ToString().Should().Be($"Error: {errorMessage}");
logs[0].ToString().Should().StartWith($"Error: ").And.ContainAny(possibleErrorMessages);

// assert outgoing
AssertOutgoingRequests(client);
Expand Down Expand Up @@ -66,7 +69,7 @@ async Task CheckResponse()
{
// assert return
httpResponse.StatusCode.Should().Be(HttpStatusCode.OK);
httpResponse.GetHeaderValue("SystemTestingToolsStub").Should().Be($@"Recording [omdb/pre-approved/happy/matrix] reason {errorMessage}");
httpResponse.GetHeaderValue("SystemTestingToolsStub").Should().StartWith($@"Recording [omdb/pre-approved/happy/matrix] reason ").And.ContainAny(possibleErrorMessages);

var movie = await httpResponse.ReadJsonBody<Logic.DTO.Media>();
movie.Id.Should().Be("tt0133093");
Expand All @@ -88,17 +91,22 @@ public async Task When_UserAsksForMovie_ButWrongUrl_AndNoRecordingFound_Then_Ret
using (new AssertionScope())
{
// assert logs
string errorMessage = "GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=gibberish received exception [No such host is known.]";

string errorMessageWindows = "GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=gibberish received exception [No such host is known.]"; // windows error message
string errorMessageUbuntu = "GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=gibberish received exception [Name or service not known]"; // ubuntu error message

var logs = client.GetSessionLogs();
logs.Should().HaveCount(1);
logs[0].ToString().Should().Be($"Error: {errorMessage}");
logs[0].ToString().Should().BeOneOf($"Error: {errorMessageWindows}", $"Error: {errorMessageUbuntu}");

// assert outgoing
AssertOutgoingRequests(client);

// assert return
httpResponse.StatusCode.Should().Be(HttpStatusCode.OK);
httpResponse.GetHeaderValue("SystemTestingToolsStub").Should().Be($@"Recording [omdb/pre-approved/happy/last_fallback] reason {errorMessage} and could not find better match");
httpResponse.GetHeaderValue("SystemTestingToolsStub").Should()
.BeOneOf($@"Recording [omdb/pre-approved/happy/last_fallback] reason {errorMessageWindows} and could not find better match",
$@"Recording [omdb/pre-approved/happy/last_fallback] reason {errorMessageUbuntu} and could not find better match");

var movie = await httpResponse.ReadJsonBody<Logic.DTO.Media>();
movie.Id.Should().Be("tt0123456");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FluentAssertions;
using FluentAssertions.Execution;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -29,11 +30,11 @@ public async Task When_CallingManyWcfMethods_Then_CanPerformMath_Successfully()
// arrange
var client = Fixture.Server.CreateClient();
client.CreateSession();

var addResponse = ResponseFactory.FromFiddlerLikeResponseFile($"{Fixture.StubsFolder}/MathWcf/Real_Responses/Happy/200_Add.txt");
var addResponse = ResponseFactory.FromFiddlerLikeResponseFile($"{Fixture.StubsFolder}/MathWCF/Real_Responses/Happy/200_Add.txt");
client.AppendHttpCallStub(HttpMethod.Post, new System.Uri(Url), addResponse, new Dictionary<string, string>() { { "SOAPAction", @"""http://tempuri.org/Add""" } });

var minusResponse = ResponseFactory.FromFiddlerLikeResponseFile($"{Fixture.StubsFolder}/MathWcf/Real_Responses/Happy/200_Minus.txt");
var minusResponse = ResponseFactory.FromFiddlerLikeResponseFile($"{Fixture.StubsFolder}/MathWCF/Real_Responses/Happy/200_Minus.txt");
client.AppendHttpCallStub(HttpMethod.Post, new System.Uri(Url), minusResponse, new Dictionary<string, string>() { { "SOAPAction", @"""http://tempuri.org/Subtract""" } });

// act
Expand Down
5 changes: 3 additions & 2 deletions Tool/SystemTestingTools.UnitTests/MockEndpointUnhappyTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FluentAssertions;
using System;
using System.IO;
using System.Text.RegularExpressions;
using Xunit;

Expand All @@ -22,8 +23,8 @@ public void FileDoesntExist()

Action act = () => ResponseFactory.FromFiddlerLikeResponseFile(fullFileName);

var exception = Assert.Throws<ArgumentException>(act);
exception.Message.Should().Be($"Could not find file '{fullFileName}'");
var exception = Assert.Throws<FileNotFoundException>(act);
exception.Message.Should().StartWith($"Could not find file '{fullFileName}', there are 0 other files in the folder ");
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions Tool/SystemTestingTools.UnitTests/RecordingManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@
// asserts
recordings.Count.Should().Be(3);

recordings[0].File.Should().Be(@"happy/200_ContainsSomeFields_PacificChallenge");
recordings[0].FileFullPath.Should().EndWith(@"recordings_temp\happy\200_ContainsSomeFields_PacificChallenge.txt");
recordings[0].File.Should().Be(@"happy/200_ContainsSomeFields_PacificChallenge");
recordings[0].FileFullPath.Should().EndWith(Path.Combine("recordings_temp","happy","200_ContainsSomeFields_PacificChallenge.txt"));

await AssertHappyRecording(recordings[1]);
await AssertUnhappyRecording(recordings[2]);
Expand All @@ -134,7 +134,7 @@
}


public static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target)

Check warning on line 137 in Tool/SystemTestingTools.UnitTests/RecordingManagerTests.cs

View workflow job for this annotation

GitHub Actions / build

Public method 'CopyFilesRecursively' on test class 'RecordingManagerTests' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 137 in Tool/SystemTestingTools.UnitTests/RecordingManagerTests.cs

View workflow job for this annotation

GitHub Actions / build

Public method 'CopyFilesRecursively' on test class 'RecordingManagerTests' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)
{
foreach (DirectoryInfo dir in source.GetDirectories())
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name));
Expand All @@ -142,7 +142,7 @@
file.CopyTo(Path.Combine(target.FullName, file.Name));
}

public static void CopyFolderAndFiles(string sourcePath, string targetPath)

Check warning on line 145 in Tool/SystemTestingTools.UnitTests/RecordingManagerTests.cs

View workflow job for this annotation

GitHub Actions / build

Public method 'CopyFolderAndFiles' on test class 'RecordingManagerTests' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 145 in Tool/SystemTestingTools.UnitTests/RecordingManagerTests.cs

View workflow job for this annotation

GitHub Actions / build

Public method 'CopyFolderAndFiles' on test class 'RecordingManagerTests' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)
{
var source = new DirectoryInfo(sourcePath);
var target = new DirectoryInfo(targetPath);
Expand Down
9 changes: 6 additions & 3 deletions Tool/SystemTestingTools.UnitTests/ValueObjectsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FluentAssertions.Execution;
using System;
using System.IO;
using System.Numerics;
using System.Text.RegularExpressions;
using Xunit;

Expand Down Expand Up @@ -54,13 +55,15 @@ public void FileFullPath_Empty_Unhappy()
}

[Fact]
public void FileFullPath_FileDoesntExist_Unhappy()
public void FileFullPath_FolderDoesntExist_Unhappy()
{
var fullFileName = FilesFolder + @"happy/401_InvalidKeyAAA";

var ex = Assert.Throws<ArgumentException>(() => { FileFullPath file = fullFileName; });
var ex = Assert.Throws<DirectoryNotFoundException>(() => { FileFullPath file = fullFileName; });

ex.Message.Should().Be($"Could not find file '{fullFileName}.txt'");
var folder = Path.GetDirectoryName(fullFileName);

ex.Message.Should().StartWith($"Could not find folder '{folder}', the only folder that exist is ");
}

[Fact]
Expand Down
20 changes: 15 additions & 5 deletions Tool/SystemTestingTools/Internal/RecordingFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.ServiceModel.Channels;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand Down Expand Up @@ -153,7 +154,7 @@ public static bool IsValid(string content)
// part 1 = date time of the recording
// part 2 = request details
// part 3 = response details
private static Regex RecordingRegex = new Regex(@".+?\nDate:(.+?)\n.+?REQUEST.+?\n(.+?)--\!\?@Divider:.+?\n(.*)", RegexOptions.Compiled | RegexOptions.Singleline);
private static Regex RecordingRegex = new Regex(@".+?\nDate:(.+?)\n.+?REQUEST.*?\n(.+?)--\!\?@Divider:.+?\n(.*)", RegexOptions.Compiled | RegexOptions.Singleline);

private static Regex DateRegex = new Regex(@"(2.+?)\(", RegexOptions.Compiled | RegexOptions.Singleline);

Expand All @@ -179,16 +180,25 @@ public static Recording Read(string content)
// headers
// white space
// body (if any)
private static Regex RequestRegex = new Regex(@"(.+?) (.+?)\n(.+?)(\r\r|\n\n|\r\n\r\n)(.*)", RegexOptions.Compiled | RegexOptions.Singleline);
private static Regex RequestRegex = new Regex(@"^(.+?) (.+?)\n(.+?)(\r\r|\n\n|\r\n\r\n)(.*)", RegexOptions.Compiled | RegexOptions.Singleline);
private static HttpRequestMessage GetRequest(string requestContent)
{
var match = RequestRegex.Match(requestContent);
var match = RequestRegex.Match(requestContent);

if (!match.Success) throw new ApplicationException("Could not parse request data");
if (!match.Success) throw new ApplicationException($"Could not parse request data");

var result = new HttpRequestMessage();

result.Method = new HttpMethod(match.Groups[1].Value);
var method = match.Groups[1].Value.Trim();
try
{
result.Method = new HttpMethod(method);
}
catch (System.FormatException ex)
{
throw new Exception($"Method [{method}] is invalid", ex);
}

result.RequestUri = new Uri(match.Groups[2].Value);

result.Content = Helper.ParseHeadersAndBody(match.Groups[3].Value, match.Groups[5].Value, result.Headers);
Expand Down
1 change: 1 addition & 0 deletions Tool/SystemTestingTools/Internal/RecordingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public List<Recording> GetRecordings(FolderAbsolutePath folder)
recording.File = StandardizeFileNameForDisplay(folder, fullFilePath);
list.Add(recording);
}
list = list.OrderBy(c => c.File).ToList(); // we sort so it's the same order in windows and linux, so we can more easily test it
return list;
}

Expand Down
26 changes: 25 additions & 1 deletion Tool/SystemTestingTools/ValueObjects/FileFullPath.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using static SystemTestingTools.Helper;
using static SystemTestingTools.Internal.Enums;

Expand All @@ -17,7 +18,30 @@ public class FileFullPath : StringValueObject
public FileFullPath(string value) : base(value)
{
if (!Path.HasExtension(_value)) _value += ".txt";
if (!File.Exists(_value)) throw new ArgumentException($"Could not find file '{_value}'");

var folder = Path.GetDirectoryName(_value);

CheckFolderExists(folder);

if (!File.Exists(_value))
{
var filesCount = Directory.GetFiles(folder).Length;
throw new FileNotFoundException($"Could not find file '{_value}', there are {filesCount} other files in the folder {folder}");
}
}

private static void CheckFolderExists(string folder)
{
if (Directory.Exists(folder)) return;

string parentFolder = folder;
do
{
parentFolder = Path.GetDirectoryName(parentFolder);
} while (!Directory.Exists(parentFolder) && !string.IsNullOrEmpty(parentFolder));


throw new DirectoryNotFoundException($"Could not find folder '{folder}', the only folder that exist is '{parentFolder}'");
}

public string ReadContent()
Expand Down
Loading