Repository navigation
Expand file tree
/
Copy pathTemplates.Tests.ps1
More file actions
44 lines (41 loc) · 2.05 KB
/
Copy pathTemplates.Tests.ps1
File metadata and controls
44 lines (41 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Describe "Verifying templating component" {
BeforeAll {
$outPath = [System.IO.Path]::GetTempPath().Trim("\/")
if ($env:SYSTEM_DEFAULTWORKINGDIRECTORY) { $outPath = $env:SYSTEM_DEFAULTWORKINGDIRECTORY.Trim("\/") }
$resourcePath = Resolve-PSFPath -Path "$PSScriptRoot\..\resources"
$templateName = 'TestTemplate-{0}' -f (Get-Random)
}
AfterAll {
Remove-Item -Path "$outPath\Test.txt" -ErrorAction Ignore
}
It "Should Record the template correctly" {
{ New-PSMDTemplate -TemplateName $templateName -FilePath "$resourcePath\þnameþ.txt" -OutPath $outPath -EnableException -ErrorAction Stop } | Should -Not -Throw
$templateInfo = Get-PSMDTemplate -TemplateName $templateName -Path $outPath
$templateRaw = Import-PSFClixml -Path $templateInfo.Path
try { $template = [PSModuleDevelopment.Template.Template]$templateRaw }
catch {
Write-Warning "Conversion to template Failed!"
Write-Warning "======================================================================="
$_ | Format-List -Force | Out-Host
Write-Warning "======================================================================="
$_.Exception | Format-List -Force | Out-Host
Write-Warning "======================================================================="
throw
}
$template.Name | Should -Be $templateName
$template.Parameters.Count | Should -Be 1
$template.Scripts.Count | Should -Be 1
$template.Scripts.Values.ScriptBlock | Should -BeOfType ([scriptblock])
}
It "Should Invoke the template correctly" {
{ Invoke-PSMDTemplate -TemplateName $templateName -Path $outPath -OutPath $outPath -Name Test -EnableException } | Should -Not -Throw
$content = Get-Content -Path "$outPath\Test.txt" -ErrorAction Stop
$values = $content | ConvertFrom-StringData -ErrorAction Stop
$values.Name | Should -Be Test
$values.Value | Should -Be '123'
}
It "Should Remove the template correctly" {
{ Remove-PSMDTemplate -TemplateName $templateName -EnableException -Confirm:$false } | Should -Not -Throw
Get-PSMDTemplate -TemplateName $templateName | Should -BeNullOrEmpty
}
}