Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action: disable tests targeting TestContainers Cloud if Forked PRs #2275

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions test/Elastic.Apm.Tests.Utilities/Docker/DockerFactAttribute.cs

This file was deleted.

35 changes: 0 additions & 35 deletions test/Elastic.Apm.Tests.Utilities/Docker/DockerTheoryAttribute.cs

This file was deleted.

25 changes: 0 additions & 25 deletions test/Elastic.Apm.Tests.Utilities/Docker/DockerUtils.cs

This file was deleted.

4 changes: 1 addition & 3 deletions test/Elastic.Apm.Tests.Utilities/TestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public static class TestEnvironment

static TestEnvironment()
{
// TODO this IsCi check is no longer valid, once we are green on Github Action
// we should be able to remove all special handling related to this
IsCi = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BUILD_ID"));
IsCi = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI"));
IsGitHubActions = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTION"));
IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Apm.Tests.Utilities.Docker;
using Xunit;

namespace Elastic.Apm.Tests.Utilities.XUnit;
Expand Down
79 changes: 79 additions & 0 deletions test/Elastic.Apm.Tests.Utilities/XUnit/DockerAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Licensed to Elasticsearch B.V under
// one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System.IO;
using ProcNet;
using Xunit;

namespace Elastic.Apm.Tests.Utilities.XUnit;


/// <inheritdoc cref="DockerTheory"/>
public sealed class DockerFact : FactAttribute
{
public DockerFact() => Skip = DockerTheory.ShouldSkip();
}

/// <summary>
/// <para>Locally we always run TestContainers through docker.</para>
/// <para>On Github Actions windows hosts we use TC cloud to launch linux docker containers</para>
/// <para>
/// When forks run the tests on pull request TestContainers Cloud won't be configured and available.
/// So we opt to skip instead.
/// </para>
/// </summary>
public sealed class DockerTheory : TheoryAttribute
{
public DockerTheory() => Skip = ShouldSkip();

public static string ShouldSkip()
{
var tcCloudConfigured = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TC_CLOUD_TOKEN"));
if (TestEnvironment.IsGitHubActions
&& TestEnvironment.IsWindows
&& !tcCloudConfigured)
return "Running on Github Action Windows host with no active TC_CLOUD_TOKEN configuration, skipping.";
// if running locally skip the test because it needs docker installed.
else if (!DockerUtils.HasDockerInstalled)
return "This test requires docker to be installed";

return null;
}
}

/// <summary>
/// Marks a test that has to be running inside of a docker container
/// </summary>
public class RunningInDockerFactAttribute : FactAttribute
{
public RunningInDockerFactAttribute()
{
if (!DockerUtils.IsRunningInDocker())
Skip = "Not running in a docker container";
}
}

internal static class DockerUtils
{
public static bool IsRunningInDocker() =>
File.Exists("/proc/1/cgroup") && File.ReadAllText("/proc/1/cgroup").Contains("docker");

public static bool HasDockerInstalled { get; }

static DockerUtils()
{
try
{
var result = Proc.Start(new StartArguments("docker", "--version"));
HasDockerInstalled = result.ExitCode == 0;
}
catch (Exception)
{
HasDockerInstalled = false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information

using Elastic.Apm.Report;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;

namespace Elastic.Apm.Docker.Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Elastic.Apm.Api;
using Elastic.Apm.DiagnosticSource;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using Elasticsearch.Net;
using FluentAssertions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Elastic.Apm.Api;
using Elastic.Apm.MongoDb.Tests.Fixture;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using MongoDB.Bson;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Elastic.Apm.EntityFrameworkCore;
using Elastic.Apm.Instrumentations.SqlClient;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Elastic.Apm.Api;
using Elastic.Apm.Instrumentations.SqlClient;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Api;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using StackExchange.Redis;
using Testcontainers.Redis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Elastic.Apm.DiagnosticSource;
using Elastic.Apm.Elasticsearch;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Tests.MockApmServer;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Tests.MockApmServer;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Tests.MockApmServer;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Tests.MockApmServer;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Tests.MockApmServer;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Tests.MockApmServer;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Tests.MockApmServer;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Loading