VOOZH about

URL: https://www.nuget.org/packages/KubeOps.Testing/

⇱ NuGet Gallery | KubeOps.Testing 7.6.1




👁 Image
KubeOps.Testing 7.6.1

dotnet add package KubeOps.Testing --version 7.6.1
 
 
NuGet\Install-Package KubeOps.Testing -Version 7.6.1
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KubeOps.Testing" Version="7.6.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KubeOps.Testing" Version="7.6.1" />
 
Directory.Packages.props
<PackageReference Include="KubeOps.Testing" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KubeOps.Testing --version 7.6.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: KubeOps.Testing, 7.6.1"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KubeOps.Testing@7.6.1
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KubeOps.Testing&version=7.6.1
 
Install as a Cake Addin
#tool nuget:?package=KubeOps.Testing&version=7.6.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

KubeOps Testing Utilities

The KubeOps.Testing package provides tools to test the custom operator.

To have an example for integration testing a custom operator have a look at the test code in the repository: Integration Tests

The tools provided aid with Integration testing. For normal unit testing, you can just mock all the things.

The main entry point for testing your custom operator is the KubernetesOperatorFactory class. It is meant to be injected into your test.

The following documentation assumes you are using xUnit as a testing framework. The techniques used should be present with other testing frameworks as well.

The following steps are needed for integration testing the controller:

  • Create a TestStartup.cs file (or any other name you want)
  • Inject the KubernetesOperatorFactory
  • Use the mocked client and helper functions to test your operator

Test Startup

This file is very similar to a "normal" Startup.cs file of an asp.net application. Either you subclass it and replace your test mocked services, or you create a new one.

Mocked elements

The main part of this operator factory does mock the used Kubernetes client and helper functions to enqueue events and finalizer events.

Both mocked elements can be retrieved via the operator factory with:

  • "MockedKubernetesClient"
  • "KubernetesOperatorFactory.EnqueueEvent"
  • "KubernetesOperatorFactory.EnqueueFinalization"

Mocked events

With the mentioned factory functions one can fire events for entities. This can be used to test your controllers.

The controllers are normally instantiated via the scope of the DI system.

Mocked IKubernetesClient

The client is essentially an empty implementation of the interface. All methods do return null or the object that was passed into the mocked class. There are five different object references that can be set to return certain results upon calling the client.

The mocked client is injected as singleton, this means the used "result" references can vary. Be aware of that and don't run your tests in parallel if you rely on those results.

Writing a test

Now with all parts in place, we can write a test. You probably need to set the solution relative content root for asp.net testing. But then you can run the factory and create a test.

// Constructor
public TestControllerTest(KubernetesOperatorFactory<TestStartup> factory)
{
 _factory = factory.WithSolutionRelativeContentRoot("tests/KubeOps.TestOperator");

 _controller = _factory.Services
 .GetRequiredService<IControllerInstanceBuilder>()
 .BuildControllers<V1TestEntity>()
 .First();

 _managerMock = _factory.Services.GetRequiredService<Mock<IManager>>();
 _managerMock.Reset();
}

// snip

[Fact]
public async Task Test_If_Manager_Created_Is_Called()
{
 _factory.Run();

 _managerMock.Setup(o => o.Reconciled(It.IsAny<V1TestEntity>()));
 _managerMock.Verify(o => o.Reconciled(It.IsAny<V1TestEntity>()), Times.Never);

 await _controller.StartAsync();
 await _factory.EnqueueEvent(ResourceEventType.Reconcile, new V1TestEntity());
 await _controller.StopAsync();

 _managerMock.Verify(o => o.Reconciled(It.IsAny<V1TestEntity>()), Times.Once);
}
Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 is compatible.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
7.6.1 4,377 9/29/2023
7.6.0 691 9/19/2023
7.5.0 419 9/13/2023
7.4.5 239 9/13/2023
7.4.4 327 8/28/2023
7.4.3 278 8/28/2023
7.4.2 1,831 7/17/2023
7.4.1 308 7/17/2023
7.4.0 390 6/26/2023
7.3.0 839 6/1/2023
7.2.0 458 4/14/2023
7.1.2 381 4/14/2023
7.1.1 578 3/1/2023
7.1.0 421 3/1/2023
7.0.10 430 2/27/2023
7.0.9 394 2/23/2023
7.0.8 407 2/23/2023
7.0.7 467 2/14/2023
7.0.6 441 2/6/2023
7.0.5 444 2/3/2023
Loading failed