Skip to content

Commit

Permalink
Rework IntegrationTestAttribute to allow for multiple instances, carr…
Browse files Browse the repository at this point in the history
…y a flag whether it can be run on CI, don't yield the trait if it can't.
  • Loading branch information
danielcweber committed Jun 19, 2024
1 parent 08fd58e commit 2b51d3e
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace ExRam.Gremlinq.Providers.GremlinServer.Tests
{
[IntegrationTest("Windows", "Linux")]
[IntegrationTest("Linux")]
[IntegrationTest("Windows", false)]
public sealed class IntegrationAndDeserializationTests : QueryExecutionTest, IClassFixture<GremlinServerContainerFixture>
{
public IntegrationAndDeserializationTests(GremlinServerContainerFixture fixture) : base(
Expand Down
3 changes: 2 additions & 1 deletion test/Providers.GremlinServer.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace ExRam.Gremlinq.Providers.GremlinServer.Tests
{
[IntegrationTest("Windows", "Linux")]
[IntegrationTest("Linux")]
[IntegrationTest("Windows", false)]
public sealed class IntegrationTests : QueryExecutionTest, IClassFixture<GremlinServerContainerFixture>
{
public IntegrationTests(GremlinServerContainerFixture fixture) : base(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace ExRam.Gremlinq.Providers.GremlinServer.Tests
{
[IntegrationTest("Windows", "Linux")]
[IntegrationTest("Linux")]
[IntegrationTest("Windows", false)]
public sealed class IntegrationWithoutProjectionTests : QueryExecutionTest, IClassFixture<GremlinServerWithoutProjectionContainerFixture>
{
public IntegrationWithoutProjectionTests(GremlinServerWithoutProjectionContainerFixture fixture) : base(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace ExRam.Gremlinq.Providers.GremlinServer.Tests
{
[IntegrationTest("Windows", "Linux")]
[IntegrationTest("Linux")]
[IntegrationTest("Windows", false)]
public sealed class PasswordSecuredIntegrationTests : QueryExecutionTest, IClassFixture<PasswordSecuredGremlinServerContainerFixture>
{
public PasswordSecuredIntegrationTests(PasswordSecuredGremlinServerContainerFixture fixture) : base(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

namespace ExRam.Gremlinq.Providers.GremlinServer.Tests
{
[IntegrationTest("Windows", "Linux")]
[IntegrationTest("Linux")]
[IntegrationTest("Windows", false)]
public sealed class WrongPasswordIntegrationTests : GremlinqTestBase, IClassFixture<WrongPasswordGremlinServerContainerFixture>
{
public sealed class WrongPasswordGremlinServerContainerFixture : DockerfileTestContainerFixture
Expand All @@ -22,7 +23,6 @@ public WrongPasswordGremlinServerContainerFixture() : base("PasswordSecureGremli
{
}


protected override async Task<IGremlinQuerySource> TransformQuerySource(IContainer container, IGremlinQuerySource g) => g
.UseGremlinServer<Vertex, Edge>(_ => _
.At(new UriBuilder("ws", container.Hostname, container.GetMappedPublicPort(8182)).Uri)
Expand Down
3 changes: 2 additions & 1 deletion test/Providers.JanusGraph.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

namespace ExRam.Gremlinq.Providers.JanusGraph.Tests
{
[IntegrationTest("Windows", "Linux")]
[IntegrationTest("Linux")]
[IntegrationTest("Windows", false)]
public sealed class IntegrationTests : QueryExecutionTest, IClassFixture<JanusGraphContainerFixture>
{
public new sealed class Verifier : JTokenExecutingVerifier
Expand Down
3 changes: 2 additions & 1 deletion test/Providers.Neptune.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace ExRam.Gremlinq.Providers.Neptune.Tests
{
[IntegrationTest("Windows", "Linux")]
[IntegrationTest("Linux")]
[IntegrationTest("Windows", false)]
public sealed class IntegrationTests : QueryExecutionTest, IClassFixture<NeptuneContainerFixture>
{
public IntegrationTests(NeptuneContainerFixture fixture) : base(
Expand Down
9 changes: 5 additions & 4 deletions test/Tests.Infrastructure/Traits/IntegrationTestAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace ExRam.Gremlinq.Tests.Infrastructure
{
[TraitDiscoverer("ExRam.Gremlinq.Tests.Infrastructure.IntegrationTestDiscoverer", "ExRam.Gremlinq.Tests.Infrastructure")]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public sealed class IntegrationTestAttribute : Attribute, ITraitAttribute
{
public IntegrationTestAttribute(params string[] validPlatforms)
public IntegrationTestAttribute(string validPlatform, bool canRunOnCI = true)
{
ValidPlatforms = validPlatforms;
ValidPlatform = validPlatform;
}

public string[] ValidPlatforms { get; }
public bool CanRunOnCI { get; }
public string ValidPlatform { get; }
}
}
10 changes: 6 additions & 4 deletions test/Tests.Infrastructure/Traits/IntegrationTestDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ public class IntegrationTestDiscoverer : ITraitDiscoverer
{
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
{
var isCi = bool.TryParse(Environment.GetEnvironmentVariable("CI"), out var ci)
? ci
: false;

yield return new KeyValuePair<string, string>("Category", "IntegrationTest");

if (traitAttribute is ReflectionAttributeInfo { Attribute: IntegrationTestAttribute integrationTestAttribute })
{
foreach (var validPlatform in integrationTestAttribute.ValidPlatforms)
{
yield return new KeyValuePair<string, string>("ValidPlatform", validPlatform);
}
if (integrationTestAttribute.CanRunOnCI || !isCi)
yield return new KeyValuePair<string, string>("ValidPlatform", integrationTestAttribute.ValidPlatform);
}
}
}
Expand Down

0 comments on commit 2b51d3e

Please sign in to comment.