Start-IpsAwsPrepareJob.Tests.ps1
BeforeAll { . $PSScriptRoot\Start-IpsAwsPrepareJob.ps1 . $PSScriptRoot\JobParamMethods.ps1 . $PSScriptRoot\PlatformMethods.ps1 . $PSScriptRoot\PrepareMethods.ps1 . $PSScriptRoot\Auth.ps1 . $PSScriptRoot\Log.ps1 . $PSScriptRoot\VersionCheck.ps1 } Describe 'Test parameter handling' { It 'Test config file' { Mock Add-PSSnapin { } Mock AuthToCitrixCloud {return @{}} Mock VersionCheck { } Mock Invoke-CCRestMethod { $Global:RestBody = $json; $Global:RestQuery = $query } $config = @' { "Deployment": "api.test.layering.cloudburrito.com", "CustomerId": "qvj487ll7e68", "CloudPlatform": "aws", "CloudProvisioningType": "Mcs", "ResourceLocationId": "52509414-3c19-4a8e-a711-01837da5a1c8", "XdReconfigure": [ {"ParameterName": "controllers", "ParameterValue": "cloudy-cc1.wse2edev.cloudy"} ], "AwsRegion": "us-east-2", "AwsTargetSnapshotId": "snap-087af7cd8fdfa545f", "AwsSubnetId": "subnet-0df5f0041b33a47ea", "AwsSecurityGroupIds": ["sg-0e38453a02de64d9d"], "UsePublicIP": true, "CloudCwSecretId": "aws-credential", "DryRun": true } '@ $configFile = New-TemporaryFile $config | Set-Content -Path $configFile.FullName Start-IpsAwsPrepareJob -ConfigJsonFile $configFile.FullName $body = ConvertFrom-Json $restBody Write-Host $restBody $restQuery.dryRun | Should -Be $true $body.securityGroupIds -is [Array] | Should -Be $true $body.securityGroupIds | Should -HaveCount 1 $body.xdReconfigure -is [Array] | Should -Be $true $body.xdReconfigure | Should -HaveCount 1 $body.xdReconfigure[0].ParameterName | Should -Be "controllers" $body.xdReconfigure[0].ParameterValue | Should -Be "cloudy-cc1.wse2edev.cloudy" $tags = Convert-Object $body.tags $tags.Count | Should -Be 1 $tags.ContainsKey("ctx-user") | Should -Be $true } It 'Test config file count 2' { Mock Add-PSSnapin { } Mock AuthToCitrixCloud {return @{}} Mock VersionCheck { } Mock Invoke-CCRestMethod { $Global:RestBody = $json; $Global:RestQuery = $query } $config = @' { "Deployment": "api.test.layering.cloudburrito.com", "CustomerId": "qvj487ll7e68", "CloudPlatform": "aws", "CloudProvisioningType": "Mcs", "ResourceLocationId": "52509414-3c19-4a8e-a711-01837da5a1c8", "XdReconfigure": [ {"ParameterName": "controllers", "ParameterValue": "cloudy-cc1.wse2edev.cloudy"}, {"ParameterName": "portnumber", "ParameterValue": "80"} ], "AwsRegion": "us-east-2", "AwsTargetSnapshotId": "snap-087af7cd8fdfa545f", "AwsSubnetId": "subnet-0df5f0041b33a47ea", "AwsSecurityGroupIds": ["sg-0e38453a02de64d9d", "sg-1fffff3a02de64d9d"], "CloudCwSecretId": "aws-credential", "Tags": {"user": "foo"} } '@ $configFile = New-TemporaryFile $config | Set-Content -Path $configFile.FullName Start-IpsAwsPrepareJob -ConfigJsonFile $configFile.FullName $body = ConvertFrom-Json $restBody Write-Host $restBody $restQuery.dryRun | Should -Be $false $body.xdReconfigure -is [Array] | Should -Be $true $body.xdReconfigure | Should -HaveCount 2 $body.xdReconfigure[0].ParameterName | Should -Be "controllers" $body.xdReconfigure[0].ParameterValue | Should -Be "cloudy-cc1.wse2edev.cloudy" $body.xdReconfigure[1].ParameterName | Should -Be "portnumber" $body.xdReconfigure[1].ParameterValue | Should -Be "80" $body.securityGroupIds -is [Array] | Should -Be $true $body.securityGroupIds | Should -HaveCount 2 $tags = Convert-Object $body.tags $tags.Count | Should -Be 2 $tags.ContainsKey("ctx-user") | Should -Be $true $tags.user | Should -Be "foo" } } |