Start-IpsGcpExportJob.Tests.ps1

BeforeAll {
    . $PSScriptRoot\Start-IpsGcpExportJob.ps1
    . $PSScriptRoot\JobParamMethods.ps1
    . $PSScriptRoot\PlatformMethods.ps1
    . $PSScriptRoot\ExportMethods.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",
    "CloudPlatform": "gcp",
    "PublishResourceLocationId": "52509414-3c19-4a8e-a711-01837da5a1c8",
    "PublishSmb": {
        "Host": "10.0.1.212",
        "Share": "Files",
        "DiskName": "nightly-mia",
        "DiskFormat": "VhdxDiskFormat",
        "CwId": "test-cloudy"
    },
    "CloudCwSecretId": "nightly-gcp-1",
    "GcpZone": "us-east4-a",
    "VpcNetworkName": "cloudy-ce",
    "VpcNetworkSubnetName": "regions/us-east4/subnetworks/cloudy-ce-us-east4",
    "NetworkTags": ["cloudy"],
    "CloudDiskName": "nightly-mia-win10",
    "OutputDiskName": "nightly-mia-win10-out"
}
'@

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

        Start-IpsGcpExportJob -ConfigJsonFile $configFile.FullName

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

        $restQuery.dryRun | Should -Be $false

        $body.platformCredentialId | Should -Be "nightly-gcp-1"
        $body.resourceLocationId | Should -Be "52509414-3c19-4a8e-a711-01837da5a1c8"
        $body.targetDiskName | Should -Be "nightly-mia-win10"
        $body.outputImageFilename | Should -Be "nightly-mia"
        $body.outputStorageLocation.location | Should -Be "smb://10.0.1.212/Files/"
        $body.outputStorageLocation.credentialId | Should -Be "test-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 1
        $tags.ContainsKey("ctx-user") | Should -Be $true
    }
}