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 all 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
37 changes: 37 additions & 0 deletions .github/workflows/buildtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,43 @@ 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 netstandard2.0/2.1 version of library with .NET Core 6.0
netstandard:
runs-on: ubuntu-latest
name: Dotnet build
strategy:
matrix:
netstandard-version: [netstandard2.0, 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
# Build KubernetesClient with specific netstandard version
- name: Build libraries
run: |
dotnet build -f ${{ matrix.netstandard-version }} --configuration Debug -v minimal ./src/KubernetesClient/KubernetesClient.csproj
dotnet build -f netstandard2.0 --configuration Debug -v minimal ./tests/SkipTestLogger/SkipTestLogger.csproj
# Build KubernetesClient.Tests and E2E.Tests
- name: Build test projects with ${{ matrix.netstandard-version }} version of KubernetesClient
run: |
dotnet build --configuration Debug -v minimal --no-dependencies -p:KubernetesClientVersion="${{ matrix.netstandard-version }}" ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj
dotnet build --configuration Debug -v minimal --no-dependencies -p:KubernetesClientVersion="${{ matrix.netstandard-version }}" ./tests/E2E.Tests/E2E.Tests.csproj
# Run compiled KubernetesClient.Tests and E2E.Tests
- name: Run test projects with ${{ matrix.netstandard-version }} version of KubernetesClient
run: |
# Run KubernetesClient.Tests.csproj
dotnet test ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj \
/p:CollectCoverage=true /p:ExcludeByFile=\"**/KubernetesClient/generated/**/*.cs\" /p:CoverletOutputFormat="cobertura" --no-build /p:KubernetesClientVersion="${{ matrix.netstandard-version }}"
# Run E2E.Tests.csproj
dotnet test ./tests/E2E.Tests/E2E.Tests.csproj \
/p:CollectCoverage=true /p:ExcludeByFile=\"**/KubernetesClient/generated/**/*.cs\" /p:CoverletOutputFormat="cobertura" --no-build /p:KubernetesClientVersion="${{ matrix.netstandard-version }}"

# Test code gen for visual studio compatibility >> https://github.com/kubernetes-client/csharp/pull/1008
codgen:
Expand Down
42 changes: 21 additions & 21 deletions src/KubernetesClient/KubernetesClient.csproj
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0;net6.0</TargetFrameworks>
<RootNamespace>k8s</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0;net6.0</TargetFrameworks>
<RootNamespace>k8s</RootNamespace>
</PropertyGroup>

<ItemGroup>
<!--TODO merge util folder -->
<Compile Remove="Util\**" />
<EmbeddedResource Remove="Util\**" />
<None Remove="Util\**" />
</ItemGroup>
<ItemGroup>
<!--TODO merge util folder -->
<Compile Remove="Util\**" />
<EmbeddedResource Remove="Util\**" />
<None Remove="Util\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="prometheus-net" Version="6.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.23.1" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="IdentityModel.OidcClient" Version="5.0.2" />
<ItemGroup>
<PackageReference Include="prometheus-net" Version="6.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.23.1" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="IdentityModel.OidcClient" Version="5.0.2" />

<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" Condition="'$(TargetFramework)' == 'netstandard2.1'" />
</ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" Condition="('$(TargetFramework)' == 'netstandard2.0') or ('$(TargetFramework)' == 'netstandard2.1')" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\KubernetesClient.Models\KubernetesClient.Models.csproj" />
<ProjectReference Include="..\KubernetesClient.Basic\KubernetesClient.Basic.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KubernetesClient.Models\KubernetesClient.Models.csproj" />
<ProjectReference Include="..\KubernetesClient.Basic\KubernetesClient.Basic.csproj" />
</ItemGroup>

</Project>
94 changes: 68 additions & 26 deletions tests/E2E.Tests/E2E.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,33 +1,75 @@
<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>
<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:KubernetesClientVersion=targetmoniker to force the inclusion of specific version of libraries-->
<!-- example: dotnet build -p:KubernetesClientVersion="netstandard2.0" ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj -->
<PropertyGroup>
<KubernetesClientVersion></KubernetesClientVersion>
</PropertyGroup>

<!-- Display version used in compilation output when is forced-->
<Target Name="DisplayMessages" BeforeTargets="Build" Condition="'$(KubernetesClientVersion)' != ''">
<message Importance="High" Text="[Flag] KubernetesClient used version = '$(KubernetesClientVersion)'" />
</Target>

<Choose>

<!-- include standard version of KubernetesClient project (auto selected by compiler) -->
<When Condition="'$(KubernetesClientVersion)' == ''">
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" />
</ItemGroup>
</When>

<!-- include nestandard2.0 version of KubernetesClient project and define KUBERNETESCLIENT_NETSTANDARD2_0 constant for #if preprocessor directives (used for tests exclusion) -->
<When Condition="'$(KubernetesClientVersion)' == 'netstandard2.0'">
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" AdditionalProperties="TargetFramework=$(KubernetesClientVersion)" />
</ItemGroup>
<PropertyGroup>
<DefineConstants>KUBERNETESCLIENT_NETSTANDARD2_0</DefineConstants>
</PropertyGroup>
</When>


<!-- include nestandard2.1 version of KubernetesClient project and define KUBERNETESCLIENT_NETSTANDARD2_1 constant for #if preprocessor directives (used for tests exclusion) -->
<When Condition="'$(KubernetesClientVersion)' == 'netstandard2.1'">
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" AdditionalProperties="TargetFramework=$(KubernetesClientVersion)" />
</ItemGroup>
<PropertyGroup>
<DefineConstants>KUBERNETESCLIENT_NETSTANDARD2_1</DefineConstants>
</PropertyGroup>
</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.0</TargetFramework>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net6.0;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>
111 changes: 75 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,60 @@
<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>
<Compile Remove="Util\**" />
<Content Remove="Util\**" />
<EmbeddedResource Remove="Util\**" />
<None Remove="Util\**" />
</ItemGroup>

<!-- set -p:KubernetesClientVersion=targetmoniker to force the inclusion of specific version of libraries-->
<!-- example: dotnet build -p:KubernetesClientVersion="netstandard2.0" ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj -->
<PropertyGroup>
<KubernetesClientVersion></KubernetesClientVersion>
</PropertyGroup>

<!-- Display version used in compilation output when is forced-->
<Target Name="DisplayMessages" BeforeTargets="Build" Condition="'$(KubernetesClientVersion)' != ''">
<message Importance="High" Text="[Flag] KubernetesClient used version = '$(KubernetesClientVersion)'" />
</Target>

<Choose>

<!-- include standard version of KubernetesClient project (auto selected by compiler) -->
<When Condition="'$(KubernetesClientVersion)' == ''">
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" />
</ItemGroup>
</When>

<ItemGroup>
<None Include="assets/*" CopyToOutputDirectory="Always" />
</ItemGroup>
<!-- include nestandard2.0 version of KubernetesClient project and define KUBERNETESCLIENT_STANDARD2_0 constant for #if preprocessor directives (used for tests exclusion) -->
<When Condition="'$(KubernetesClientVersion)' == 'netstandard2.0'">
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" AdditionalProperties="TargetFramework=$(KubernetesClientVersion)" />
</ItemGroup>
<PropertyGroup>
<DefineConstants>KUBERNETESCLIENT_NETSTANDARD2_0</DefineConstants>
</PropertyGroup>
</When>

<ItemGroup>
<Compile Remove="Util\**" />
<Content Remove="Util\**" />
<EmbeddedResource Remove="Util\**" />
<None Remove="Util\**" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" />
</ItemGroup>
<!-- include nestandard2.1 version of KubernetesClient project and define KUBERNETESCLIENT_STANDARD2_1 constant for #if preprocessor directives (used for tests exclusion) -->
<When Condition="'$(KubernetesClientVersion)' == 'netstandard2.1'">
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" AdditionalProperties="TargetFramework=$(KubernetesClientVersion)" />
</ItemGroup>
<PropertyGroup>
<DefineConstants>KUBERNETESCLIENT_NETSTANDARD2_1</DefineConstants>
</PropertyGroup>
</When>

</Choose>
</Project>
Loading