Skip to content

Tests with netstandard2.0/2.1 version of KubernetesClient without .NET Core 3.1 #1029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/buildtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,35 @@ jobs:
run: dotnet build --configuration Release -v detailed
- name: Test
run: dotnet test /p:CollectCoverage=true /p:ExcludeByFile=\"**/KubernetesClient/generated/**/*.cs\" /p:CoverletOutputFormat="cobertura"

# Build and test netstandard 2.1 version of library with net core 5.0 and 6.0
netstandard2_1:
runs-on: ubuntu-latest
name: Dotnet build netstandard2.1
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup dotnet
uses: actions/setup-dotnet@v2
with:
dotnet-version: |
5.0.x
6.0.x
- name: Build libraries
run: |
dotnet build -f netstandard2.1 --configuration Debug -v minimal ./src/KubernetesClient/KubernetesClient.csproj
dotnet build -f netstandard2.0 --configuration Debug -v minimal ./tests/SkipTestLogger/SkipTestLogger.csproj
- name: Build test projects
run: |
dotnet build --configuration Debug -v minimal --no-dependencies -p:UseLibNetStandard2_1=true ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj
dotnet build --configuration Debug -v minimal --no-dependencies -p:UseLibNetStandard2_1=true ./tests/E2E.Tests/E2E.Tests.csproj
- name: Test
run: |
dotnet test /p:CollectCoverage=true /p:ExcludeByFile=\"**/KubernetesClient/generated/**/*.cs\" /p:CoverletOutputFormat="cobertura" \
--no-build ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj
dotnet test /p:CollectCoverage=true /p:ExcludeByFile=\"**/KubernetesClient/generated/**/*.cs\" /p:CoverletOutputFormat="cobertura" \
--no-build ./tests/E2E.Tests/E2E.Tests.csproj

# Test code gen for visual studio compatibility >> https://github.com/kubernetes-client/csharp/pull/1008
codgen:
Expand Down
87 changes: 60 additions & 27 deletions tests/E2E.Tests/E2E.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,33 +1,66 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<SignAssembly>true</SignAssembly>
<RootNamespace>k8s.E2E</RootNamespace>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<SignAssembly>true</SignAssembly>
<RootNamespace>k8s.E2E</RootNamespace>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ItemGroup>

<PackageReference Include="JsonPatch.Net" Version="2.0.4" />
<PackageReference Include="SharpZipLib" Version="1.4.0" />
<PackageReference Include="JsonPatch.Net" Version="2.0.4" />
<PackageReference Include="SharpZipLib" Version="1.4.0" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />

<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.1.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" />
<ProjectReference Include="..\SkipTestLogger\SkipTestLogger.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.2" />
</ItemGroup>
<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.1.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SkipTestLogger\SkipTestLogger.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.2" />
</ItemGroup>

<!--
set -p:UseLibNetStandard2_0=true to force the inclusion of netstandard2.0 version of libraries, Default: false
set -p:UseLibNetStandard2_1=true to force the inclusion of netstandard2.1 version of libraries, Default: false
-->
<PropertyGroup>
<UseLibNetStandard2_0>false</UseLibNetStandard2_0>
<UseLibNetStandard2_1>false</UseLibNetStandard2_1>
</PropertyGroup>

<Target Name="DisplayMessages" BeforeTargets="Build" >
<message Importance="High" Text="[Flag] UseLibNetStandard2_0 = $(UseLibNetStandard2_0)"/>
<message Importance="High" Text="[Flag] UseLibNetStandard2_1 = $(UseLibNetStandard2_1)"/>
</Target>

<Choose>
<When Condition="('$(UseLibNetStandard2_0)' != 'true') And ('$(UseLibNetStandard2_1)' != 'true')">
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj"/>
</ItemGroup>
</When>

<When Condition="'$(UseLibNetStandard2_0)' == 'true'">
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" AdditionalProperties="TargetFramework=netstandard2.0"/>
</ItemGroup>
</When>

