Skip to content

Commit

Permalink
test: add IntegrationTest project (#100)
Browse files Browse the repository at this point in the history
* test: add husky integration test project

* chore: Remove unused "Issue99" folder from HuskyIntegrationTests

The "Issue99" folder is not being used anymore in the HuskyIntegrationTests project. This commit removes the redundant folder reference from the project file to keep the project structure clean and accurate.

* fix: add integration Test base project template

* test: Add new method in DockerFixture and modify tests

A new method `StartWithInstalledHusky` has been added to `DockerFixture`, this method provides an easier way to get a container with Husky installed. Some code rearrangement and wording modifications were made in the `Extensions` and `Tests` classes to make test cases clearer and more understandable. The newly created TestProjectBase solution was also added.

* test: Update BashAsync method and enhance Docker setup

The BashAsync method in Extensions.cs now handles exceptions for non-zero exit codes, enhancing error handling. A new method, AddCsharpClass, has also been added to help create C# classes. In DockerFixture.cs, global user details are now set up to aid Git operations.
  • Loading branch information
alirezanet authored Dec 17, 2023
1 parent 9c334c8 commit ca61a32
Show file tree
Hide file tree
Showing 16 changed files with 854 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Exclude everything
*

# Include the src folder
!src
!README.md

# Exclude build-related folders within src/Husky
src/Husky/bin/
src/Husky/obj/
src/Husky/nupkg/
Empty file added .gitmodules
Empty file.
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This dockerfile is used in the integration tests

# Use the official .NET SDK image as a base
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
ARG RESOURCE_REAPER_SESSION_ID="00000000-0000-0000-0000-000000000000"
LABEL "org.testcontainers.resource-reaper-session"=$RESOURCE_REAPER_SESSION_ID

# Set the working directory
WORKDIR /app

# Copy the .csproj file to the container
COPY src/Husky/Husky.csproj ./

ENV HUSKY=0

# Copy the remaining files to the container
COPY . ./

# Restore dependencies
RUN dotnet restore /app/src/Husky

# Build the application
RUN dotnet build --no-restore -c Release -f net8.0 /app/src/Husky

# Create a NuGet package
RUN dotnet pack --no-build --no-restore -c Release -o out /app/src/Husky/Husky.csproj -p:TargetFrameworks=net8.0

# Use the same .NET SDK image for the final stage
FROM mcr.microsoft.com/dotnet/sdk:8.0
ARG RESOURCE_REAPER_SESSION_ID="00000000-0000-0000-0000-000000000000"
LABEL "org.testcontainers.resource-reaper-session"=$RESOURCE_REAPER_SESSION_ID

# Set the working directory
WORKDIR /app

# Install Git
RUN apt-get update && \
apt-get install -y git

# Copy the NuGet package from the build-env to the runtime image
COPY --from=build-env /app/out/*.nupkg /app/nupkg/

# Install Husky tool and add the global tools path to the PATH
RUN dotnet tool install -g --no-cache --add-source /app/nupkg/ husky \
&& echo "export PATH=\$PATH:/root/.dotnet/tools" >> ~/.bashrc

# Set the entry point to a simple shell
ENTRYPOINT ["/bin/bash"]
9 changes: 8 additions & 1 deletion Husky.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
#
#
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Husky", "src\Husky\Husky.csproj", "{12AB4B33-47A6-49D5-872A-5BA6DD634E9C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{302A5F25-CB44-4ED0-A65E-06C04648D211}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HuskyTest", "tests\HuskyTest\HuskyTest.csproj", "{57EE798B-0FE0-42A4-BDB9-D168109D3E7D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HuskyIntegrationTests", "tests\HuskyIntegrationTests\HuskyIntegrationTests.csproj", "{FAF049CD-6E45-4A66-A88F-C2EB007DFCC3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,8 +23,13 @@ Global
{57EE798B-0FE0-42A4-BDB9-D168109D3E7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57EE798B-0FE0-42A4-BDB9-D168109D3E7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57EE798B-0FE0-42A4-BDB9-D168109D3E7D}.Release|Any CPU.Build.0 = Release|Any CPU
{FAF049CD-6E45-4A66-A88F-C2EB007DFCC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAF049CD-6E45-4A66-A88F-C2EB007DFCC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAF049CD-6E45-4A66-A88F-C2EB007DFCC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAF049CD-6E45-4A66-A88F-C2EB007DFCC3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{57EE798B-0FE0-42A4-BDB9-D168109D3E7D} = {302A5F25-CB44-4ED0-A65E-06C04648D211}
{FAF049CD-6E45-4A66-A88F-C2EB007DFCC3} = {302A5F25-CB44-4ED0-A65E-06C04648D211}
EndGlobalSection
EndGlobal
31 changes: 31 additions & 0 deletions tests/HuskyIntegrationTests/HuskyIntegrationTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="Testcontainers" Version="3.6.0" />
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Folder Include="TestProjectBase\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"husky": {
"version": "0.6.3",
"commands": [
"husky"
]
}
}
}
Loading

0 comments on commit ca61a32

Please sign in to comment.