Skip to content
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

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

Closed

Conversation

m3nax
Copy link
Contributor

@m3nax m3nax commented Sep 22, 2022

After a long journey looking for a way to compile test projects by forcing the use of a specific version of a "ProjectReference" I wrote the following pipeline.

Now it is certain that the compiler takes the netstandard2.1 version of the library.

How test the solution:

  • download this branch
  • clean project
  • run: dotnet build -f netstandard2.1 --configuration Debug -v minimal ./src/KubernetesClient/KubernetesClient.csproj
  • run; dotnet build -f netstandard2.0 --configuration Debug -v minimal ./tests/SkipTestLogger/SkipTestLogger.csproj

Now set the flag UseLibNetStandard2_1 to false or omit it

  • run: dotnet build --configuration Debug -v minimal --no-dependencies -p:UseLibNetStandard2_1=false ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj
  • run: dotnet build --configuration Debug -v minimal --no-dependencies -p:UseLibNetStandard2_1=false ./tests/E2E.Tests/E2E.Tests.csproj

Now set the flag UseLibNetStandard2_1 to true

  • run: dotnet build --configuration Debug -v minimal --no-dependencies -p:UseLibNetStandard2_1=true ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj
  • run: dotnet build --configuration Debug -v minimal --no-dependencies -p:UseLibNetStandard2_1=true ./tests/E2E.Tests/E2E.Tests.csproj

It switch between forced and standard inclusion of ProjectReference inside KubernetesClient.Tests.csproj and E2E.Tests.csproj:

<!-- standard -->
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj"/>

<!-- with forced target framework -->
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" AdditionalProperties="TargetFramework=netstandard2.1"/>

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 22, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: m3nax
Once this PR has been reviewed and has the lgtm label, please assign tg123 for approval by writing /assign @tg123 in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 22, 2022
@m3nax
Copy link
Contributor Author

m3nax commented Sep 22, 2022

Related #988

@tg123
Copy link
Member

tg123 commented Sep 22, 2022

Not sure if the compiler today takes it
here is the thread when i want to solve the issue
dotnet/sdk#1791

could you please link me any official doc about the property?

@m3nax
Copy link
Contributor Author

m3nax commented Sep 22, 2022

Not sure if the compiler today takes it here is the thread when i want to solve the issue dotnet/sdk#1791

could you please link me any official doc about the property?

Conditional inclusion: https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-conditional-constructs?view=vs-2022
AdditionalProperties: https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-task?view=vs-2022#additionalproperties-metadata

@tg123
Copy link
Member

tg123 commented Sep 22, 2022

I mean TargetFramework= in AdditionalProperties

@tg123
Copy link
Member

tg123 commented Sep 22, 2022

looks like the idea is to override the TargetFramework during compile
not sure if it works, but lets test with a netstandard2 only testcase to ensure the code path is covered well

thanks for the idea

@m3nax
Copy link
Contributor Author

m3nax commented Sep 23, 2022

Yes you are right, is the equivalent of dotnet build -p:TargetFramework=netstandard2.1 but only for a specific dependency.
Tomorrow i will write the netstandard2.0 version.

@m3nax m3nax marked this pull request as draft September 23, 2022 08:36
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 23, 2022
@m3nax
Copy link
Contributor Author

m3nax commented Sep 23, 2022

@tg123

For netstandard2.0 the project to test is only KubernetesClient.Classic.Tests correct?

@tg123
Copy link
Member

tg123 commented Sep 23, 2022

@tg123

For netstandard2.0 the project to test is only KubernetesClient.Classic.Tests correct?

netstardard 2.0 is for net48, but asp.net core cant start with net48.
the tests is very basic at the moment.

Ah, I think we do not have to do this tricky workaround.
the test project can target netstandard2.0/netstardard2.1 directly.
If i remember correctly, the reason I am using the netcore is because of aspnetcore

while, the aspnetcore is to mock a http server here until a better http lib for test found.
hope above would help you understand the whole picture better.

lets target netstanard2 directly to see if we start there :)

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 27, 2022
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 3, 2022
@m3nax
Copy link
Contributor Author

m3nax commented Oct 4, 2022

@tg123

