Skip to content

Commit 164ec24

Browse files
author
Christoph Bühler
committed
fix: linting errors in testing package
1 parent fe499b5 commit 164ec24

File tree

3 files changed

+319
-316
lines changed

3 files changed

+319
-316
lines changed

src/KubeOps.Testing/KubernetesOperatorFactory.cs

Lines changed: 82 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -12,104 +12,103 @@
1212
using Microsoft.Extensions.Hosting;
1313
using Microsoft.Extensions.Logging;
1414

15-
namespace KubeOps.Testing
15+
namespace KubeOps.Testing;
16+
17+
/// <summary>
18+
/// Operator factory for testing an operator created with the asp web server.
19+
/// </summary>
20+
/// <typeparam name="TTestStartup">Type of the Startup type (see asp.net).</typeparam>
21+
public class KubernetesOperatorFactory<TTestStartup> : WebApplicationFactory<TTestStartup>
22+
where TTestStartup : class
1623
{
24+
private string? _solutionRelativeContentRoot;
25+
1726
/// <summary>
18-
/// Operator factory for testing an operator created with the asp web server.
27+
/// Return a mocked kubernetes client. This client defines
28+
/// no-op for all related methods.
1929
/// </summary>
20-
/// <typeparam name="TTestStartup">Type of the Startup type (see asp.net).</typeparam>
21-
public class KubernetesOperatorFactory<TTestStartup> : WebApplicationFactory<TTestStartup>
22-
where TTestStartup : class
23-
{
24-
private string? _solutionRelativeContentRoot;
30+
public MockKubernetesClient MockedKubernetesClient =>
31+
Services.GetRequiredService<IKubernetesClient>() as MockKubernetesClient ??
32+
throw new ArgumentException("Wrong kubernetes client registered.");
2533

26-
/// <summary>
27-
/// Return a mocked kubernetes client. This client defines
28-
/// no-op for all related methods.
29-
/// </summary>
30-
public MockKubernetesClient MockedKubernetesClient =>
31-
Services.GetRequiredService<IKubernetesClient>() as MockKubernetesClient ??
32-
throw new ArgumentException("Wrong kubernetes client registered.");
33-
34-
/// <summary>
35-
/// Set a specific content root path to the given factory.
36-
/// </summary>
37-
/// <param name="root">The solution relative content root path to configure.</param>
38-
/// <returns>The <see cref="KubernetesOperatorFactory{TTestStartup}"/> for chaining.</returns>
39-
public KubernetesOperatorFactory<TTestStartup> WithSolutionRelativeContentRoot(string root)
40-
{
41-
_solutionRelativeContentRoot = root;
42-
return this;
43-
}
44-
45-
/// <summary>
46-
/// Start the server.
47-
/// </summary>
48-
public void Run()
49-
{
50-
// This triggers "EnsureServer()" in the base class.
51-
var server = Server;
52-
}
34+
/// <summary>
35+
/// Set a specific content root path to the given factory.
36+
/// </summary>
37+
/// <param name="root">The solution relative content root path to configure.</param>
38+
/// <returns>The <see cref="KubernetesOperatorFactory{TTestStartup}"/> for chaining.</returns>
39+
public KubernetesOperatorFactory<TTestStartup> WithSolutionRelativeContentRoot(string root)
40+
{
41+
_solutionRelativeContentRoot = root;
42+
return this;
43+
}
5344

54-
public Task EnqueueEvent<TEntity>(
55-
ResourceEventType type,
56-
TEntity resource,
57-
int attempt = 0,
58-
TimeSpan? delay = null)
59-
where TEntity : class, IKubernetesObject<V1ObjectMeta>
60-
{
61-
var queue = Services.GetService<IEventQueue<TEntity>>();
45+
/// <summary>
46+
/// Start the server.
47+
/// </summary>
48+
public void Run()
49+
{
50+
// This triggers "EnsureServer()" in the base class.
51+
var server = Server;
52+
}
6253

63-
queue?.EnqueueLocal(new ResourceEvent<TEntity>(type, resource, attempt, delay));
54+
public Task EnqueueEvent<TEntity>(
55+
ResourceEventType type,
56+
TEntity resource,
57+
int attempt = 0,
58+
TimeSpan? delay = null)
59+
where TEntity : class, IKubernetesObject<V1ObjectMeta>
60+
{
61+
var queue = Services.GetService<IEventQueue<TEntity>>();
6462

65-
return Task.CompletedTask;
66-
}
63+
queue?.EnqueueLocal(new ResourceEvent<TEntity>(type, resource, attempt, delay));
6764

68-
public Task EnqueueFinalization<TEntity>(TEntity resource)
69-
where TEntity : class, IKubernetesObject<V1ObjectMeta>
70-
{
71-
var queue = Services.GetService<IEventQueue<TEntity>>();
65+
return Task.CompletedTask;
66+
}
7267

73-
queue?.EnqueueLocal(new ResourceEvent<TEntity>(ResourceEventType.Finalizing, resource));
68+
public Task EnqueueFinalization<TEntity>(TEntity resource)
69+
where TEntity : class, IKubernetesObject<V1ObjectMeta>
70+
{
71+
var queue = Services.GetService<IEventQueue<TEntity>>();
7472

75-
return Task.CompletedTask;
76-
}
73+
queue?.EnqueueLocal(new ResourceEvent<TEntity>(ResourceEventType.Finalizing, resource));
7774

78-
/// <summary>
79-
/// Create the host builder. Needed for the factory.
80-
/// </summary>
81-
/// <returns>The created <see cref="IHostBuilder"/>.</returns>
82-
protected override IHostBuilder CreateHostBuilder() =>
83-
Host.CreateDefaultBuilder()
84-
.ConfigureWebHostDefaults(
85-
webBuilder => webBuilder
86-
.UseStartup<TTestStartup>());
75+
return Task.CompletedTask;
76+
}
8777

88-
/// <summary>
89-
/// Configure the web-host.
90-
/// This registers the mocked client as well as mocked
91-
/// event queues.
92-
/// </summary>
93-
/// <param name="builder">The web host builder.</param>
94-
protected override void ConfigureWebHost(IWebHostBuilder builder)
95-
{
96-
base.ConfigureWebHost(builder);
97-
builder.ConfigureTestServices(
98-
services =>
99-
{
100-
var elector = services.First(
101-
d => d.ServiceType == typeof(IHostedService) && d.ImplementationType == typeof(LeaderElector));
102-
services.Remove(elector);
78+
/// <summary>
79+
/// Create the host builder. Needed for the factory.
80+
/// </summary>
81+
/// <returns>The created <see cref="IHostBuilder"/>.</returns>
82+
protected override IHostBuilder CreateHostBuilder() =>
83+
Host.CreateDefaultBuilder()
84+
.ConfigureWebHostDefaults(
85+
webBuilder => webBuilder
86+
.UseStartup<TTestStartup>());
10387

104-
services.RemoveAll(typeof(IEventQueue<>));
105-
services.AddSingleton(typeof(IEventQueue<>), typeof(MockEventQueue<>));
106-
});
107-
if (_solutionRelativeContentRoot != null)
88+
/// <summary>
89+
/// Configure the web-host.
90+
/// This registers the mocked client as well as mocked
91+
/// event queues.
92+
/// </summary>
93+
/// <param name="builder">The web host builder.</param>
94+
protected override void ConfigureWebHost(IWebHostBuilder builder)
95+
{
96+
base.ConfigureWebHost(builder);
97+
builder.ConfigureTestServices(
98+
services =>
10899
{
109-
builder.UseSolutionRelativeContentRoot(_solutionRelativeContentRoot);
110-
}
100+
var elector = services.First(
101+
d => d.ServiceType == typeof(IHostedService) && d.ImplementationType == typeof(LeaderElector));
102+
services.Remove(elector);
111103

112-
builder.ConfigureLogging(logging => logging.ClearProviders());
104+
services.RemoveAll(typeof(IEventQueue<>));
105+
services.AddSingleton(typeof(IEventQueue<>), typeof(MockEventQueue<>));
106+
});
107+
if (_solutionRelativeContentRoot != null)
108+
{
109+
builder.UseSolutionRelativeContentRoot(_solutionRelativeContentRoot);
113110
}
111+
112+
builder.ConfigureLogging(logging => logging.ClearProviders());
114113
}
115114
}

0 commit comments

Comments
 (0)