Skip to content

Commit

Permalink
fix copying compressed pkg issue (#6347)
Browse files Browse the repository at this point in the history
* fix copying compressed pkg issue

* remove useless variable and add more unit tests
  • Loading branch information
BinWuMSFT authored Feb 2, 2018
1 parent 4a7f371 commit 33fb4d3
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Tasks/ServiceFabricDeploy/Create-DiffPackage.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ function Copy-DiffPackage
$localPkgPath = Join-Path $localParentPkgPath $localPackage.Name
$diffPkgPath = Join-Path $diffParentPkgPath $localPackage.Name

if (Test-Path -Path ($localPkgPath + ".zip"))
{
$localPkgPath += ".zip"
$diffPkgPath += ".zip"
}

Write-Host (Get-VstsLocString -Key DIFFPKG_CopyingToDiffPackge -ArgumentList @($localPkgPath, $diffPkgPath))
# Copy the package on this level to diff package which is considered to be Leaf
Copy-Item $localPkgPath $diffPkgPath -Recurse
Expand Down
40 changes: 39 additions & 1 deletion Tasks/ServiceFabricDeploy/Tests/CreateDiffPkg.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ $serviceManifestPath2 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless2Pkg\S
$serviceManifestDiffPath2 = $diffPackagePath + "\Stateless2Pkg\ServiceManifest.xml"
$codePkg2 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless2Pkg\Code"
$codeDiffPkg2 = $diffPackagePath + "\Stateless2Pkg\Code"
$serviceManifestPath3 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless3Pkg\ServiceManifest.xml"
$serviceManifestDiffPath3 = $diffPackagePath + "\Stateless3Pkg\ServiceManifest.xml"
$codePkg3 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless3Pkg\Code.zip"
$codeDiffPkg3 = $diffPackagePath + "\Stateless3Pkg\Code.zip"
$serviceManifestPath4 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless4Pkg\ServiceManifest.xml"
$serviceManifestDiffPath4 = $diffPackagePath + "\Stateless4Pkg\ServiceManifest.xml"
$codePkg4 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless4Pkg\Code.zip"
$codeDiffPkg4 = $diffPackagePath + "\Stateless4Pkg\Code.zip"

# Setup input arguments
Register-Mock Get-VstsInput { $publishProfilePath } -- -Name publishProfilePath
Expand Down Expand Up @@ -75,7 +83,13 @@ $serviceType1 = @{
$serviceType2 = @{
"ServiceManifestName" = "Stateless2Pkg"
}
$serviceTypes = @($serviceType1, $serviceType2)
$serviceType3 = @{
"ServiceManifestName" = "Stateless3Pkg"
}
$serviceType4 = @{
"ServiceManifestName" = "Stateless4Pkg"
}
$serviceTypes = @($serviceType1, $serviceType2, $serviceType3, $serviceType4)
$serviceManifest1 = '<ServiceManifest Name="Stateless1Pkg" Version="1.0.0">' +
'<ServiceTypes>' +
'<StatelessServiceType ServiceTypeName="Stateless1Type" />' +
Expand All @@ -92,12 +106,32 @@ $serviceManifest2 = '<ServiceManifest Name="Stateless2Pkg" Version="1.0.0">' +
'</CodePackage>' +
'<ConfigPackage Name="Config" Version="1.0.0" />' +
'</ServiceManifest>'
$serviceManifest3 = '<ServiceManifest Name="Stateless3Pkg" Version="1.0.0">' +
'<ServiceTypes>' +
'<StatelessServiceType ServiceTypeName="Stateless3Type" />' +
'</ServiceTypes>' +
'<CodePackage Name="Code" Version="1.0.0">' +
'</CodePackage>' +
'<ConfigPackage Name="Config" Version="1.0.0" />' +
'</ServiceManifest>'
$serviceManifest4 = '<ServiceManifest Name="Stateless4Pkg" Version="1.0.0">' +
'<ServiceTypes>' +
'<StatelessServiceType ServiceTypeName="Stateless4Type" />' +
'</ServiceTypes>' +
'<CodePackage Name="Code" Version="1.0.0">' +
'</CodePackage>' +
'<ConfigPackage Name="Config" Version="1.0.0" />' +
'</ServiceManifest>'

Register-Mock Get-ServiceFabricServiceType {$serviceTypes} -- -ApplicationTypeName $applicationTypeName -ApplicationTypeVersion $applicationTypeVersion
Register-Mock Get-ServiceFabricServiceManifest {$serviceManifest1} -- -ApplicationTypeName $applicationTypeName -ApplicationTypeVersion $applicationTypeVersion -ServiceManifestName "Stateless1Pkg"
Register-Mock Get-ServiceFabricServiceManifest {$serviceManifest2} -- -ApplicationTypeName $applicationTypeName -ApplicationTypeVersion $applicationTypeVersion -ServiceManifestName "Stateless2Pkg"
Register-Mock Get-ServiceFabricServiceManifest {$serviceManifest3} -- -ApplicationTypeName $applicationTypeName -ApplicationTypeVersion $applicationTypeVersion -ServiceManifestName "Stateless3Pkg"
Register-Mock Get-ServiceFabricServiceManifest {$serviceManifest4} -- -ApplicationTypeName $applicationTypeName -ApplicationTypeVersion $applicationTypeVersion -ServiceManifestName "Stateless4Pkg"

Register-Mock Copy-Item {} $appManifestPath $appManifestDiffPath -Force
Register-Mock Test-Path { $true } -Path $codePkg3
Register-Mock Test-Path { $true } -Path $codePkg4

Microsoft.PowerShell.Core\Import-Module "$PSScriptRoot\..\Create-DiffPackage.psm1"

Expand All @@ -109,6 +143,10 @@ Microsoft.PowerShell.Core\Import-Module "$PSScriptRoot\..\Create-DiffPackage.psm
Assert-WasCalled Copy-Item $appManifestPath $appManifestDiffPath -Force
Assert-WasCalled Copy-Item $serviceManifestPath1 $serviceManifestDiffPath1 -Force -Times 0
Assert-WasCalled Copy-Item $serviceManifestPath2 $serviceManifestDiffPath2 -Force
Assert-WasCalled Copy-Item $serviceManifestPath3 $serviceManifestDiffPath3 -Force -Times 0
Assert-WasCalled Copy-Item $serviceManifestPath4 $serviceManifestDiffPath4 -Force
Assert-WasCalled Copy-Item $codePkg1 $codeDiffPkg1 -Recurse -Times 0
Assert-WasCalled Copy-Item $codePkg2 $codeDiffPkg2 -Recurse
Assert-WasCalled Copy-Item $codePkg3 $codeDiffPkg3 -Recurse -Times 0
Assert-WasCalled Copy-Item $codePkg4 $codeDiffPkg4 -Recurse
Assert-WasCalled Publish-NewServiceFabricApplication -Arguments $publishArgs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="TestType" ApplicationTypeVersion="2.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="Stateless4_InstanceCount" DefaultValue="-1" />
<Parameter Name="Stateless3_InstanceCount" DefaultValue="-1" />
<Parameter Name="Stateless2_InstanceCount" DefaultValue="-1" />
<Parameter Name="Stateless1_InstanceCount" DefaultValue="-1" />
</Parameters>
<!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion
should match the Name and Version attributes of the ServiceManifest element defined in the
ServiceManifest.xml file. -->
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Stateless4Pkg" ServiceManifestVersion="2.0.0" />
<ConfigOverrides />
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Stateless3Pkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Stateless2Pkg" ServiceManifestVersion="2.0.0" />
<ConfigOverrides />
Expand All @@ -21,6 +31,16 @@
ServiceFabric PowerShell module.
The attribute ServiceTypeName below must match the name defined in the imported ServiceManifest.xml file. -->
<Service Name="Stateless4" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="Stateless4Type" InstanceCount="[Stateless4_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
<Service Name="Stateless3" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="Stateless3Type" InstanceCount="[Stateless3_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
<Service Name="Stateless2" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="Stateless2Type" InstanceCount="[Stateless2_InstanceCount]">
<SingletonPartition />
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Binary file not shown.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ServiceManifest Name="Stateless3Pkg" Version="1.0.0">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="Stateless3Type" />
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
</ServiceManifest>
Binary file not shown.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ServiceManifest Name="Stateless4Pkg" Version="2.0.0">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="Stateless4Type" />
</ServiceTypes>
<CodePackage Name="Code" Version="2.0.0">
</CodePackage>
<ConfigPackage Name="Config" Version="2.0.0" />
</ServiceManifest>

0 comments on commit 33fb4d3

Please sign in to comment.