diff --git a/test/AWS.Deploy.CLI.IntegrationTests/Helpers/TestEnvironmentVariableManager.cs b/test/AWS.Deploy.CLI.IntegrationTests/Helpers/TestEnvironmentVariableManager.cs new file mode 100644 index 000000000..364a00a4e --- /dev/null +++ b/test/AWS.Deploy.CLI.IntegrationTests/Helpers/TestEnvironmentVariableManager.cs @@ -0,0 +1,28 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +using System; +using System.Collections.Generic; +using System.Text; +using AWS.Deploy.Orchestration.Utilities; + +namespace AWS.Deploy.CLI.IntegrationTests.Helpers +{ + public class TestEnvironmentVariableManager : IEnvironmentVariableManager + { + public readonly Dictionary store = new Dictionary(); + + public string GetEnvironmentVariable(string variable) + { + return store.ContainsKey(variable) ? store[variable] : null; + } + + public void SetEnvironmentVariable(string variable, string value) + { + if (string.Equals(variable, "AWS_DOTNET_DEPLOYTOOL_WORKSPACE")) + store[variable] = value; + else + Environment.SetEnvironmentVariable(variable, value); + } + } +} diff --git a/test/AWS.Deploy.CLI.IntegrationTests/Helpers/Utilities.cs b/test/AWS.Deploy.CLI.IntegrationTests/Helpers/Utilities.cs new file mode 100644 index 000000000..35d65913a --- /dev/null +++ b/test/AWS.Deploy.CLI.IntegrationTests/Helpers/Utilities.cs @@ -0,0 +1,41 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using AWS.Deploy.Orchestration.Utilities; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace AWS.Deploy.CLI.IntegrationTests.Helpers +{ + public static class Utilities + { + /// + /// This method sets a custom workspace which will be used by the deploy tool to create and run the CDK project and any temporary files during the deployment. + /// It also adds a nuget.config file that references a private nuget-cache. This cache holds the latest (in-development/unreleased) version of AWS.Deploy.Recipes.CDK.Common.nupkg file + /// + public static void OverrideDefaultWorkspace(ServiceProvider serviceProvider, string customWorkspace) + { + var environmentVariableManager = serviceProvider.GetRequiredService(); + environmentVariableManager.SetEnvironmentVariable("AWS_DOTNET_DEPLOYTOOL_WORKSPACE", customWorkspace); + Directory.CreateDirectory(customWorkspace); + + var nugetCachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".aws-dotnet-deploy", "Projects", "nuget-cache"); + nugetCachePath = nugetCachePath.Replace(Path.DirectorySeparatorChar, '/'); + + var nugetConfigContent = $@" + + + + + + +".Trim(); + + File.WriteAllText(Path.Combine(customWorkspace, "nuget.config"), nugetConfigContent); + } + } +} diff --git a/test/AWS.Deploy.CLI.IntegrationTests/WebAppNoDockerFileTests.cs b/test/AWS.Deploy.CLI.IntegrationTests/WebAppNoDockerFileTests.cs index f13ae0b53..a52b6a110 100644 --- a/test/AWS.Deploy.CLI.IntegrationTests/WebAppNoDockerFileTests.cs +++ b/test/AWS.Deploy.CLI.IntegrationTests/WebAppNoDockerFileTests.cs @@ -52,9 +52,7 @@ public WebAppNoDockerFileTests() var serviceProvider = serviceCollection.BuildServiceProvider(); _customWorkspace = Path.Combine(Path.GetTempPath(), $"deploy-tool-workspace{Guid.NewGuid().ToString().Split('-').Last()}"); - var environmentVariableManager = serviceProvider.GetRequiredService(); - environmentVariableManager.SetEnvironmentVariable("AWS_DOTNET_DEPLOYTOOL_WORKSPACE", _customWorkspace); - Directory.CreateDirectory(_customWorkspace); + Helpers.Utilities.OverrideDefaultWorkspace(serviceProvider, _customWorkspace); _app = serviceProvider.GetService(); Assert.NotNull(_app); @@ -204,22 +202,4 @@ protected virtual void Dispose(bool disposing) Dispose(false); } } - - public class TestEnvironmentVariableManager : IEnvironmentVariableManager - { - public readonly Dictionary store = new Dictionary(); - - public string GetEnvironmentVariable(string variable) - { - return store.ContainsKey(variable) ? store[variable] : null; - } - - public void SetEnvironmentVariable(string variable, string value) - { - if (string.Equals(variable, "AWS_DOTNET_DEPLOYTOOL_WORKSPACE")) - store[variable] = value; - else - Environment.SetEnvironmentVariable(variable, value); - } - } }