C
C#2mo ago
Core

✅ Github action fails, but running it locally via `act` succeeds

Hello, I have tests that should read files from a certain path. The entire folder content is copied after build. Can it be that the folder is not accessible by github actions?
<ItemGroup>
<None Update="TestImages\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="TestImages\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
9 Replies
Sehra
Sehra2mo ago
check so the directory is named TestImages, case sensitive
Core
CoreOP2mo ago
- name: List Files in Test Output Directory
run: ls -R ./tests/QrCode.Generator.Tests/bin/Release/net9.0/
- name: List Files in Test Output Directory
run: ls -R ./tests/QrCode.Generator.Tests/bin/Release/net9.0/
This was added, and the output was:
./tests/QrCode.Generator.Tests/bin/Release/net9.0/TestImages/Webp:
marker_1.webp
marker_10.webp
./tests/QrCode.Generator.Tests/bin/Release/net9.0/TestImages/Webp:
marker_1.webp
marker_10.webp
The naming looks fine This is the error:
Run dotnet test --configuration Release --no-build

Run tests: '/home/runner/work/qr-code-generator/qr-code-generator/tests/QrCode.Generator.Tests/bin/Release/net9.0/QrCode.Generator.Tests.dll' [net9.0|x64]
failed Generate_WithMarkerStyle_ShouldReturnPng(QrCodeMarkerStyle { Id = 2, MarkerStyle = SharpTopLeft }) (407ms)
System.NullReferenceException: Object reference not set to an instance of an object.
at QrCode.Generator.Core.QrCodeGeneratorTests.AreImagesIdentical(Byte[] generatedImage, String referenceImagePath) in /home/runner/work/qr-code-generator/qr-code-generator/tests/QrCode.Generator.Tests/Core/QrCodeGeneratorTests.cs:115****
Run dotnet test --configuration Release --no-build

Run tests: '/home/runner/work/qr-code-generator/qr-code-generator/tests/QrCode.Generator.Tests/bin/Release/net9.0/QrCode.Generator.Tests.dll' [net9.0|x64]
failed Generate_WithMarkerStyle_ShouldReturnPng(QrCodeMarkerStyle { Id = 2, MarkerStyle = SharpTopLeft }) (407ms)
System.NullReferenceException: Object reference not set to an instance of an object.
at QrCode.Generator.Core.QrCodeGeneratorTests.AreImagesIdentical(Byte[] generatedImage, String referenceImagePath) in /home/runner/work/qr-code-generator/qr-code-generator/tests/QrCode.Generator.Tests/Core/QrCodeGeneratorTests.cs:115****
Sehra
Sehra2mo ago
and what is on line 115?
Core
CoreOP2mo ago
Reading a file From the same path which was copied on build
Sehra
Sehra2mo ago
paste the test code, reading a file usually doesn't throw NRE
Core
CoreOP2mo ago
c#
private static bool AreImagesIdentical(byte[] generatedImage, string referenceImagePath)
{
using var generatedBitmap = SKBitmap.Decode(generatedImage);
using var referenceBitmap = SKBitmap.Decode(referenceImagePath);
return generatedBitmap.Bytes.SequenceEqual(referenceBitmap.Bytes);
}
c#
private static bool AreImagesIdentical(byte[] generatedImage, string referenceImagePath)
{
using var generatedBitmap = SKBitmap.Decode(generatedImage);
using var referenceBitmap = SKBitmap.Decode(referenceImagePath);
return generatedBitmap.Bytes.SequenceEqual(referenceBitmap.Bytes);
}
SkiaSharp decodes the images, from the file referenceBitmap is null when the last line is reached: generatedBitmap.Bytes.SequenceEqual(referenceBitmap.Bytes);
Sehra
Sehra2mo ago
so something with referenceImagePath, SKBitmap return null on decode error
Core
CoreOP2mo ago
Yup, changed it to only read the file: System.IO.DirectoryNotFoundException: Could not find a part of the path '/home/runner/work/qr-code-generator/qr-code-generator/tests/QrCode.Generator.Tests/bin/Release/net9.0/TestImages/Png/marker_3.png'. dogshit what it is I will close this because I still want my sanity Anyway, Thank you $close
MODiX
MODiX2mo ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?