11using System ;
2+ using System . Collections . Generic ;
23using System . Linq ;
34using System . Reflection ;
45using Xunit ;
@@ -8,6 +9,8 @@ namespace Tests.Framework
89{
910 public class IntegrationTestDiscoverer : NestTestDiscoverer
1011 {
12+ private bool RunningOnTeamCity { get ; } = ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( "TEAMCITY_VERSION" ) ) ;
13+
1114 public IntegrationTestDiscoverer ( IMessageSink diagnosticMessageSink )
1215 : base ( diagnosticMessageSink , TestClient . Configuration . RunIntegrationTests ) { }
1316
@@ -19,9 +22,12 @@ protected override bool SkipMethod(ITestFrameworkDiscoveryOptions discoveryOptio
1922
2023 return SkipClassMarkedWithRequiresPluginFor2XSnapshotBuildTests ( classOfMethod )
2124 || TypeSkipVersionAttributeSatisfies ( classOfMethod )
22- || MethodSkipVersionAttributeSatisfies ( method ) ;
25+ || MethodSkipVersionAttributeSatisfies ( method )
26+ || SkipWhenRunOnTeamCity ( classOfMethod , method ) ;
27+ }
2328 }
2429
30+
2531 private static bool SkipClassMarkedWithRequiresPluginFor2XSnapshotBuildTests ( Type classOfMethod )
2632 {
2733 var v = TestClient . Configuration . ElasticsearchVersion ;
@@ -31,24 +37,27 @@ private static bool SkipClassMarkedWithRequiresPluginFor2XSnapshotBuildTests(Typ
3137 return attributes . Any ( ) ;
3238 }
3339
34- private static bool TypeSkipVersionAttributeSatisfies ( Type classOfMethod )
35- {
36- var attributes = classOfMethod . GetAttributes < SkipVersionAttribute > ( ) ;
37- if ( ! attributes . Any ( ) ) return false ;
40+ private bool SkipWhenRunOnTeamCity ( Type classOfMethod , MethodInfo info ) {
41+ if ( ! this . RunningOnTeamCity ) return false ;
3842
39- return attributes
40- . SelectMany ( a => a . Ranges )
41- . Any ( range => TestClient . VersionUnderTestSatisfiedBy ( range . ToString ( ) ) ) ;
43+ var attributes = classOfMethod . GetAttributes < SkipOnTeamCityAttribute > ( ) . Concat ( info . GetAttributes < SkipOnTeamCityAttribute > ( ) ) ;
44+ return attributes . Any ( ) ;
4245 }
4346
44- private static bool MethodSkipVersionAttributeSatisfies ( MethodInfo methodInfo )
47+ private static bool TypeSkipVersionAttributeSatisfies ( Type classOfMethod ) =>
48+ VersionUnderTestMatchesAttribute ( classOfMethod . GetAttributes < SkipVersionAttribute > ( ) ) ;
49+
50+ private static bool MethodSkipVersionAttributeSatisfies ( MethodInfo methodInfo ) =>
51+ VersionUnderTestMatchesAttribute ( methodInfo . GetAttributes < SkipVersionAttribute > ( ) ) ;
52+
53+ private static bool VersionUnderTestMatchesAttribute ( IEnumerable < SkipVersionAttribute > attributes )
4554 {
46- var attributes = methodInfo . GetAttributes < SkipVersionAttribute > ( ) ;
4755 if ( ! attributes . Any ( ) ) return false ;
4856
4957 return attributes
5058 . SelectMany ( a => a . Ranges )
5159 . Any ( range => TestClient . VersionUnderTestSatisfiedBy ( range . ToString ( ) ) ) ;
5260 }
61+
5362 }
5463}
0 commit comments