Tests/Import-TemplateConfiguration.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
gci "$PSScriptRoot\..\*.psm1" | Import-Module  -force

Describe 'Import-TemplateConfiguration' {
    Context 'When configuration has template expansions' {
        $workingFile = "$PSScriptRoot\TestData\temp_template_properties.json"
        $expandedWorkingFile = "$PSScriptRoot\TestData\temp_template_properties.pstemplate_expanded.json"
        $origFile = "$PSScriptRoot\TestData\template_properties.json"
        Copy-Item $origFile $workingFile -force
        Import-TemplateConfiguration -Path $workingFile -DoNotDeleteExpandedConfigFiles 
        $expandedConfig = Get-Content $expandedWorkingFile -Raw
        #Write-Host -ForegroundColor Cyan $expandedConfig
        
        It 'expands all template tokens' {
            $expandedConfig | Should Not Match '\[\[.*?\]\]'          
        }
        
        It 'can evaluate powershell method calls' {
            $conf = $expandedConfig | ConvertFrom-Json
            $conf.OctopusProjectNameSlug | Should Match 'ComponentProjectTemplate'
        }
    }
}