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

Fix SSI tests for profiler integration tests #6016

Merged
merged 1 commit into from
Sep 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
using System.Linq;
using System.Net;
using Datadog.Profiler.IntegrationTests.Helpers;
using Datadog.Profiler.IntegrationTests.Xunit;
using FluentAssertions;
using Newtonsoft.Json.Linq;
using Xunit;
using Xunit.Abstractions;

namespace Datadog.Profiler.IntegrationTests.SingleStepInstrumentation
{
[EnvironmentRestorerAttribute(EnvironmentVariables.SsiDeployed)]
public class SingleStepInstrumentationTest
{
private readonly ITestOutputHelper _output;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// <copyright file="EnvironmentRestorerAttribute.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2022 Datadog, Inc.
// </copyright>

using System;
using System.Collections.Generic;
using System.Reflection;
using Xunit.Sdk;

namespace Datadog.Profiler.IntegrationTests.Xunit;

[AttributeUsage(AttributeTargets.Class)]
public class EnvironmentRestorerAttribute : BeforeAfterTestAttribute
{
private readonly string[] _variables;
private readonly Dictionary<string, string> _originalVariables;

public EnvironmentRestorerAttribute(params string[] args)
{
_variables = args;
_originalVariables = new(args.Length);
}

public override void Before(MethodInfo methodUnderTest)
{
foreach (var variable in _variables)
{
_originalVariables[variable] = Environment.GetEnvironmentVariable(variable);
// clear variable
Environment.SetEnvironmentVariable(variable, null);
}

base.Before(methodUnderTest);
}

public override void After(MethodInfo methodUnderTest)
{
foreach (var variable in _originalVariables)
{
Environment.SetEnvironmentVariable(variable.Key, variable.Value);
}
}
}
Loading