1
- using Elastic . Xunit . XunitPlumbing ;
1
+ using System ;
2
+ using System . Threading . Tasks ;
3
+ using Elastic . Xunit . XunitPlumbing ;
2
4
using Elasticsearch . Net ;
3
5
using FluentAssertions ;
4
6
using Nest ;
9
11
10
12
namespace Tests . XPack . License . StartTrialLicense
11
13
{
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" ) ]
13
17
public class StartTrialLicenseApiTests
14
- : ApiIntegrationTestBase < XPackCluster , IStartTrialLicenseResponse , IStartTrialLicenseRequest , StartTrialLicenseDescriptor ,
18
+ : ApiIntegrationTestBase < TrialLicenseCluster , IStartTrialLicenseResponse , IStartTrialLicenseRequest , StartTrialLicenseDescriptor ,
15
19
StartTrialLicenseRequest >
16
20
{
17
- public StartTrialLicenseApiTests ( XPackCluster cluster , EndpointUsage usage ) : base ( cluster , usage ) { }
21
+ public StartTrialLicenseApiTests ( TrialLicenseCluster cluster , EndpointUsage usage ) : base ( cluster , usage ) { }
18
22
19
23
protected bool BootstrappedWithLicense => ! string . IsNullOrEmpty ( Cluster . ClusterConfiguration . XPackLicenseJson ) ;
20
24
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
+
23
33
protected override HttpMethod HttpMethod => HttpMethod . POST ;
24
34
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 ";
26
36
27
37
protected override LazyResponses ClientUsage ( ) => Calls (
28
38
( client , f ) => client . StartTrialLicense ( f ) ,
@@ -31,20 +41,14 @@ protected override LazyResponses ClientUsage() => Calls(
31
41
( client , r ) => client . StartTrialLicenseAsync ( r )
32
42
) ;
33
43
44
+ protected override StartTrialLicenseRequest Initializer => new StartTrialLicenseRequest { Acknowledge = true } ;
45
+ protected override Func < StartTrialLicenseDescriptor , IStartTrialLicenseRequest > Fluent => s => s . Acknowledge ( ) ;
46
+
34
47
protected override void ExpectResponse ( IStartTrialLicenseResponse response )
35
48
{
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" ) ;
48
52
}
49
53
}
50
54
}
0 commit comments