Skip to content

Commit

Permalink
Updating Managed Dependencies folder installation path for local deve…
Browse files Browse the repository at this point in the history
…lopment.
  • Loading branch information
Francisco-Gamino committed Apr 9, 2019
1 parent 6e8fded commit 687a293
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
13 changes: 9 additions & 4 deletions src/DependencyManagement/DependencyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ internal class DependencyManager
// Central repository for acquiring PowerShell modules.
private const string Repository = "PSGallery";

// AzureFunctions folder name.
private const string AzureFunctionsFolderName = "AzureFunctions";

// Managed Dependencies folder name.
private const string ManagedDependenciesFolderName = "ManagedDependencies";

Expand Down Expand Up @@ -305,9 +308,9 @@ private void ValidateModuleName(string name)
/// <summary>
/// Gets the Managed Dependencies folder path.
/// If we are running in Azure, the path is HOME\data\ManagedDependencies.
/// Otherwise, the path is functionAppRoot\ManagedDependencies.
/// Otherwise, the path is LocalApplicationData\AzureFunctions\FunctionAppName\ManagedDependencies.
/// </summary>
private string GetManagedDependenciesPath(string functionAppRoot)
private string GetManagedDependenciesPath(string functionAppRootPath)
{
string managedDependenciesFolderPath = null;

Expand All @@ -325,8 +328,10 @@ private string GetManagedDependenciesPath(string functionAppRoot)
}
else
{
// Otherwise, the ManagedDependencies folder is created under the function app root.
managedDependenciesFolderPath = Path.Join(functionAppRoot, ManagedDependenciesFolderName);
// Otherwise, the ManagedDependencies folder is created under LocalApplicationData\AzureFunctions\FunctionAppName\ManagedDependencies.
string functionAppName = Path.GetFileName(functionAppRootPath);
string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify);
managedDependenciesFolderPath = Path.Combine(appDataFolder, AzureFunctionsFolderName, functionAppName, ManagedDependenciesFolderName);
}

return managedDependenciesFolderPath;
Expand Down
24 changes: 16 additions & 8 deletions test/Unit/DependencyManagement/DependencyManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class DependencyManagementTests
private readonly string _dependencyManagementDirectory;
private readonly string _functionId;
private const string ManagedDependenciesFolderName = "ManagedDependencies";
private const string AzureFunctionsFolderName = "AzureFunctions";

public DependencyManagementTests()
{
Expand All @@ -42,6 +43,14 @@ private FunctionLoadRequest GetFuncLoadRequest(string functionAppRoot, bool mana
return functionLoadRequest;
}

private string GetManagedDependenciesPath(string functionAppRootPath)
{
string functionAppName = Path.GetFileName(functionAppRootPath);
string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify);
string managedDependenciesFolderPath = Path.Combine(appDataFolder, AzureFunctionsFolderName, functionAppName, ManagedDependenciesFolderName);
return managedDependenciesFolderPath;
}

private void TestCaseCleanup()
{
// We run a test case clean up to reset DependencyManager.Dependencies and DependencyManager.DependenciesPath
Expand All @@ -66,10 +75,10 @@ public void TestManagedDependencyBasicRequirements()
{
// Test case setup.
var requirementsDirectoryName = "BasicRequirements";
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName,
"FunctionDirectory");
var managedDependenciesFolderPath = Path.Combine(_dependencyManagementDirectory,
requirementsDirectoryName, ManagedDependenciesFolderName);
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
var managedDependenciesFolderPath = GetManagedDependenciesPath(functionAppRoot);

var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);

// Create DependencyManager and process the requirements.psd1 file at the function app root.
Expand Down Expand Up @@ -97,10 +106,9 @@ public void TestManagedDependencyEmptyHashtableRequirement()
{
// Test case setup.
var requirementsDirectoryName = "EmptyHashtableRequirement";
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName,
"FunctionDirectory");
var managedDependenciesFolderPath = Path.Combine(_dependencyManagementDirectory,
requirementsDirectoryName, ManagedDependenciesFolderName);
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName,"FunctionDirectory");
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
var managedDependenciesFolderPath = GetManagedDependenciesPath(functionAppRoot);
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);

// Create DependencyManager and process the requirements.psd1 file at the function app root.
Expand Down

0 comments on commit 687a293

Please sign in to comment.