Skip to content

Commit c977bb0

Browse files
committed
Start Trial and Basic integration tests now run against isolated cluster, StartTrialResponse needs to be subclass of AcknowledgedResponse
1 parent d42cbc6 commit c977bb0

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

src/Nest/XPack/License/StartTrialLicense/StartTrialLicenseResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Nest
44
{
5-
public interface IStartTrialLicenseResponse : IResponse
5+
public interface IStartTrialLicenseResponse : IAcknowledgedResponse
66
{
77
[JsonProperty("error_message")]
88
string ErrorMessage { get; }
@@ -11,7 +11,7 @@ public interface IStartTrialLicenseResponse : IResponse
1111
bool TrialWasStarted { get; }
1212
}
1313

14-
public class StartTrialLicenseResponse : ResponseBase, IStartTrialLicenseResponse
14+
public class StartTrialLicenseResponse : AcknowledgedResponseBase, IStartTrialLicenseResponse
1515
{
1616
public string ErrorMessage { get; internal set; }
1717
public bool TrialWasStarted { get; internal set; }

src/Tests/Tests/XPack/License/StartBasicLicense/StartBasicLicenseApiTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using Elastic.Xunit.XunitPlumbing;
1+
using Elastic.Xunit.XunitPlumbing;
32
using Elasticsearch.Net;
43
using FluentAssertions;
54
using Nest;
@@ -10,11 +9,13 @@
109

1110
namespace Tests.XPack.License.StartBasicLicense
1211
{
12+
public class BasicLicenseCluster : ClientTestClusterBase { }
13+
1314
[SkipVersion("<6.5.0", "")]
1415
public class StartBasicLicenseApiTests
15-
: ApiIntegrationTestBase<XPackCluster, IStartBasicLicenseResponse, IStartBasicLicenseRequest, StartBasicLicenseDescriptor, StartBasicLicenseRequest>
16+
: ApiIntegrationTestBase<BasicLicenseCluster, IStartBasicLicenseResponse, IStartBasicLicenseRequest, StartBasicLicenseDescriptor, StartBasicLicenseRequest>
1617
{
17-
public StartBasicLicenseApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
18+
public StartBasicLicenseApiTests(BasicLicenseCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1819

1920
protected override bool ExpectIsValid => false;
2021
protected override int ExpectStatusCode => 200;
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Elastic.Xunit.XunitPlumbing;
1+
using System;
2+
using System.Threading.Tasks;
3+
using Elastic.Xunit.XunitPlumbing;
24
using Elasticsearch.Net;
35
using FluentAssertions;
46
using Nest;
@@ -9,20 +11,28 @@
911

1012
namespace Tests.XPack.License.StartTrialLicense
1113
{
12-
[SkipVersion("<6.1.0", "Only exists in Elasticsearch 6.1.0+")]
14+
public class TrialLicenseCluster : ClientTestClusterBase { }
15+
16+
[SkipVersion("<6.4.0", "Only exists in Elasticsearch 6.1.0+, expect x-pack to ship in default distribution")]
1317
public class StartTrialLicenseApiTests
14-
: ApiIntegrationTestBase<XPackCluster, IStartTrialLicenseResponse, IStartTrialLicenseRequest, StartTrialLicenseDescriptor,
18+
: ApiIntegrationTestBase<TrialLicenseCluster, IStartTrialLicenseResponse, IStartTrialLicenseRequest, StartTrialLicenseDescriptor,
1519
StartTrialLicenseRequest>
1620
{
17-
public StartTrialLicenseApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
21+
public StartTrialLicenseApiTests(TrialLicenseCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1822

1923
protected bool BootstrappedWithLicense => !string.IsNullOrEmpty(Cluster.ClusterConfiguration.XPackLicenseJson);
2024

21-
protected override bool ExpectIsValid => BootstrappedWithLicense;
22-
protected override int ExpectStatusCode => BootstrappedWithLicense ? 200 : 403;
25+
protected override bool ExpectIsValid => true;
26+
[I] public override async Task ReturnsExpectedIsValid() =>
27+
await AssertOnAllResponses(r => r.ShouldHaveExpectedIsValid(r.TrialWasStarted));
28+
29+
protected override int ExpectStatusCode => 200;
30+
[I] public override async Task ReturnsExpectedStatusCode() =>
31+
await AssertOnAllResponses(r => r.ApiCall.HttpStatusCode.Should().Be(r.TrialWasStarted ? 200 : 403));
32+
2333
protected override HttpMethod HttpMethod => HttpMethod.POST;
2434
protected override bool SupportsDeserialization => false;
25-
protected override string UrlPath => $"/_xpack/license/start_trial";
35+
protected override string UrlPath => $"/_xpack/license/start_trial?acknowledge=true";
2636

2737
protected override LazyResponses ClientUsage() => Calls(
2838
(client, f) => client.StartTrialLicense(f),
@@ -31,20 +41,14 @@ protected override LazyResponses ClientUsage() => Calls(
3141
(client, r) => client.StartTrialLicenseAsync(r)
3242
);
3343

44+
protected override StartTrialLicenseRequest Initializer => new StartTrialLicenseRequest { Acknowledge = true };
45+
protected override Func<StartTrialLicenseDescriptor, IStartTrialLicenseRequest> Fluent => s => s.Acknowledge();
46+
3447
protected override void ExpectResponse(IStartTrialLicenseResponse response)
3548
{
36-
response.TrialWasStarted.Should().BeFalse();
37-
if (!BootstrappedWithLicense)
38-
{
39-
// license already applied
40-
response.ErrorMessage.Should().Be("Operation failed: Trial was already activated.");
41-
}
42-
else
43-
{
44-
// running with a license means you have to pass the acknowledge flag to forcefully go
45-
// into trial mode
46-
response.ErrorMessage.Should().Contain(" Needs acknowledgement");
47-
}
49+
response.Acknowledged.Should().BeTrue();
50+
if (!response.TrialWasStarted)
51+
response.ErrorMessage.Should().NotBeNullOrWhiteSpace().And.Contain("Trial was already activated");
4852
}
4953
}
5054
}

0 commit comments

Comments
 (0)