<When Condition="'$(UseLibNetStandard2_1)' == 'true'">
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" AdditionalProperties="TargetFramework=netstandard2.1"/>
</ItemGroup>
</When>
</Choose>
</Project>
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<RootNamespace>k8s.Tests</RootNamespace>
<TargetFramework Condition="'$(OS)' != 'Windows_NT'">net6</TargetFramework>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net6;net48</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<IsPackable>false</IsPackable>
<RootNamespace>k8s.Tests</RootNamespace>
<TargetFramework Condition="'$(OS)' != 'Windows_NT'">net6</TargetFramework>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net6;net48</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="AutoMapper" Version="10.1.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="AutoMapper" Version="10.1.1" />
</ItemGroup>

<ItemGroup>
<ItemGroup>

<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
Expand All @@ -33,10 +33,11 @@
<PackageReference Include="Xunit.StaFact" Version="1.1.11" />
<PackageReference Include="Moq" Version="4.18.2" />

<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient.Classic\KubernetesClient.Classic.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient.Classic\KubernetesClient.Classic.csproj" AdditionalProperties="TargetFramework=netstandard2.0"/>
</ItemGroup>

</Project>
90 changes: 54 additions & 36 deletions tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<IsPackable>false</IsPackable>
<RootNamespace>k8s.Tests</RootNamespace>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
</ItemGroup>

<ItemGroup>

<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PropertyGroup>
<IsPackable>false</IsPackable>
<RootNamespace>k8s.Tests</RootNamespace>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0;net6.0</TargetFrameworks>

what about this?
any idea to fix asp.net?

Copy link
Contributor Author

@m3nax m3nax Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't target netstandard2.0/2.1 directly inside test project because , as stated in the docs

.NET Standard is a formal specification of .NET APIs that are available on multiple .NET implementations.

and depends by the framework implementation of the apis docs.

xunit can't directly test netstandard because like other programs, require the netstandard api implementation to run xunit docs
The additional property is the only trick i know to test netstandard implementation with xunit.

I tested on my machine the suggestion and, as i wrote, i can't build test project.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup that is where i stopped.
prefer it than changing target during build.
it is not testing what is really shipped to nuget.

</PropertyGroup>

<ItemGroup>
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
</ItemGroup>

<ItemGroup>

<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
Expand All @@ -31,21 +31,39 @@
<PackageReference Include="Xunit.StaFact" Version="1.1.11" />
<PackageReference Include="Moq" Version="4.18.2" />

<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<None Include="assets/*" CopyToOutputDirectory="Always" />
</ItemGroup>

<ItemGroup>
<None Include="assets/*" CopyToOutputDirectory="Always" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Util\**" />
<Content Remove="Util\**" />
<EmbeddedResource Remove="Util\**" />
<None Remove="Util\**" />
</ItemGroup>

<ItemGroup>
<Compile Remove="Util\**" />
<Content Remove="Util\**" />
<EmbeddedResource Remove="Util\**" />
<None Remove="Util\**" />
</ItemGroup>
<!-- set -p:UseLibNetStandard2_1=true to force the inclusion of netstandard2.1 version of libraries, Default: false -->
<PropertyGroup>
<UseLibNetStandard2_1>false</UseLibNetStandard2_1>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" />
</ItemGroup>
<Target Name="DisplayMessages" BeforeTargets="Build" >
<message Importance="High" Text="[Flag] UseLibNetStandard2_1 = $(UseLibNetStandard2_1)"/>
</Target>

<Choose>
<When Condition="'$(UseLibNetStandard2_1)' != 'true'">
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj"/>
</ItemGroup>
</When>
<When Condition="'$(UseLibNetStandard2_1)' == 'true'">
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" AdditionalProperties="TargetFramework=netstandard2.1"/>
</ItemGroup>
</When>
</Choose>
</Project>