Skip to content

Commit

Permalink
Better Tests (#6)
Browse files Browse the repository at this point in the history
* Improve CI-Pipeline. Add more unit tests. Remove integration tests.

* Fixed ci

* Fix thread issues

* Fix ci pipeline

* Fix pipeline

* Fix pipeline

* Fix filename

* Remove warnings

* Update coverage to allow gradual improvement.

* Remove warnings

* Fix encoding
  • Loading branch information
Gitii authored Mar 3, 2022
1 parent 00541a2 commit d95a0df
Show file tree
Hide file tree
Showing 30 changed files with 1,021 additions and 604 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/auto-approve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Auto approve

on:
pull_request_target

jobs:
auto-approve:
runs-on: ubuntu-latest
steps:
- uses: hmarr/auto-approve-action@v2
if: github.actor == 'Gitii'
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
39 changes: 38 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main

jobs:
build:
test:
runs-on: windows-latest
steps:
- name: Checkout
Expand All @@ -30,3 +30,40 @@ jobs:
run: dotnet build --configuration Release
- name: Test
run: dotnet test --configuration Release --no-build --filter TestCategory!=Integration
- name: Generate coverage
run: ./generate-coverage.cmd
- name: Upload code coverage results
uses: actions/upload-artifact@v2
with:
name: code-coverage-report
path: CoverageResults

verify:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download code coverage resilts
uses: actions/download-artifact@v2
with:
name: code-coverage-report
path: CoverageResults
- name: Code Coverage Summary Report
uses: irongut/[email protected]
with:
filename: CoverageResults/coverage.cobertura.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '53 44'
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ _TeamCity*
coverage*.json
coverage*.xml
coverage*.info
CoverageReport

# Visual Studio code coverage results
*.coverage
Expand Down
45 changes: 45 additions & 0 deletions Community.Wsl.Sdk.Tests/BlockingReadOnlyStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading;

namespace Community.Wsl.Sdk.Tests;

[ExcludeFromCodeCoverage]
public class BlockingReadOnlyStream : Stream
{
public override void Flush() { }

public override int Read(byte[] buffer, int offset, int count)
{
Thread.Sleep(5000);
return 0;
}

public override long Seek(long offset, SeekOrigin origin)
{
throw new Exception();
}

public override void SetLength(long value)
{
throw new NotSupportedException();
}

public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}

public override bool CanRead { get; } = true;
public override bool CanSeek { get; } = false;
public override bool CanWrite { get; } = false;

public override long Length => throw new Exception();

public override long Position
{
get { throw new Exception(); }
set { throw new Exception(); }
}
}
35 changes: 35 additions & 0 deletions Community.Wsl.Sdk.Tests/CommandExecutionOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using NUnit.Framework;

namespace Community.Wsl.Sdk.Tests;

public class CommandExecutionOptionsTests
{
[Test]
public void Constructor_ShouldEqualKnownValuesTests()
{
var ceo = new CommandExecutionOptions()
{
FailOnNegativeExitCode = true,
StdErrDataProcessingMode = DataProcessingMode.External,
StdInDataProcessingMode = DataProcessingMode.Binary,
StdoutDataProcessingMode = DataProcessingMode.String,
StderrEncoding = Encoding.ASCII,
StdinEncoding = Encoding.Default,
StdoutEncoding = Encoding.Latin1
};

ceo.FailOnNegativeExitCode.Should().BeTrue();
ceo.StdErrDataProcessingMode.Should().Be(DataProcessingMode.External);
ceo.StdInDataProcessingMode.Should().Be(DataProcessingMode.Binary);
ceo.StdoutDataProcessingMode.Should().Be(DataProcessingMode.String);
ceo.StderrEncoding.Should().BeSameAs(Encoding.ASCII);
ceo.StdinEncoding.Should().BeSameAs(Encoding.Default);
ceo.StdoutEncoding.Should().BeSameAs(Encoding.Latin1);
}
}
31 changes: 31 additions & 0 deletions Community.Wsl.Sdk.Tests/CommandResultTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using NUnit.Framework;

namespace Community.Wsl.Sdk.Tests;

public class CommandResultTests
{
[Test]
public void Constructor_ShouldEqualKnownValuesTests()
{
var cr = new CommandResult()
{
ExitCode = 0,
Stderr = "a",
StderrData = new byte[] { 1 },
Stdout = "b",
StdoutData = new byte[] { 2 }
};

cr.ExitCode.Should().Be(0);
cr.Stderr.Should().Be("a");
cr.StderrData.Should().Equal(1);
cr.Stdout.Should().Be("b");
cr.StdoutData.Should().Equal(2);
}
}
Loading

0 comments on commit d95a0df

Please sign in to comment.