-
Notifications
You must be signed in to change notification settings - Fork 86
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
add support for list network area and test (#381) #387
add support for list network area and test (#381) #387
Conversation
Consul.Test/OperatorTest.cs
Outdated
public async Task Operator_AreaList() | ||
{ | ||
var req = await _client.Operator.AreaList(); | ||
Assert.NotNull(req.Response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this test more exhaustive, it would be nice to create an area first and then assert that the query result is non-empty (instead of not null).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done ✅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pleas also updated the test condition, from not null to non-empty. Please inspect also a result fields if they are filled in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test are failing now with:
Consul.Test.OperatorTest.Operator_CreateArea: Consul.ConsulRequestException : Unexpected response, status code InternalServerError: area "d0c9af6b-363b-69b3-a1a9-50089871df13" with peer datacenter "dc2" already exists
Assert.NotNull(response.Response); Assert.NotNull(response.Response);
} }
[EnterpriseOnlyFact]
public async Task Operator_AreaList()
{
await _client.Operator.CreateArea(new AreaRequest { PeerDatacenter = "dc2", UseTLS = false, RetryJoin = null });
var req = await _client.Operator.AreaList();
Assert.NotNull(req.Response);
Member
@[marcin-krystianc](https://github.com/marcin-krystianc) marcin-krystianc 3 hours ago
To make this test more exhaustive, it would be nice to create an area first and then assert that the query result is non-empty (instead of not null).
Contributor
Author
@[larrytamnjong](https://github.com/larrytamnjong) larrytamnjong 29 minutes ago
Thanks, done ✅
Member
@[marcin-krystianc](https://github.com/marcin-krystianc) marcin-krystianc now
Pleas also updated the test condition, from not null to non-empty. Please inspect also a result fields if they are filled in.
@marcin-krystianc Reply...
}
} }
} }
Maybe try using a random name every time you create an area.
Thanks, @marcin-krystianc your right the error occurred because I tried adding an operator area with the name "dc2," which was already created during the "create operator area" test. I’ve fixed that issue now. Hopefully, it's okay now. |
Using fixed name is not ideal, I guess it is impossible to run that test twice in a row? The test should be implemented in a way, that makes it possible to run it multiple times without any issue. |
Thanks, @marcin-krystianc, and apologies for the back-and-forth. I’ve added a method to generate a random dc name for each test run. The tests are still in queue. Let me know if this approach works or if there's anything else you'd like me to adjust. |
Consul.Test/OperatorTest.cs
Outdated
internal static string GeneratePeerDatacenterName() | ||
{ | ||
int randomNumber = Random.Next(100, 1000); | ||
return $"ran-dc-{randomNumber}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single random number might be not enough to prevent from conflicts/duplicates. We've already a method KVTest.GenerateTestKeyName()
which is being used in many places in tests already. It generates 16 character long random string. Please use it instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcin-krystianc thanks, you can take another look now.
Consul.Test/OperatorTest.cs
Outdated
await _client.Operator.CreateArea(new AreaRequest { PeerDatacenter = peerDataCenter, UseTLS = false, RetryJoin = null }); | ||
|
||
var req = await _client.Operator.AreaList(); | ||
Assert.NotEmpty(req.Response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one more thing, can we test if the fields in the response are not null?
So far we know that we can create and list areas, but it would be great if we assert that the values returned by the list operation correspond to the values used in the create operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also try filling the RetryJoin
field and then validating the content of it when returned?
Consul.Test/OperatorTest.cs
Outdated
|
||
var req = await _client.Operator.AreaList(); | ||
Assert.NotEmpty(req.Response); | ||
Assert.Equal(area.PeerDatacenter, req.Response.First().PeerDatacenter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There can be multiple items in the result list, so the first one is not necessarily the one we are looking for. You need to look for the right one, e.g.:
var result = req.Response.Single(x => x.PeerDatacenter == area.peerDataCenter);
Assert.Equal(area.UseTLS, result.UseTLS);
Assert.Equal(area.RetryJoin, result.RetryJoin);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcin-krystianc I'm not sure if testing RetryJoin is sufficient with this approach Assert.Equal(area.RetryJoin, result.RetryJoin);
or if it would be better to test each element individually in the array, like this: for (int i = 0; i < retryJoinAddresses.Length; i++) { Assert.Equal(retryJoinAddresses[i], createdArea.RetryJoin[i]); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcin-krystianc I'm not sure if testing RetryJoin is sufficient with this approach
Assert.Equal(area.RetryJoin, result.RetryJoin);
or if it would be better to test each element individually in the array, like this:for (int i = 0; i < retryJoinAddresses.Length; i++) { Assert.Equal(retryJoinAddresses[i], createdArea.RetryJoin[i]); }
There is an overload for IEnumerable
:
public static void Equal<T>(
IEnumerable<T> expected,
IEnumerable<T> actual,
IEqualityComparer<T> comparer)
so I guess it will do the right thing.
You can try to define manually two lists and see how it reacts to different item order in both lists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's perfect now 👍
No description provided.