-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathDeploy-Accelerator.Tests.ps1
More file actions
176 lines (154 loc) · 7.57 KB
/
Deploy-Accelerator.Tests.ps1
File metadata and controls
176 lines (154 loc) · 7.57 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = 'ALZ'
$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1")
#-------------------------------------------------------------------------
if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') {
#if the module is already in memory, remove it
Remove-Module -Name $ModuleName -Force
}
Import-Module $PathToManifest -Force
#-------------------------------------------------------------------------
InModuleScope 'ALZ' {
Describe 'Deploy-Accelerator Public Function Tests' -Tag Unit {
BeforeAll {
$WarningPreference = 'SilentlyContinue'
$ErrorActionPreference = 'SilentlyContinue'
}
Context 'Error' {
}
Context 'Success' {
BeforeEach {
Mock -CommandName Set-Config -MockWith {
@(
@{
"description" = "Test configuration 1"
"names" = @("value1", "value2")
"defaultValue" = "default"
"value" = "value"
},
@{
"description" = "Test configuration 2"
"names" = @("value1")
"defaultValue" = "default"
"value" = "value"
}
)
}
Mock -CommandName Test-Tooling
Mock -CommandName Edit-ALZConfigurationFilesInPlace
Mock -CommandName Copy-Item -MockWith { }
Mock -CommandName Get-ALZConfig -MockWith {
@{
"module_url" = "test"
"version" = "v1.0.0"
"deployment_files" = @(
@{
"displayName" = "Management Groups Deployment"
"templateFilePath" = "./infra-as-code/bicep/modules/managementGroups/managementGroupsScopeEscape.bicep"
"templateParametersFilePath" = "./config/custom-parameters/managementGroups.parameters.all.json"
"templateParametersSourceFilePath" = "./infra-as-code/bicep/modules/managementGroups/parameters/managementGroups.parameters.all.json"
"deploymentType" = "managementGroup"
}
)
"config_files" = @(
@{
"source" = "a"
"destination" = "b"
}
)
"cicd" = @{
"azuredevops" = @(
@{
"source" = "a"
"destination" = "b"
}
)
"github" = @(
@{
"source" = "a"
"destination" = "b"
}
)
}
"parameters" = @{
"test" = @{
"type" = "string"
}
}
}
}
Mock -CommandName Get-GithubRelease -MockWith { $("v0.0.1") }
Mock -CommandName Write-InformationColored
Mock -CommandName Get-HCLParserTool -MockWith { "test" }
Mock -CommandName Get-TerraformTool -MockWith { }
Mock -CommandName Convert-HCLVariablesToInputConfig -MockWith {
@(
@{
"description" = "Test configuration 1"
"names" = @("value1", "value2")
"defaultValue" = "default"
"value" = "value"
},
@{
"description" = "Test configuration 2"
"names" = @("value1")
"defaultValue" = "default"
"value" = "value"
}
)
}
Mock -CommandName Invoke-Terraform -MockWith { }
Mock -CommandName Invoke-Upgrade -MockWith { }
Mock -CommandName Invoke-FullUpgrade -MockWith { }
Mock -CommandName Get-TerraformTool -MockWith {}
Mock -CommandName New-FolderStructure -MockWith {}
Mock -CommandName New-ModuleSetup -MockWith {
@{
"version" = "v0.0.1"
"path" = "./example/example"
}
}
Mock -CommandName Get-BootstrapAndStarterConfig -MockWith {
@{
"hasStarterModule" = $true
"validationConfig" = @{
"azure_location" = @{
"AllowedValues" = @{
"Values" = @( "uksouth", "ukwest" )
}
}
}
}
}
Mock -CommandName New-Bootstrap -MockWith {}
Mock -CommandName Get-AzureRegionData -MockWith {
@{
"uksouth" = @{
"display_name" = "UK South"
"zone" = @( "1", "2", "3" )
}
}
}
}
It 'should call the correct functions for bicep module configuration' {
Deploy-Accelerator -i "bicep" -b "github" -inputs "example.yml"
Assert-MockCalled -CommandName Get-BootstrapAndStarterConfig -Exactly 1
Assert-MockCalled -CommandName New-ModuleSetup -Exactly 2
}
It 'should call the correct functions for terraform module configuration' {
Deploy-Accelerator -i "terraform" -b "github" -inputs "example.yml"
Assert-MockCalled -CommandName Get-BootstrapAndStarterConfig -Exactly 1
Assert-MockCalled -CommandName New-Bootstrap -Exactly 1
Assert-MockCalled -CommandName New-ModuleSetup -Exactly 2
}
It 'should call the correct functions for terraform module configuration with generate_only' {
Deploy-Accelerator -i "terraform" -b "github" -inputs "example.yml" -generate_only
Assert-MockCalled -CommandName Get-BootstrapAndStarterConfig -Exactly 1
Assert-MockCalled -CommandName New-Bootstrap -Exactly 1 -ParameterFilter { $generateOnly -eq $true }
Assert-MockCalled -CommandName New-ModuleSetup -Exactly 2
}
}
}
}