Skip to content

Commit

Permalink
Fix SyncTriggers for regular ZipDeploy functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmelsayed committed Apr 24, 2018
1 parent 3d478a2 commit 54fb4ec
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 4 deletions.
88 changes: 88 additions & 0 deletions Kudu.Core.Test/Deployment/PushDeploymentControllerFacts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.IO;
using System.IO.Abstractions;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Kudu.Contracts.Settings;
using Kudu.Contracts.Tracing;
using Kudu.Core.Deployment;
using Kudu.Core.Infrastructure;
using Kudu.Core.Tracing;
using Kudu.Services.Deployment;
using Moq;
using Xunit;

namespace Kudu.Core.Test.Deployment
{
public class PushDeploymentControllerFacts
{
[Fact]
public async Task ZipDeployInRunFromZipSetsZipNameAndSyncTriggersPath()
{
// Setup
var environment = new Mock<IEnvironment>();
var deploymentManager = new Mock<IFetchDeploymentManager>();
var tracer = new Mock<ITracer>();
var traceFactory = new Mock<ITraceFactory>();
var settings = new Mock<IDeploymentSettingsManager>();
var fileSystem = new Mock<IFileSystem>();
var fileBase = new Mock<FileBase>();
var directoryBase = new Mock<DirectoryBase>();
var fileStream = new MemoryStream();
var requestStream = new MemoryStream(Encoding.UTF8.GetBytes("Request Body"));

settings
.Setup(s => s.GetValue(It.Is<string>(t => t == SettingsKeys.RunFromZip), It.IsAny<bool>()))
.Returns("1");

environment
.SetupGet(e => e.SitePackagesPath)
.Returns(@"x:\data");

fileBase
.Setup(f => f.Create(It.IsAny<string>()))
.Returns(fileStream);
directoryBase
.Setup(d => d.Exists(It.IsAny<string>()))
.Returns(true);

fileSystem.SetupGet(f => f.File).Returns(fileBase.Object);
fileSystem.SetupGet(f => f.Directory).Returns(directoryBase.Object);

FileSystemHelpers.Instance = fileSystem.Object;

deploymentManager
.Setup(m => m.FetchDeploy(It.IsAny<ZipDeploymentInfo>(), It.IsAny<bool>(), It.IsAny<Uri>(), It.IsAny<string>()))
.Returns(Task.FromResult(FetchDeploymentRequestResult.RanSynchronously));

var controller = new PushDeploymentController(
environment.Object,
deploymentManager.Object,
tracer.Object,
traceFactory.Object,
settings.Object)
{
Request = new HttpRequestMessage(HttpMethod.Post, "https://localhost/zipDeploy")
{
Content = new StreamContent(requestStream)
}
};

// Act
var response = await controller.ZipPushDeploy();

// Assert
deploymentManager
.Verify(m => m.FetchDeploy(It.Is<ZipDeploymentInfo>(di =>
!string.IsNullOrEmpty(di.ZipName) && !string.IsNullOrEmpty(di.SyncFunctionsTriggersPath)),
It.IsAny<bool>(),
It.IsAny<Uri>(),
It.IsAny<string>()
));

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
}
1 change: 1 addition & 0 deletions Kudu.Core.Test/Kudu.Core.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<Compile Include="Deployment\FetchDeploymentManagerFacts.cs" />
<Compile Include="Deployment\Generator\ExternalCommandBuilderFacts.cs" />
<Compile Include="Deployment\Generator\SiteBuilderFactoryFacts.cs" />
<Compile Include="Deployment\PushDeploymentControllerFacts.cs" />
<Compile Include="Deployment\PythonSiteEnablerTests.cs" />
<Compile Include="Deployment\NodeSiteEnablerTests.cs" />
<Compile Include="Deployment\DeploymentManagerFacts.cs" />
Expand Down
1 change: 1 addition & 0 deletions Kudu.Core/Deployment/ZipDeploymentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public override IRepository GetRepository()

public string Message { get; set; }

// This is used if the deployment is Run-From-Zip
public string ZipName { get; set; }
}
}
13 changes: 9 additions & 4 deletions Kudu.Services/Deployment/PushDeploymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,20 @@ public async Task<HttpResponseMessage> ZipPushDeploy(
DoFullBuildByDefault = false,
Author = author,
AuthorEmail = authorEmail,
Message = message,
Message = message
};

if (_settings.RunFromLocalZip())
{
// This is used if the deployment is Run-From-Zip
// the name of the deployed file in D:\home\data\SitePackages\{name}.zip is the
// timestamp in the format yyyMMddHHmmss.
ZipName = $"{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.zip",
deploymentInfo.ZipName = $"{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.zip";

// This is also for Run-From-Zip where we need to extract the triggers
// for post deployment sync triggers.
SyncFunctionsTriggersPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())
};
deploymentInfo.SyncFunctionsTriggersPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
}

return await PushDeployAsync(deploymentInfo, isAsync);
}
Expand Down

0 comments on commit 54fb4ec

Please sign in to comment.