77using Elasticsearch . Net ;
88using FluentAssertions ;
99using Nest ;
10+ using Tests . Core . Client ;
1011using Tests . Core . Extensions ;
1112using Tests . Core . ManagedElasticsearch . Clusters ;
13+ using Tests . Domain ;
1214using Tests . Framework . EndpointTests ;
1315using Tests . Framework . EndpointTests . TestState ;
1416
@@ -24,6 +26,21 @@ public NodesUsageApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(c
2426 protected override HttpMethod HttpMethod => HttpMethod . GET ;
2527 protected override string UrlPath => "/_nodes/usage" ;
2628
29+ protected override void IntegrationSetup ( IElasticClient client , CallUniqueValues values )
30+ {
31+ var searchResponse = client . Search < Project > ( s => s
32+ . Size ( 0 )
33+ . Aggregations ( a => a
34+ . Average ( "avg_commits" , avg => avg
35+ . Field ( f => f . NumberOfCommits )
36+ )
37+ )
38+ ) ;
39+
40+ if ( ! searchResponse . IsValid )
41+ throw new Exception ( $ "Exception when setting up { nameof ( NodesUsageApiTests ) } : { searchResponse . DebugInformation } ") ;
42+ }
43+
2744 protected override LazyResponses ClientUsage ( ) => Calls (
2845 ( client , f ) => client . Nodes . Usage ( ) ,
2946 ( client , f ) => client . Nodes . UsageAsync ( ) ,
@@ -43,9 +60,15 @@ protected override void ExpectResponse(NodesUsageResponse response)
4360 response . Nodes . Should ( ) . NotBeNull ( ) ;
4461 response . Nodes . Should ( ) . HaveCount ( 1 ) ;
4562
46- response . Nodes . First ( ) . Value . Timestamp . Should ( ) . BeBefore ( DateTimeOffset . UtcNow ) ;
47- response . Nodes . First ( ) . Value . Since . Should ( ) . BeBefore ( DateTimeOffset . UtcNow ) ;
48- response . Nodes . First ( ) . Value . RestActions . Should ( ) . NotBeNull ( ) ;
63+ var firstNode = response . Nodes . First ( ) ;
64+ firstNode . Value . Timestamp . Should ( ) . BeBefore ( DateTimeOffset . UtcNow ) ;
65+ firstNode . Value . Since . Should ( ) . BeBefore ( DateTimeOffset . UtcNow ) ;
66+ firstNode . Value . RestActions . Should ( ) . NotBeNull ( ) ;
67+
68+ if ( TestClient . Configuration . InRange ( ">=7.8.0" ) )
69+ {
70+ firstNode . Value . Aggregations . Should ( ) . NotBeNull ( ) . And . ContainKey ( "avg" ) ;
71+ }
4972 }
5073 }
5174}
0 commit comments