I removed the tests for the netstandard2.0 version while keeping the dependency on the netstandard2.0 version of the dependency in the project file.
csproj line > (/~https://github.com/kubernetes-client/csharp/pull/1029/files#diff-e19de45fad07027102b277638b6008d1dd89bc8cc9082513e0c86931e47a8a83R40)
This allows us to test the netstandard2.0 version for the net framework 4.8

I merged the latest version of the master, are there any other changes to make?

<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.

@m3nax m3nax marked this pull request as ready for review October 4, 2022 18:38
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 4, 2022
@k8s-ci-robot k8s-ci-robot requested a review from tg123 October 4, 2022 18:39
@m3nax m3nax marked this pull request as draft October 4, 2022 20:06
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 4, 2022
@m3nax
Copy link
Contributor Author

m3nax commented Oct 4, 2022

With this version:

  • KubernetesClient.Classic.Tests can be deleted, all netstandard2.0 tests are executed in KubernetesClient.Tests like netstandard2.1, net5.0 and net6.0
  • KubernetesClient.Classic can be deleted/deprecated, now KubernetesClient is compiled with netstandard2.0;netstandard2.1;net5.0;net6.0 targets frameworks
  • watch test (WatchTests.cs) aren't executed only for netstandard2.0 because they are unsopported (backport watcher to Classic #901)
  • with netstandard2.0 version of KubernetesClient we support .NET framework version >= 4.6.2 (i think)
  • the version of KubernetesClient included by tests projects is parametrized and can be used for other tests

Steps to test this version (netstandard2.0):

# clean solution

dotnet build -f netstandard2.0 --configuration Debug -v minimal ./src/KubernetesClient/KubernetesClient.csproj 
dotnet build -f netstandard2.0 --configuration Debug -v minimal ./tests/SkipTestLogger/SkipTestLogger.csproj
		  
dotnet build --configuration Debug -v minimal --no-dependencies -p:KubernetesClientVersion="netstandard2.0" ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj 
dotnet build --configuration Debug -v minimal --no-dependencies -p:KubernetesClientVersion="netstandard2.0" ./tests/E2E.Tests/E2E.Tests.csproj
		  
dotnet test ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj /p:CollectCoverage=true /p:ExcludeByFile=\"**/KubernetesClient/generated/**/*.cs\" /p:CoverletOutputFormat="cobertura" /p:KubernetesClientVersion="netstandard2.0" --no-build 
dotnet test ./tests/E2E.Tests/E2E.Tests.csproj /p:CollectCoverage=true /p:ExcludeByFile=\"**/KubernetesClient/generated/**/*.cs\" /p:CoverletOutputFormat="cobertura" /p:KubernetesClientVersion="netstandard2.0" --no-build

Steps to test this version (netstandard2.1):

# clean solution

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
		  
dotnet build --configuration Debug -v minimal --no-dependencies -p:KubernetesClientVersion="netstandard2.1" ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj 
dotnet build --configuration Debug -v minimal --no-dependencies -p:KubernetesClientVersion="netstandard2.1" ./tests/E2E.Tests/E2E.Tests.csproj
		  
dotnet test ./tests/KubernetesClient.Tests/KubernetesClient.Tests.csproj /p:CollectCoverage=true /p:ExcludeByFile=\"**/KubernetesClient/generated/**/*.cs\" /p:CoverletOutputFormat="cobertura" /p:KubernetesClientVersion="netstandard2.1" --no-build 
dotnet test ./tests/E2E.Tests/E2E.Tests.csproj /p:CollectCoverage=true /p:ExcludeByFile=\"**/KubernetesClient/generated/**/*.cs\" /p:CoverletOutputFormat="cobertura" /p:KubernetesClientVersion="netstandard2.1" --no-build

@m3nax m3nax marked this pull request as ready for review October 4, 2022 21:54
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 4, 2022
@m3nax m3nax changed the title Netstandard2.1 compilation action without net 3.1 Tests netstandard2.0/2.1 version of KubernetesClient without .NET Core 3.1 Oct 5, 2022
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 7, 2022
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 10, 2022
@m3nax m3nax changed the title Tests netstandard2.0/2.1 version of KubernetesClient without .NET Core 3.1 Tests with netstandard2.0/2.1 version of KubernetesClient without .NET Core 3.1 Oct 10, 2022
@m3nax
Copy link
Contributor Author

m3nax commented Oct 10, 2022

/assign @tg123

If you don't like the proposed solution, close the PR.

@k8s-ci-robot
Copy link
Contributor

@m3nax: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 12, 2022
@tg123 tg123 mentioned this pull request Dec 11, 2022
@m3nax m3nax closed this Dec 12, 2022
@m3nax
Copy link
Contributor Author

m3nax commented Dec 12, 2022

Closed because implemented in #1122 with netstandard2.1 removal

@m3nax m3nax deleted the netstandard2.1-compilation branch May 3, 2023 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants