diff --git a/test/KubeOps.Operator.Test/Controller/EntityController.Integration.Test.cs b/test/KubeOps.Operator.Test/Controller/EntityController.Integration.Test.cs index fee650d9..c8c21f1c 100644 --- a/test/KubeOps.Operator.Test/Controller/EntityController.Integration.Test.cs +++ b/test/KubeOps.Operator.Test/Controller/EntityController.Integration.Test.cs @@ -16,7 +16,7 @@ namespace KubeOps.Operator.Test.Controller; -public class EntityControllerIntegrationTest : IntegrationTestBase +public sealed class EntityControllerIntegrationTest : IntegrationTestBase { private readonly InvocationCounter _mock = new(); private readonly IKubernetesClient _client = new KubernetesClient.KubernetesClient(); @@ -25,7 +25,7 @@ public class EntityControllerIntegrationTest : IntegrationTestBase [Fact] public async Task Should_Call_Reconcile_On_New_Entity() { - await _client.CreateAsync(new V1OperatorIntegrationTestEntity("test-entity", "username", _ns.Namespace)); + await _client.CreateAsync(new V1OperatorIntegrationTestEntity("test-entity", "username", _ns.Namespace, true)); await _mock.WaitForInvocations; _mock.Invocations.Count.Should().Be(1); @@ -119,12 +119,22 @@ protected override void ConfigureHost(HostApplicationBuilder builder) .AddController(); } - private class TestController(InvocationCounter svc) : IEntityController + private sealed class TestController( + InvocationCounter svc, + IKubernetesClient client) : IEntityController { - public Task> ReconcileAsync(V1OperatorIntegrationTestEntity entity, CancellationToken cancellationToken) + public async Task> ReconcileAsync(V1OperatorIntegrationTestEntity entity, CancellationToken cancellationToken) { + if (entity.Spec.CouldChangeStatus) + { + // status change: issue 1001 (https://github.com/dotnet/dotnet-operator-sdk/issues/1001) + entity.Status.Status = "reconciled"; + entity = await client.UpdateStatusAsync(entity, cancellationToken); + } + svc.Invocation(entity); - return Task.FromResult(ReconciliationResult.Success(entity)); + + return ReconciliationResult.Success(entity); } public Task> DeletedAsync(V1OperatorIntegrationTestEntity entity, CancellationToken cancellationToken) diff --git a/test/KubeOps.Operator.Test/IntegrationTestCollection.cs b/test/KubeOps.Operator.Test/IntegrationTestCollection.cs index fba46a9d..549408d8 100644 --- a/test/KubeOps.Operator.Test/IntegrationTestCollection.cs +++ b/test/KubeOps.Operator.Test/IntegrationTestCollection.cs @@ -59,12 +59,12 @@ public sealed class TestNamespaceProvider : IAsyncLifetime private readonly IKubernetesClient _client = new KubernetesClient.KubernetesClient(); private V1Namespace _namespace = null!; - public string Namespace { get; } = Guid.NewGuid().ToString().ToLower(); + public string Namespace { get; } = $"kubeops-{Guid.NewGuid().ToString().ToLower()}"; public async Task InitializeAsync() { _namespace = - await _client.CreateAsync(new V1Namespace() + await _client.CreateAsync(new V1Namespace { Metadata = new() { Name = Namespace }, }.Initialize()); diff --git a/test/KubeOps.Operator.Test/TestEntities/V1OperatorIntegrationTestEntity.cs b/test/KubeOps.Operator.Test/TestEntities/V1OperatorIntegrationTestEntity.cs index 3e9547c4..dd31c6b4 100644 --- a/test/KubeOps.Operator.Test/TestEntities/V1OperatorIntegrationTestEntity.cs +++ b/test/KubeOps.Operator.Test/TestEntities/V1OperatorIntegrationTestEntity.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +using System.Text.Json.Serialization; + using k8s.Models; using KubeOps.Abstractions.Entities; @@ -18,10 +20,11 @@ public V1OperatorIntegrationTestEntity() Kind = "OperatorIntegrationTest"; } - public V1OperatorIntegrationTestEntity(string name, string username, string ns) : this() + public V1OperatorIntegrationTestEntity(string name, string username, string ns, bool couldChangeStatus = false) : this() { Metadata.Name = name; Spec.Username = username; + Spec.CouldChangeStatus = couldChangeStatus; Metadata.NamespaceProperty = ns; } @@ -30,6 +33,8 @@ public V1OperatorIntegrationTestEntity(string name, string username, string ns) public sealed class EntitySpec { public string Username { get; set; } = string.Empty; + + public bool CouldChangeStatus { get; set; } } public sealed class EntityStatus