1- using Elastic . Xunit . XunitPlumbing ;
1+ using System ;
2+ using System . Threading . Tasks ;
3+ using Elastic . Xunit . XunitPlumbing ;
24using Elasticsearch . Net ;
35using FluentAssertions ;
46using Nest ;
911
1012namespace 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