-
Notifications
You must be signed in to change notification settings - Fork 727
Adding public API test coverage for Aspire.Hosting.Elasticsearch #5119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
598b9fe
25b3abb
acf8bce
29265c2
c53018f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Aspire.Hosting.ApplicationModel; | ||
| using Xunit; | ||
|
|
||
| namespace Aspire.Hosting.Elasticsearch.Tests; | ||
|
|
||
| public class ElasticsearchPublicApiTests | ||
| { | ||
| [Fact] | ||
| public void AddElasticsearchContainerShouldThrowWhenBuilderIsNull() | ||
| { | ||
| IDistributedApplicationBuilder builder = null!; | ||
| const string name = "Elasticsearch"; | ||
|
|
||
| var action = () => builder.AddElasticsearch(name); | ||
|
|
||
| var exception = Assert.Throws<ArgumentNullException>(action); | ||
| Assert.Equal(nameof(builder), exception.ParamName); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AddElasticsearchContainerShouldThrowWhenNameIsNull() | ||
| { | ||
| IDistributedApplicationBuilder builder = new DistributedApplicationBuilder([]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I found out. Better to use TestDistributedApplicationBuilder.Create();
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFIK
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I wanted this more from the point of view that there would be a single code base for checking the public 'null'. |
||
| string name = null!; | ||
|
|
||
| var action = () => builder.AddElasticsearch(name); | ||
|
|
||
| var exception = Assert.Throws<ArgumentNullException>(action); | ||
| Assert.Equal(nameof(name), exception.ParamName); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(false)] | ||
| [InlineData(true)] | ||
| public void WithDataShouldThrowWhenBuilderIsNull(bool useVolume) | ||
| { | ||
| IResourceBuilder<ElasticsearchResource> builder = null!; | ||
|
|
||
| Func<IResourceBuilder<ElasticsearchResource>>? action = null; | ||
|
|
||
| if (useVolume) | ||
| { | ||
| action = () => builder.WithDataVolume(); | ||
| } | ||
| else | ||
| { | ||
| const string source = "/data"; | ||
|
|
||
| action = () => builder.WithDataBindMount(source); | ||
| } | ||
|
|
||
| var exception = Assert.Throws<ArgumentNullException>(action); | ||
| Assert.Equal(nameof(builder), exception.ParamName); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WithDataBindMountShouldThrowWhenSourceIsNull() | ||
| { | ||
| var builder = new DistributedApplicationBuilder([]); | ||
| var resourceBuilder = builder.AddElasticsearch("Elasticsearch"); | ||
|
|
||
| string source = null!; | ||
|
|
||
| var action = () => resourceBuilder.WithDataBindMount(source); | ||
|
|
||
| var exception = Assert.Throws<ArgumentNullException>(action); | ||
| Assert.Equal(nameof(source), exception.ParamName); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CtorElasticsearchResourceShouldThrowWhenNameIsNull() | ||
| { | ||
| var builder = new DistributedApplicationBuilder([]); | ||
| builder.Configuration["Parameters:Password"] = "p@ssw0rd"; | ||
| var password = builder.AddParameter("Password"); | ||
| const string name = null!; | ||
|
|
||
| var action = () => new ElasticsearchResource(name, password.Resource); | ||
|
|
||
| var exception = Assert.Throws<ArgumentNullException>(action); | ||
| Assert.Equal(nameof(name), exception.ParamName); | ||
| } | ||
| [Fact] | ||
| public void CtorElasticsearchResourceShouldThrowWhenPasswordIsNull() | ||
| { | ||
| const string name = "Elasticsearch"; | ||
| ParameterResource password = null!; | ||
|
|
||
| var action = () => new ElasticsearchResource(name, password); | ||
|
|
||
| var exception = Assert.Throws<ArgumentNullException>(action); | ||
| Assert.Equal(nameof(password), exception.ParamName); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.