Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests\TestVirtualMachineWithVMAgentAutoUpdate.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests\TestVMImageCmdletOutputFormat.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VMDynamicTests\RunVMDynamicTests.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,25 @@ function Get-ComputeTestMode
return $testMode;
}


<#
.SYNOPSIS
Get Compute Test Location
#>
function Get-ComputTestLocation
# Get Compute Test Location
function Get-ComputeTestLocation
{
return $env:AZURE_COMPUTE_TEST_LOCATION;
}

# Cleans the created resource group
function Clean-ResourceGroup($rgname)
{
Remove-AzureResourceGroup -Name $rgname -Force;
}

# Get Compute Test Tag
function Get-ComputeTestTag
{
param ([string] $tagname)

return @{ Name = $tagname; Value = (Get-Date).ToUniversalTime().ToString("u") };
}

######################
#
Expand Down Expand Up @@ -156,11 +165,11 @@ Gets random resource name
#>
function Get-RandomItemName
{
param([string] $prefix = "pslibtest")
param([string] $prefix = "crptestps")

if ($prefix -eq $null -or $prefix -eq '')
{
$prefix = "pslibtest";
$prefix = "crptestps";
}

$str = $prefix + ((Get-Random) % 10000);
Expand Down Expand Up @@ -284,9 +293,37 @@ function Get-DefaultVMConfig

# VM Profile & Hardware
$vmsize = Get-DefaultVMSize $location;
$vmname = Get-RandomItemName 'pstestvm';
$vmname = Get-RandomItemName 'crptestps';

$vm = New-AzureVMConfig -VMName $vmname -VMSize $vmsize;

return $vm;
}
}

# Assert Output Contains
function Assert-OutputContains
{
param([string] $cmd, [string[]] $sstr)

$st = Write-Verbose ('Running Command : ' + $cmd);
$output = Invoke-Expression $cmd | Out-String;

$max_output_len = 1500;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just an arbitrary number? Can you add comment about why you choose this number for max_output_len?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is for logging, and it doesn't help if the log is too long.

if ($output.Length -gt $max_output_len)
{
# Truncate Long Output in Logs
$st = Write-Verbose ('Output String : ' + $output.Substring(0, $max_output_len) + '...');
}
else
{
$st = Write-Verbose ('Output String : ' + $output);
}

$index = 1;
foreach ($str in $sstr)
{
$st = Write-Verbose ('Search String ' + $index++ + " : `'" + $str + "`'");
Assert-True { $output.Contains($str) }
$st = Write-Verbose "Found.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function Run-VMDynamicTests
{
param ([int] $num_total_generated_tests = 3, [string] $base_folder = '.\ScenarioTests\Generated')

$target_location = Get-ComputTestLocation;
$target_location = Get-ComputeTestLocation;

$st = Write-Verbose 'Running VM Dynamic Tests - Start';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,12 @@ public void TestVirtualMachineTags()
{
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineTags");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVMImageCmdletOutputFormat()
{
ComputeTestController.NewInstance.RunPsTest("Test-VMImageCmdletOutputFormat");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1281,3 +1281,27 @@ function Test-LinuxVirtualMachine
Clean-ResourceGroup $rgname
}
}

# Test Image Cmdlet Output Format
function Test-VMImageCmdletOutputFormat
{
$locStr = 'westus';
$publisher = 'MicrosoftWindowsServer';
$offer = 'WindowsServer';
$sku = '2008-R2-SP1';
$ver = '2.0.201503';

Assert-OutputContains " Get-AzureVMImagePublisher -Location $locStr" @('Id', 'Location', 'PublisherName');

Assert-OutputContains " Get-AzureVMImagePublisher -Location $locStr | ? { `$_.PublisherName -eq `'$publisher`' } " @('Id', 'Location', 'PublisherName');

Assert-OutputContains " Get-AzureVMImagePublisher -Location $locStr | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzureVMImageOffer " @('Id', 'Location', 'PublisherName', 'Offer');

Assert-OutputContains " Get-AzureVMImagePublisher -Location $locStr | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzureVMImageOffer | Get-AzureVMImageSku " @('Id', 'Location', 'PublisherName', 'Offer', 'Sku');

Assert-OutputContains " Get-AzureVMImagePublisher -Location $locStr | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzureVMImageOffer | Get-AzureVMImageSku | Get-AzureVMImage " @('Id', 'Location', 'PublisherName', 'Offer', 'Sku', 'Version', 'FilterExpression');

Assert-OutputContains " Get-AzureVMImage -Location $locStr -PublisherName $publisher -Offer $offer -Skus $sku -Version $ver " @('Id', 'Location', 'PublisherName', 'Offer', 'Sku', 'Version', 'FilterExpression', 'Name', 'DataDiskImages', 'OSDiskImage', 'PurchasePlan');

Assert-OutputContains " Get-AzureVMImageDetail -Location $locStr -PublisherName $publisher -Offer $offer -Skus $sku -Version $ver " @('Id', 'Location', 'PublisherName', 'Offer', 'Sku', 'Version', 'FilterExpression', 'Name', 'DataDiskImages', 'OSDiskImage', 'PurchasePlan');
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet(VerbsCommon.Get,
ProfileNouns.VirtualMachineExtensionImage)]
[Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineExtensionImage)]
[OutputType(typeof(PSVirtualMachineExtensionImage))]
[OutputType(typeof(PSVirtualMachineExtensionImageDetails))]
public class GetAzureVMExtensionImageCommand : VirtualMachineExtensionImageBaseCmdlet
{
Expand Down Expand Up @@ -92,15 +92,15 @@ public override void ExecuteCmdlet()
StatusCode = result.StatusCode,
Id = result.VirtualMachineExtensionImage.Id,
Location = result.VirtualMachineExtensionImage.Location,
Name = result.VirtualMachineExtensionImage.Name,
HandlerSchema = result.VirtualMachineExtensionImage.HandlerSchema,
OperatingSystem = result.VirtualMachineExtensionImage.OperatingSystem,
ComputeRole = result.VirtualMachineExtensionImage.ComputeRole,
SupportsMultipleExtensions = result.VirtualMachineExtensionImage.SupportsMultipleExtensions,
VMScaleSetEnabled = result.VirtualMachineExtensionImage.VMScaleSetEnabled,
Version = result.VirtualMachineExtensionImage.Name,
PublisherName = this.PublisherName,
Type = this.Type,
Version = this.Version
FilterExpression = this.FilterExpression
};

WriteObject(image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineExtensionImageType)]
[OutputType(typeof(PSVirtualMachineExtensionImage))]
[OutputType(typeof(PSVirtualMachineExtensionImageType))]
public class GetAzureVMExtensionImageTypeCommand : VirtualMachineExtensionImageBaseCmdlet
{
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
Expand All @@ -44,7 +44,7 @@ public override void ExecuteCmdlet()
VirtualMachineImageResourceList result = this.VirtualMachineExtensionImageClient.ListTypes(parameters);

var images = from r in result.Resources
select new PSVirtualMachineExtensionImage
select new PSVirtualMachineExtensionImageType
{
RequestId = result.RequestId,
StatusCode = result.StatusCode,
Expand Down
Loading