Start-IpsGcpPrepareJob.Tests.ps1

BeforeAll {
    . $PSScriptRoot\Start-IpsGcpPrepareJob.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": "wse2edev",
    "Prefix": "ips",
    "CloudPlatform": "gcp",
    "CloudCwSecretId": "nightly-gcp-1",
    "CloudProvisioningType": "Mcs",
    "CloudDiskName": "nightly-mia-win10",
    "OutputDiskName": "nightly-mia-win10-out",
    "XdReconfigure": [
        {"ParameterName": "controllers", "ParameterValue": "cloudy-cc1.wse2edev.cloudy"},
        {"ParameterName": "portnumber", "ParameterValue": "80"}
    ],
    "ResourceLocationId": "52509414-3c19-4a8e-a711-01837da5a1c8",
    "GcpZone": "us-east4-a",
    "VpcNetworkName": "cloudy-ce",
    "VpcNetworkSubnetName": "regions/us-east4/subnetworks/cloudy-ce-us-east4",
    "NetworkTags": ["cloudy"],
    "Tags": {"test": "abcdef"}
}
'@

        $configFile = New-TemporaryFile
        $config | Set-Content -Path $configFile.FullName

        Start-IpsGcpPrepareJob -ConfigJsonFile $configFile.FullName

        $body = ConvertFrom-Json $restBody
        Write-Host $restBody

        $restQuery.dryRun | Should -Be $False

        $body.prefix | Should -Be "ips"
        $body.provisioningType | Should -Be "Mcs"
        $body.platformCredentialId | Should -Be "nightly-gcp-1"
        $body.resourceLocationId | Should -Be "52509414-3c19-4a8e-a711-01837da5a1c8"
        $body.targetImageName | Should -Be "nightly-mia-win10"
        $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.networkTags -is [Array] | Should -Be $true
        $body.networkTags | Should -HaveCount 1
        $body.networkTags[0] | Should -Be "cloudy"

        $tags = Convert-Object $body.tags
        $tags.Count | Should -Be 2
        $tags.ContainsKey("ctx-user") | Should -Be $true
        $tags.test | Should -Be "abcdef"
    }

    It 'Test splat' {
        Mock Add-PSSnapin { }
        Mock AuthToCitrixCloud {return @{}}
        Mock VersionCheck { }
        Mock Invoke-CCRestMethod { $Global:RestBody = $json; $Global:RestQuery = $query }
        $prepareParams = @{
            Deployment = 'api.us.test.layering.cloudburrito.com'
            CustomerId = 'qvj487ll7e68'
            ResourceLocationId = '52509414-3c19-4a8e-a711-01837da5a1c8'
            CloudProvisioningType = 'Mcs'
            CloudDiskName = 'nightly-mia-win10'
            GcpCwSecretId = 'nightly-gcp-1'
            GcpZone = 'us-east4-a'
            VpcNetworkName = "cloudy-ce"
            VpcNetworkSubnetName = "regions/us-east4/subnetworks/cloudy-ce-us-east4"
            XdReconfigure = @(
                @{ParameterName = "controllers"; ParameterValue = "cloudy-cc1.wse2edev.cloudy"}
            )
            NetworkTags = @("cloudy")
            Tags = @{ test = "abcdef" }
        }

        Start-IpsGcpPrepareJob @prepareParams -Force -DryRun $true

        $body = ConvertFrom-Json $restBody

        Write-Host $restBody

        $restQuery.dryRun | Should -Be $true

        $body.provisioningType | Should -Be "Mcs"
        $body.platformCredentialId | Should -Be "nightly-gcp-1"
        $body.targetImageName | Should -Be "nightly-mia-win10"
        $body.resourceLocationId | Should -Be "52509414-3c19-4a8e-a711-01837da5a1c8"
        $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"
        $body.networkTags -is [Array] | Should -Be $true
        $body.networkTags | Should -HaveCount 1
        $body.networkTags[0] | Should -Be "cloudy"

        $tags = Convert-Object $body.tags
        $tags.Count | Should -Be 2
        $tags.ContainsKey("ctx-user") | Should -Be $true
        $tags.test | Should -Be "abcdef"
    }
}