Skip to content

Commit 85bc283

Browse files
authored
Update pipeline: use ubuntu instead of windows, fix code bugs that happen in ubuntu (#20)
Update pipeline: use ubuntu instead of windows, fix code bugs that happen in ubuntu
1 parent 90330b7 commit 85bc283

File tree

9 files changed

+97
-57
lines changed

9 files changed

+97
-57
lines changed

.github/workflows/pipeline.yml

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,55 +29,47 @@ env:
2929

3030
jobs:
3131
build:
32-
runs-on: windows-latest
32+
runs-on: ubuntu-latest
3333

3434
steps:
35+
3536
- name: Set version
3637
id: versioner
3738
run: |
38-
if($env:GITHUB_EVENT_NAME -like "release") {
39-
#example refs/tags/v2.0.33
40-
$parts = $env:GITHUB_REF.Split("/")
41-
$version=$parts[2]
42-
# remove the V from the version, .net builder doesn't accept strings
43-
$version = $version.Replace("v", "")
44-
SET $version=%version:~1%
45-
}
46-
else {
47-
$version="0.0.$env:GITHUB_RUN_NUMBER"
48-
}
49-
echo "::set-output name=VERSION::$version"
50-
Write-Host "$env:GITHUB_EVENT_NAME ($env:GITHUB_REF) generated version $version"
39+
if [[ ${{ github.event_name }} == 'release' ]]; then
40+
version="${github.ref##*/}"
41+
version="${version/[^0-9.]/}"
42+
else
43+
version="0.0.${{ github.run_number }}"
44+
# Add your commands for non-release events (command B)
45+
fi
46+
47+
echo "${{ github.event_name }} ${{ github.ref }} generated version $version"
48+
echo "Version=${version}" >> $GITHUB_OUTPUT
49+
5150
- name: Setup .NET core 3.1.x
52-
uses: actions/setup-dotnet@v3
51+
uses: actions/setup-dotnet@v4
5352
with:
5453
dotnet-version: '3.1.x'
55-
- uses: actions/checkout@v2
56-
- name: Create folder
57-
run: mkdir BuildReports
54+
- uses: actions/checkout@v4
5855
- name: Install dependencies
59-
run: dotnet restore --verbosity m > BuildReports/Restore.txt
56+
run: dotnet restore --verbosity m
6057
- name: Build
61-
run: |
62-
Write-Host "Version ${{steps.versioner.outputs.VERSION}}"
63-
dotnet build --no-restore --verbosity m --configuration Release /p:Version=${{ steps.versioner.outputs.VERSION }} > BuildReports/Build.txt
58+
run: dotnet build --no-restore --verbosity m --configuration Release /p:Version=${{ steps.versioner.outputs.Version }}
6459
- name: Test
65-
run: dotnet test --no-build --configuration Release > BuildReports/Tests.txt
60+
run: dotnet test --no-build --configuration Release --verbosity quiet --logger "trx" --results-directory "TestResults"
61+
- name: Test Report
62+
uses: dorny/test-reporter@v1
63+
if: success() || failure()
64+
with:
65+
name: Tests Reports
66+
path: TestResults/*
67+
reporter: dotnet-trx
6668
- name: Copy generated nuget file
67-
shell: bash
6869
run: find . -name "SystemTestingTools*.nupkg" -exec cp "{}" ./ \;
69-
- name: Set build report artifacts
70-
if: ${{ always() }} # run this step even if previous steps failed
71-
uses: actions/upload-artifact@v2
72-
with:
73-
name: BuildReports
74-
path: |
75-
BuildReports/**
76-
retention-days: 7
77-
if-no-files-found: error
7870
- name: Set nuget package artifact
7971
if: ${{ success() }} # run this step even if previous steps failed
80-
uses: actions/upload-artifact@v2
72+
uses: actions/upload-artifact@v4
8173
with:
8274
name: NugetPackage
8375
path: SystemTestingTools*.nupkg
@@ -89,7 +81,7 @@ jobs:
8981
if: github.event_name == 'release'
9082
runs-on: ubuntu-latest
9183
steps:
92-
- uses: actions/download-artifact@v2
84+
- uses: actions/download-artifact@v4
9385
with:
9486
name: NugetPackage
9587
- name: Push to NuGet Feed

Examples/MovieProject/MovieProject.Tests/MovieProject.InterceptionUnhappyTests/GetMovieTests.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public async Task When_UserAsksForMovie_ButWrongUrl_Then_FindResponseInPreApprov
2727
// arrange
2828
var client = Fixture.Server.CreateClient();
2929
client.CreateSession();
30-
string errorMessage = "GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=matrix received exception [No such host is known.]";
30+
31+
var possibleErrorMessages = new string[] { "GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=matrix received exception [No such host is known.]", // windows
32+
"GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=matrix received exception [Name or service not known]" }; // ubuntu
33+
3134

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

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

7174
var movie = await httpResponse.ReadJsonBody<Logic.DTO.Media>();
7275
movie.Id.Should().Be("tt0133093");
@@ -88,17 +91,22 @@ public async Task When_UserAsksForMovie_ButWrongUrl_AndNoRecordingFound_Then_Ret
8891
using (new AssertionScope())
8992
{
9093
// assert logs
91-
string errorMessage = "GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=gibberish received exception [No such host is known.]";
94+
95+
string errorMessageWindows = "GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=gibberish received exception [No such host is known.]"; // windows error message
96+
string errorMessageUbuntu = "GET http://www.omdbapifake.com/?apikey=863d6589&type=movie&t=gibberish received exception [Name or service not known]"; // ubuntu error message
97+
9298
var logs = client.GetSessionLogs();
9399
logs.Should().HaveCount(1);
94-
logs[0].ToString().Should().Be($"Error: {errorMessage}");
100+
logs[0].ToString().Should().BeOneOf($"Error: {errorMessageWindows}", $"Error: {errorMessageUbuntu}");
95101

96102
// assert outgoing
97103
AssertOutgoingRequests(client);
98104

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

103111
var movie = await httpResponse.ReadJsonBody<Logic.DTO.Media>();
104112
movie.Id.Should().Be("tt0123456");

Examples/MovieProject/MovieProject.Tests/MovieProject.IsolatedTests/ComponentTesting/MathHappyTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using FluentAssertions;
22
using FluentAssertions.Execution;
33
using System.Collections.Generic;
4+
using System.IO;
45
using System.Linq;
56
using System.Net;
67
using System.Net.Http;
@@ -29,11 +30,11 @@ public async Task When_CallingManyWcfMethods_Then_CanPerformMath_Successfully()
2930
// arrange
3031
var client = Fixture.Server.CreateClient();
3132
client.CreateSession();
32-
33-
var addResponse = ResponseFactory.FromFiddlerLikeResponseFile($"{Fixture.StubsFolder}/MathWcf/Real_Responses/Happy/200_Add.txt");
33+
34+
var addResponse = ResponseFactory.FromFiddlerLikeResponseFile($"{Fixture.StubsFolder}/MathWCF/Real_Responses/Happy/200_Add.txt");
3435
client.AppendHttpCallStub(HttpMethod.Post, new System.Uri(Url), addResponse, new Dictionary<string, string>() { { "SOAPAction", @"""http://tempuri.org/Add""" } });
3536

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

3940
// act

Tool/SystemTestingTools.UnitTests/MockEndpointUnhappyTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FluentAssertions;
22
using System;
3+
using System.IO;
34
using System.Text.RegularExpressions;
45
using Xunit;
56

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

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

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

2930
[Fact]

Tool/SystemTestingTools.UnitTests/RecordingManagerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public async Task GetRecordings_Including_Old_One_And_ResendAndUpdate_Works()
120120
// asserts
121121
recordings.Count.Should().Be(3);
122122

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

126126
await AssertHappyRecording(recordings[1]);
127127
await AssertUnhappyRecording(recordings[2]);

Tool/SystemTestingTools.UnitTests/ValueObjectsTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using FluentAssertions.Execution;
33
using System;
44
using System.IO;
5+
using System.Numerics;
56
using System.Text.RegularExpressions;
67
using Xunit;
78

@@ -54,13 +55,15 @@ public void FileFullPath_Empty_Unhappy()
5455
}
5556

5657
[Fact]
57-
public void FileFullPath_FileDoesntExist_Unhappy()
58+
public void FileFullPath_FolderDoesntExist_Unhappy()
5859
{
5960
var fullFileName = FilesFolder + @"happy/401_InvalidKeyAAA";
6061

61-
var ex = Assert.Throws<ArgumentException>(() => { FileFullPath file = fullFileName; });
62+
var ex = Assert.Throws<DirectoryNotFoundException>(() => { FileFullPath file = fullFileName; });
6263

63-
ex.Message.Should().Be($"Could not find file '{fullFileName}.txt'");
64+
var folder = Path.GetDirectoryName(fullFileName);
65+
66+
ex.Message.Should().StartWith($"Could not find folder '{folder}', the only folder that exist is ");
6467
}
6568

6669
[Fact]

Tool/SystemTestingTools/Internal/RecordingFormatter.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Net.Http;
66
using System.Net.Http.Headers;
77
using System.Reflection;
8+
using System.ServiceModel.Channels;
89
using System.Text;
910
using System.Text.RegularExpressions;
1011
using System.Threading.Tasks;
@@ -153,7 +154,7 @@ public static bool IsValid(string content)
153154
// part 1 = date time of the recording
154155
// part 2 = request details
155156
// part 3 = response details
156-
private static Regex RecordingRegex = new Regex(@".+?\nDate:(.+?)\n.+?REQUEST.+?\n(.+?)--\!\?@Divider:.+?\n(.*)", RegexOptions.Compiled | RegexOptions.Singleline);
157+
private static Regex RecordingRegex = new Regex(@".+?\nDate:(.+?)\n.+?REQUEST.*?\n(.+?)--\!\?@Divider:.+?\n(.*)", RegexOptions.Compiled | RegexOptions.Singleline);
157158

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

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

187-
if (!match.Success) throw new ApplicationException("Could not parse request data");
188+
if (!match.Success) throw new ApplicationException($"Could not parse request data");
188189

189190
var result = new HttpRequestMessage();
190191

191-
result.Method = new HttpMethod(match.Groups[1].Value);
192+
var method = match.Groups[1].Value.Trim();
193+
try
194+
{
195+
result.Method = new HttpMethod(method);
196+
}
197+
catch (System.FormatException ex)
198+
{
199+
throw new Exception($"Method [{method}] is invalid", ex);
200+
}
201+
192202
result.RequestUri = new Uri(match.Groups[2].Value);
193203

194204
result.Content = Helper.ParseHeadersAndBody(match.Groups[3].Value, match.Groups[5].Value, result.Headers);

Tool/SystemTestingTools/Internal/RecordingManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public List<Recording> GetRecordings(FolderAbsolutePath folder)
6262
recording.File = StandardizeFileNameForDisplay(folder, fullFilePath);
6363
list.Add(recording);
6464
}
65+
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
6566
return list;
6667
}
6768

Tool/SystemTestingTools/ValueObjects/FileFullPath.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using static SystemTestingTools.Helper;
45
using static SystemTestingTools.Internal.Enums;
56

@@ -17,7 +18,30 @@ public class FileFullPath : StringValueObject
1718
public FileFullPath(string value) : base(value)
1819
{
1920
if (!Path.HasExtension(_value)) _value += ".txt";
20-
if (!File.Exists(_value)) throw new ArgumentException($"Could not find file '{_value}'");
21+
22+
var folder = Path.GetDirectoryName(_value);
23+
24+
CheckFolderExists(folder);
25+
26+
if (!File.Exists(_value))
27+
{
28+
var filesCount = Directory.GetFiles(folder).Length;
29+
throw new FileNotFoundException($"Could not find file '{_value}', there are {filesCount} other files in the folder {folder}");
30+
}
31+
}
32+
33+
private static void CheckFolderExists(string folder)
34+
{
35+
if (Directory.Exists(folder)) return;
36+
37+
string parentFolder = folder;
38+
do
39+
{
40+
parentFolder = Path.GetDirectoryName(parentFolder);
41+
} while (!Directory.Exists(parentFolder) && !string.IsNullOrEmpty(parentFolder));
42+
43+
44+
throw new DirectoryNotFoundException($"Could not find folder '{folder}', the only folder that exist is '{parentFolder}'");
2145
}
2246

2347
public string ReadContent()

0 commit comments

Comments
 (0)