KubeOps.Testing
7.4.1
See the version list below for details.
dotnet add package KubeOps.Testing --version 7.4.1
NuGet\Install-Package KubeOps.Testing -Version 7.4.1
<PackageReference Include="KubeOps.Testing" Version="7.4.1" />
paket add KubeOps.Testing --version 7.4.1
#r "nuget: KubeOps.Testing, 7.4.1"
// Install KubeOps.Testing as a Cake Addin #addin nuget:?package=KubeOps.Testing&version=7.4.1 // Install KubeOps.Testing as a Cake Tool #tool nuget:?package=KubeOps.Testing&version=7.4.1
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 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- KubeOps (>= 7.4.1)
- Microsoft.AspNetCore.Mvc.Testing (>= 6.0.14)
-
net7.0
- KubeOps (>= 7.4.1)
- Microsoft.AspNetCore.Mvc.Testing (>= 7.0.3)
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 | 3,789 | 9/29/2023 |
7.6.0 | 508 | 9/19/2023 |
7.5.0 | 252 | 9/13/2023 |
7.4.5 | 101 | 9/13/2023 |
7.4.4 | 163 | 8/28/2023 |
7.4.3 | 118 | 8/28/2023 |
7.4.2 | 1,671 | 7/17/2023 |
7.4.1 | 126 | 7/17/2023 |
7.4.0 | 228 | 6/26/2023 |
7.3.0 | 639 | 6/1/2023 |
7.2.0 | 270 | 4/14/2023 |
7.1.2 | 195 | 4/14/2023 |
7.1.1 | 395 | 3/1/2023 |
7.1.0 | 228 | 3/1/2023 |
7.0.10 | 235 | 2/27/2023 |
7.0.9 | 213 | 2/23/2023 |
7.0.8 | 224 | 2/23/2023 |
7.0.7 | 277 | 2/14/2023 |
7.0.6 | 260 | 2/6/2023 |
7.0.5 | 258 | 2/3/2023 |
7.0.4 | 278 | 1/30/2023 |
7.0.3 | 262 | 1/30/2023 |
7.0.2 | 284 | 1/26/2023 |
7.0.1 | 272 | 1/23/2023 |
7.0.0 | 274 | 1/19/2023 |
7.0.0-prerelease.2 | 158 | 6/4/2022 |
7.0.0-prerelease.1 | 130 | 6/2/2022 |
6.6.2 | 832 | 1/17/2023 |
6.6.1 | 1,195 | 10/27/2022 |
6.6.0 | 481 | 8/10/2022 |
6.5.4 | 501 | 7/23/2022 |
6.5.3 | 523 | 6/4/2022 |
6.5.2 | 510 | 6/4/2022 |
6.5.1 | 530 | 6/2/2022 |
6.5.0 | 505 | 5/25/2022 |
6.4.0 | 543 | 5/16/2022 |
6.3.1 | 1,867 | 5/11/2022 |
6.3.0 | 567 | 4/28/2022 |
6.2.13 | 605 | 2/21/2022 |
6.2.12 | 572 | 2/18/2022 |
6.2.11 | 597 | 2/16/2022 |
6.2.10 | 591 | 2/13/2022 |
6.2.9 | 595 | 2/9/2022 |
6.2.8 | 594 | 2/8/2022 |
6.2.7 | 639 | 2/2/2022 |
6.2.6 | 636 | 2/1/2022 |
6.2.5 | 614 | 1/30/2022 |
6.2.4 | 623 | 1/27/2022 |
6.2.3 | 602 | 1/27/2022 |
6.2.2 | 630 | 1/24/2022 |
6.2.1 | 653 | 1/12/2022 |
6.2.0 | 490 | 1/7/2022 |
6.1.2 | 372 | 1/2/2022 |
6.1.0 | 381 | 12/26/2021 |
6.0.18 | 392 | 12/15/2021 |
6.0.17 | 373 | 12/14/2021 |
6.0.16 | 379 | 12/5/2021 |
6.0.15 | 367 | 12/4/2021 |
6.0.14 | 843 | 11/19/2021 |
6.0.13 | 398 | 11/16/2021 |
6.0.12 | 462 | 11/13/2021 |
6.0.11 | 465 | 11/8/2021 |
6.0.10 | 488 | 11/3/2021 |
6.0.9 | 424 | 11/2/2021 |
6.0.8 | 513 | 10/28/2021 |
6.0.7 | 462 | 10/27/2021 |
6.0.6 | 540 | 10/25/2021 |
6.0.5 | 511 | 10/25/2021 |
6.0.4 | 529 | 10/21/2021 |
6.0.3 | 475 | 10/15/2021 |
6.0.2 | 477 | 10/12/2021 |
6.0.1 | 503 | 10/12/2021 |
6.0.0 | 462 | 10/11/2021 |
6.0.0-prerelease.5 | 192 | 9/20/2021 |
6.0.0-prerelease.4 | 144 | 9/20/2021 |
6.0.0-prerelease.3 | 176 | 9/20/2021 |
6.0.0-prerelease.2 | 170 | 9/20/2021 |
6.0.0-prerelease.1 | 157 | 9/20/2021 |
5.4.9 | 479 | 9/30/2021 |
5.4.8 | 417 | 9/29/2021 |
5.4.7 | 508 | 9/25/2021 |
5.4.6 | 585 | 9/24/2021 |
5.4.5 | 510 | 9/22/2021 |
5.4.4 | 456 | 9/17/2021 |
5.4.3 | 414 | 9/14/2021 |
5.4.2 | 500 | 9/14/2021 |
5.4.1 | 517 | 9/8/2021 |
5.4.0 | 461 | 9/8/2021 |
5.3.6 | 506 | 8/27/2021 |
5.3.5 | 496 | 8/27/2021 |
5.3.4 | 506 | 8/27/2021 |
5.3.3 | 452 | 8/26/2021 |
5.3.2 | 427 | 8/26/2021 |
5.3.1 | 477 | 8/26/2021 |
5.3.0 | 481 | 8/26/2021 |
5.2.0 | 494 | 8/24/2021 |
5.1.4 | 505 | 8/24/2021 |
5.1.3 | 507 | 8/20/2021 |
5.1.2 | 569 | 8/19/2021 |
5.1.1 | 503 | 8/19/2021 |
5.1.0 | 497 | 8/19/2021 |
5.1.0-prerelease.2 | 181 | 8/19/2021 |
5.1.0-prerelease.1 | 172 | 8/19/2021 |
5.0.2-prerelease.1 | 169 | 8/19/2021 |
5.0.1 | 515 | 8/18/2021 |
5.0.0 | 458 | 8/18/2021 |
4.3.2 | 506 | 8/14/2021 |
4.3.1 | 404 | 8/13/2021 |
4.3.0 | 455 | 8/13/2021 |
4.2.0 | 444 | 8/13/2021 |
4.1.12 | 452 | 8/10/2021 |
4.1.11 | 497 | 8/9/2021 |
4.1.10 | 482 | 8/6/2021 |
4.1.9 | 526 | 8/5/2021 |
4.1.8 | 495 | 8/4/2021 |
4.1.7 | 502 | 8/4/2021 |
4.1.6 | 515 | 7/22/2021 |
4.1.5 | 504 | 7/13/2021 |
4.1.4 | 531 | 7/6/2021 |
4.1.3 | 592 | 6/29/2021 |
4.1.2 | 632 | 6/27/2021 |
4.1.1 | 476 | 6/21/2021 |
4.1.0 | 545 | 6/20/2021 |
4.0.23 | 532 | 6/13/2021 |
4.0.22 | 485 | 6/8/2021 |
4.0.21 | 531 | 6/2/2021 |
4.0.20 | 529 | 5/24/2021 |
4.0.19 | 439 | 5/19/2021 |
4.0.17 | 496 | 5/7/2021 |
4.0.16 | 449 | 5/5/2021 |
4.0.15 | 504 | 5/4/2021 |
4.0.14 | 465 | 4/26/2021 |
4.0.13 | 487 | 4/10/2021 |
4.0.12 | 476 | 4/9/2021 |
4.0.11 | 513 | 4/8/2021 |
4.0.10 | 471 | 4/6/2021 |
4.0.9 | 455 | 4/6/2021 |
4.0.8 | 526 | 4/3/2021 |
4.0.7 | 488 | 4/1/2021 |
4.0.6 | 502 | 3/31/2021 |
4.0.5 | 568 | 3/27/2021 |
4.0.4 | 438 | 3/25/2021 |
4.0.3 | 506 | 3/20/2021 |
4.0.2 | 495 | 3/19/2021 |
4.0.1 | 534 | 3/15/2021 |
4.0.0 | 501 | 3/5/2021 |
4.0.0-prerelease.2 | 214 | 3/5/2021 |
4.0.0-prerelease.1 | 218 | 3/4/2021 |
3.1.1-prerelease.2 | 212 | 2/24/2021 |
3.1.1-prerelease.1 | 170 | 2/23/2021 |
3.1.0 | 466 | 2/23/2021 |
3.1.0-prerelease.4 | 171 | 2/23/2021 |
3.1.0-prerelease.3 | 167 | 2/22/2021 |
3.1.0-prerelease.2 | 182 | 2/22/2021 |
3.1.0-prerelease.1 | 182 | 2/22/2021 |
3.0.1-prerelease.2 | 171 | 2/21/2021 |
3.0.1-prerelease.1 | 204 | 2/9/2021 |
3.0.0 | 484 | 2/8/2021 |
3.0.0-prerelease.4 | 179 | 2/4/2021 |
3.0.0-prerelease.3 | 174 | 1/29/2021 |
3.0.0-prerelease.2 | 179 | 1/29/2021 |
3.0.0-prerelease.1 | 196 | 1/24/2021 |
2.5.0 | 509 | 12/28/2020 |
2.4.0 | 481 | 12/11/2020 |
2.3.0 | 471 | 10/26/2020 |
2.2.0 | 488 | 9/18/2020 |
2.1.1 | 432 | 9/10/2020 |
2.1.0 | 460 | 9/10/2020 |
2.0.0 | 471 | 9/1/2020 |
'## [7.4.1](https://github.com/buehler/dotnet-operator-sdk/compare/v7.4.0...v7.4.1) (2023-07-17)
### Bug Fixes
* add backwards compatibilty for cert creation ([#578](https://github.com/buehler/dotnet-operator-sdk/issues/578)) ([789f1e3](https://github.com/buehler/dotnet-operator-sdk/commit/789f1e3d4bbc4e80e9c582f4901da88eed5b4d12))
'