Skip to content

Commit

Permalink
ensure we can write to console out early if e2e is not configured pro…
Browse files Browse the repository at this point in the history
…perly
  • Loading branch information
Mpdreamz committed Feb 12, 2024
1 parent 132b691 commit 1b6e9db
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ jobs:
- run: ./build.sh test --test-suite=e2e
env:
E2E__ENDPOINT: "${{env.ELASTIC_APM_SERVER_URL}}"
E2E__Authorization: "Authentication=ApiKey ${{env.ELASTIC_APM_API_KEY}}"
E2E__AUTHORIZATION: "Authentication=ApiKey ${{env.ELASTIC_APM_API_KEY}}"
E2E__BROWSEREMAIL: "${{env.KIBANA_USERNAME}}"
E2E__BROWSERPASSWORD: "${{env.KIBANA_PASSWORD}}"
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Microsoft.Extensions.Configuration;
using Microsoft.Playwright;
using Xunit;

namespace Elastic.OpenTelemetry.EndToEndTests.DistributedFixture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public async Task InitializeAsync()
AspNetApplication = new AspNetCoreExampleApplication(ServiceName, configuration);
ApmUI = new ApmUIBrowserContext(configuration, ServiceName);

Console.WriteLine("Initializing.......?");

foreach (var trafficSimulator in _trafficSimulators)
await trafficSimulator.Start(this);

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

using System.Net;
using FluentAssertions;

namespace Elastic.OpenTelemetry.EndToEndTests.DistributedFixture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.Playwright" Version="1.41.1"/>
<PackageReference Include="Nullean.Xunit.Partitions" Version="0.4.2" />
<PackageReference Include="Proc" Version="0.8.1"/>
<PackageReference Include="XunitContext" Version="3.3.1"/>
<!--<PackageReference Include="XunitContext" Version="3.3.1"/>-->
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0"/>
Expand Down
41 changes: 34 additions & 7 deletions tests/Elastic.OpenTelemetry.EndToEndTests/GlobalSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,45 @@
// 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

global using Xunit;
global using FluentAssertions;
using System.Runtime.CompilerServices;
using Elastic.OpenTelemetry.EndToEndTests;
using Elastic.OpenTelemetry.EndToEndTests.DistributedFixture;
using FluentAssertions;
using Microsoft.Extensions.Configuration;
using Nullean.Xunit.Partitions;
using Xunit;

[assembly: TestFramework(Partition.TestFramework, Partition.Assembly)]
[assembly: PartitionOptions(typeof(EndToEndOptions))]

namespace Elastic.OpenTelemetry.EndToEndTests;

public static class GlobalSetup
public class EndToEndOptions : PartitionOptions
{
[ModuleInitializer]
public static void Setup() =>
XunitContext.EnableExceptionCapture();
public EndToEndOptions() { }

public override void OnBeforeTestsRun()
{
var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddUserSecrets<DotNetRunApplication>()
.Build();
try
{
configuration["E2E:Endpoint"].Should()
.NotBeNullOrWhiteSpace("Missing E2E:Endpoint configuration");
configuration["E2E:Authorization"].Should()
.NotBeNullOrWhiteSpace("Missing E2E:Authorization configuration");
configuration["E2E:BrowserEmail"].Should()
.NotBeNullOrWhiteSpace("Missing E2E:BrowserEmail configuration");
configuration["E2E:BrowserPassword"].Should()
.NotBeNullOrWhiteSpace("Missing E2E:BrowserPassword configuration");
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine(e.Message);
Console.WriteLine();
throw;
}
}
}
8 changes: 6 additions & 2 deletions tests/Elastic.OpenTelemetry.EndToEndTests/ServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
// See the LICENSE file in the project root for more information

using Elastic.OpenTelemetry.EndToEndTests.DistributedFixture;
using FluentAssertions;
using Microsoft.Playwright;
using Nullean.Xunit.Partitions.Sdk;
using Xunit;
using Xunit.Abstractions;
using static Microsoft.Playwright.Assertions;

namespace Elastic.OpenTelemetry.EndToEndTests;

public class EndToEndTests(ITestOutputHelper output, DistributedApplicationFixture fixture)
: XunitContextBase(output), IPartitionFixture<DistributedApplicationFixture>, IAsyncLifetime
: IPartitionFixture<DistributedApplicationFixture>, IAsyncLifetime
{
public ITestOutputHelper Output { get; } = output;
private string _testName = string.Empty;
private IPage _page = null!;

Expand All @@ -31,5 +35,5 @@ public async Task LatencyShowsAGraph()

public async Task InitializeAsync() => _page = await fixture.ApmUI.NewProfiledPage(_testName);

public async Task DisposeAsync() => await fixture.ApmUI.StopTrace(_page, XunitContext.Context.TestException == null ? null : _testName);
public async Task DisposeAsync() => await fixture.ApmUI.StopTrace(_page, null == null ? null : _testName);
}

0 comments on commit 1b6e9db

Please sign in to comment.