![]() |
VOOZH | about |
dotnet add package KubeOps.Testing --version 7.6.1
NuGet\Install-Package KubeOps.Testing -Version 7.6.1
<PackageReference Include="KubeOps.Testing" Version="7.6.1" />
<PackageVersion Include="KubeOps.Testing" Version="7.6.1" />Directory.Packages.props
<PackageReference Include="KubeOps.Testing" />Project file
paket add KubeOps.Testing --version 7.6.1
#r "nuget: KubeOps.Testing, 7.6.1"
#:package KubeOps.Testing@7.6.1
#addin nuget:?package=KubeOps.Testing&version=7.6.1Install as a Cake Addin
#tool nuget:?package=KubeOps.Testing&version=7.6.1Install as a Cake Tool
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:
TestStartup.cs file (or any other name you want)KubernetesOperatorFactoryThis 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.
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:
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.
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.
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. |
This package is not used by any NuGet packages.
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 |
'## [7.6.1](https://github.com/buehler/dotnet-operator-sdk/compare/v7.6.0...v7.6.1) (2023-09-29)
### Bug Fixes
* Merge Watch & Local events. Switch by uid & type grouping. ([#616](https://github.com/buehler/dotnet-operator-sdk/issues/616)) ([d6031c6](https://github.com/buehler/dotnet-operator-sdk/commit/d6031c64d1dba02822da90804f19dd51f40ebc98)), closes [#585](https://github.com/buehler/dotnet-operator-sdk/issues/585) [#579](https://github.com/buehler/dotnet-operator-sdk/issues/579)
'