Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Automation] Fix the issue for string value #14346

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update test case and fix issue for int
  • Loading branch information
wyunchi-ms committed Feb 26, 2021
commit 6cd00182f26ea0224cd726414195f88118cbac10
35 changes: 31 additions & 4 deletions src/Automation/Automation.Test/ScenarioTests/VariableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,27 @@ public VariableTests(Xunit.Abstractions.ITestOutputHelper output)
[Trait(Category.Service, Category.Automation)]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.BVT)]
public void TestE2EVariableAsset()
public void TestStringVariable()
{
TestRunner.RunTestScript("Test-E2EVariableAsset");
TestRunner.RunTestScript("Test-StringVariable");
}

[Fact]
[Trait(Category.Service, Category.Automation)]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.BVT)]
public void TestIntVariable()
{
TestRunner.RunTestScript("Test-IntVariable");
}

[Fact]
[Trait(Category.Service, Category.Automation)]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.BVT)]
public void TestFloatVariable()
{
TestRunner.RunTestScript("Test-FloatVariable");
}

[Fact]
Expand All @@ -55,9 +73,18 @@ public void TestNormalHashTableVariable()
[Trait(Category.Service, Category.Automation)]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.BVT)]
public void TestJsonInValueVariable()
public void TestMultiLevelDictVariable()
{
TestRunner.RunTestScript("Test-MultiLevelDictVariable");
}

[Fact]
[Trait(Category.Service, Category.Automation)]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.BVT)]
public void TestJsonInDictValueVariable()
{
TestRunner.RunTestScript("Test-JsonInValueVariable");
TestRunner.RunTestScript("Test-JsonInDictValueVariable");
}
}
}
155 changes: 150 additions & 5 deletions src/Automation/Automation.Test/ScenarioTests/VariableTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
.SYNOPSIS
Tests create new automation variable with string value.
#>
function Test-E2EVariableAsset
function Test-StringVariable
{
$resourceGroupName = "wyunchi-automation"
$automationAccountName = "test-automation-0"
$output = Get-AzAutomationAccount -ResourceGroupName $resourceGroupName -AutomationAccountName $automationAccountName -ErrorAction SilentlyContinue
$variableName = "CreateNewVariableWithValue"
$variableName = "StringValue"
$variableValue = "StringValue"
$variableValueUpdated = "StringValueChanged"

Expand Down Expand Up @@ -60,6 +60,103 @@ function Test-E2EVariableAsset

Assert-True {$output -eq $null}
}

<#
.SYNOPSIS
Tests create new automation variable with string value.
#>
function Test-IntVariable
{
$resourceGroupName = "wyunchi-automation"
$automationAccountName = "test-automation-0"
$output = Get-AzAutomationAccount -ResourceGroupName $resourceGroupName -AutomationAccountName $automationAccountName -ErrorAction SilentlyContinue
$variableName = "CreateNewVariableWithValue"
$variableValue = 1
$variableValueUpdated = 2

$variableCreated = New-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName `
-value $variableValue `
-Encrypted:$false `
-Description "Hello"

$getVariable = Get-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName

Assert-AreEqual "Hello" $getVariable.Description

Set-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-Name $variableName `
-Encrypted:$false `
-value $variableValueUpdated

$getVariable = Get-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName

Assert-AreEqual $variableValueUpdated $getVariable.value

Remove-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-Name $variableName

$output = Get-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName -ErrorAction SilentlyContinue

Assert-True {$output -eq $null}
}

<#
.SYNOPSIS
Tests create new automation variable with string value.
#>
function Test-FloatVariable
{
$resourceGroupName = "wyunchi-automation"
$automationAccountName = "test-automation-0"
$output = Get-AzAutomationAccount -ResourceGroupName $resourceGroupName -AutomationAccountName $automationAccountName -ErrorAction SilentlyContinue
$variableName = "NewFloatVariable"
$variableValue = 1.1
$variableValueUpdated = 2.2

$variableCreated = New-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName `
-value $variableValue `
-Encrypted:$false `
-Description "float"
Assert-AreEqual ($variableValue | ConvertTo-Json) $variableCreated.value.toString()

$getVariable = Get-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName

Set-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-Name $variableName `
-Encrypted:$false `
-value $variableValueUpdated

$getVariable = Get-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName

Assert-AreEqual ($variableValueUpdated | ConvertTo-Json) $getVariable.value.toString()

Remove-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-Name $variableName

$output = Get-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName -ErrorAction SilentlyContinue

Assert-True {$output -eq $null}
}

<#
.SYNOPSIS
Expand Down Expand Up @@ -161,12 +258,12 @@ function Test-NormalHashTableVariable
.SYNOPSIS
Tests create new automation variable with multi level dict.
#>
function Test-JsonInValueVariable
function Test-MultiLevelDictVariable
{
$resourceGroupName = "wyunchi-automation"
$automationAccountName = "test-automation-0"
$output = Get-AzAutomationAccount -ResourceGroupName $resourceGroupName -AutomationAccountName $automationAccountName -ErrorAction SilentlyContinue
$variableName = "JsonInValueVariable"
$variableName = "MultiLevelDict"
$variableValue = @{"key0" = @{"subkey" = "subvalue"}}
$variableValueUpdated = @{"key0" = @{"subkey" = @{"3rdkey" = "3rd-value"}}}

Expand All @@ -175,7 +272,55 @@ function Test-JsonInValueVariable
-name $variableName `
-value $variableValue `
-Encrypted:$false `
-Description "JsonInValueVariable"
-Description "MultiLevelDict"
Assert-AreEqual ($variableValue | ConvertTo-Json) $variableCreated.value.toString()

$getVariable = Get-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName

Set-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-Name $variableName `
-Encrypted:$false `
-value $variableValueUpdated

$getVariable = Get-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName

Assert-AreEqual ($variableValueUpdated | ConvertTo-Json) $getVariable.value.toString()

Remove-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-Name $variableName

$output = Get-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName -ErrorAction SilentlyContinue

Assert-True {$output -eq $null}
}

<#
.SYNOPSIS
Tests create new automation variable with multi level dict.
#>
function Test-JsonInDictValueVariable
{
$resourceGroupName = "wyunchi-automation"
$automationAccountName = "test-automation-0"
$output = Get-AzAutomationAccount -ResourceGroupName $resourceGroupName -AutomationAccountName $automationAccountName -ErrorAction SilentlyContinue
$variableName = "JsonInDictValue"
$variableValue = @{"key0" = "{`"subkey`" = `"sub-value`"}"}
$variableValueUpdated = @{"key0" = "{`"subkey`" = `"0`"}"}

$variableCreated = New-AzAutomationVariable -ResourceGroupName $resourceGroupName `
-AutomationAccountName $automationAccountName `
-name $variableName `
-value $variableValue `
-Encrypted:$false `
-Description "JsonInDictValue"
Assert-AreEqual ($variableValue | ConvertTo-Json) $variableCreated.value.toString()

$getVariable = Get-AzAutomationVariable -ResourceGroupName $resourceGroupName `
Expand Down
Loading