|
| 1 | +using System.Diagnostics; |
| 2 | + |
| 3 | +namespace Base58Encoding.Tests; |
| 4 | + |
| 5 | +public class BigEndianTests |
| 6 | +{ |
| 7 | + private readonly ITestOutputHelper _output; |
| 8 | + |
| 9 | + public BigEndianTests(ITestOutputHelper output) |
| 10 | + { |
| 11 | + _output = output; |
| 12 | + } |
| 13 | + |
| 14 | + /// <summary> |
| 15 | + /// Alternatively can be run manually to verify compatibility on big-endian systems using below command |
| 16 | + /// docker run -it --rm --platform linux/s390x -v ProjectPath/src:/src registry.access.redhat.com/dotnet/sdk:10.0 sh -c "cd /src/Base58Encoding.Tests && dotnet run" |
| 17 | + /// </summary> |
| 18 | + [Fact(Skip = "For local usage only")] |
| 19 | + public void Base58Encoding_Works_On_BigEndian_ViaProcess() |
| 20 | + { |
| 21 | + if (!BitConverter.IsLittleEndian) |
| 22 | + { |
| 23 | + _output.WriteLine("Skipping big-endian verification as already running on big-endian environment."); |
| 24 | + return; |
| 25 | + } |
| 26 | + |
| 27 | + var path = FindSrcPath(); |
| 28 | + |
| 29 | + var process = new Process |
| 30 | + { |
| 31 | + StartInfo = new ProcessStartInfo |
| 32 | + { |
| 33 | + FileName = "docker", |
| 34 | + Arguments = $"run --rm --platform linux/s390x -v {path}:/src registry.access.redhat.com/dotnet/sdk:10.0 sh -c \"cd /src/Base58Encoding.Tests && dotnet run --no-restore --no-build\"", |
| 35 | + RedirectStandardOutput = true, |
| 36 | + RedirectStandardError = true, |
| 37 | + UseShellExecute = false |
| 38 | + } |
| 39 | + }; |
| 40 | + |
| 41 | + process.Start(); |
| 42 | + string output = process.StandardOutput.ReadToEnd(); |
| 43 | + process.WaitForExit(); |
| 44 | + |
| 45 | + Assert.Equal(0, process.ExitCode); |
| 46 | + Assert.Contains("Passed!", output); |
| 47 | + |
| 48 | + _output.Write(output); |
| 49 | + } |
| 50 | + |
| 51 | + private static string FindSrcPath() |
| 52 | + { |
| 53 | + var dir = new DirectoryInfo(Directory.GetCurrentDirectory()); |
| 54 | + while (dir != null && dir.Name != "src" && !dir.GetFiles("*.slnx").Any()) |
| 55 | + { |
| 56 | + dir = dir.Parent; |
| 57 | + } |
| 58 | + |
| 59 | + if (dir == null) throw new Exception("Src path not found."); |
| 60 | + return Path.GetFullPath(dir.FullName); |
| 61 | + } |
| 62 | +} |
0 commit comments