Skip to content

Commit

Permalink
Merge pull request #34 from sam-cogan/samcogan/ttk-update
Browse files Browse the repository at this point in the history
update ttk to 0.25
fixes #33
  • Loading branch information
sam-cogan authored Nov 9, 2024
2 parents 4550243 + 67ff47f commit 7ea3bd4
Show file tree
Hide file tree
Showing 21 changed files with 42,576 additions and 11,427 deletions.
3 changes: 2 additions & 1 deletion Tests/testfiles/bicep/sql.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ resource server 'Microsoft.Sql/servers@2019-06-01-preview' = {
}

resource sqlDB 'Microsoft.Sql/servers/databases@2020-08-01-preview' = {
name: '${server.name}/${sqlDBName}'
name: sqlDBName
parent: server
location: location
sku: {
name: 'Standard'
Expand Down
9 changes: 7 additions & 2 deletions Tests/testfiles/bicep/storage.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ resource sa 'Microsoft.Storage/storageAccounts@2019-06-01' = {
location: location
sku: {
name: 'Standard_LRS'
tier: 'Standard'
}
kind: 'StorageV2'
properties: {
accessTier: 'Hot'
}
}

resource blobService 'Microsoft.Storage/storageAccounts/blobServices@2019-06-01' = {
name: 'default'
parent: sa
}

resource container 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${sa.name}/default/${containerName}'
name: containerName
parent: blobService
}
4 changes: 2 additions & 2 deletions Tests/testfiles/mainTemplate/newStorageAccount.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"type": "String"
"type": "string"
},
"storageAccountType": {
"type": "string",
Expand All @@ -27,7 +27,7 @@
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[parameters('StorageAccountName')]",
"apiVersion": "2022-09-01",
"apiVersion": "2023-05-01",
"location": "[parameters('location')]",
"properties": {
"accountType": "[parameters('storageAccountType')]"
Expand Down
Binary file added arm-ttk-extension-xplatform/arm-ttk/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion arm-ttk-extension-xplatform/arm-ttk/ConvertFrom-JSON.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ process

# First, strip block comments
$inObj = $_
$in = if ($InputObject.Contains('*/')) {
$in = if ($InputObject.Contains('*/') -and $InputObject.Contains('/*')) {
$JSONBlockComments.Replace($inObj,'')
} else {
$InputObject
Expand Down
2 changes: 1 addition & 1 deletion arm-ttk-extension-xplatform/arm-ttk/Expand-AzTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function Expand-AzTemplate
$preferredJsonFile = $TemplatePath |
Get-ChildItem -Filter *.json |
# for a file named azuredeploy.json, prereq.azuredeploy.json or mainTemplate.json
#Where-Object { 'azuredeploy.json', 'mainTemplate.json', 'prereq.azuredeploy.json' -contains $_.Name } |
# Where-Object { 'azuredeploy.json', 'mainTemplate.json', 'prereq.azuredeploy.json' -contains $_.Name } |
Select-Object -First 1 -ExpandProperty Fullname
# If no file was found, write an error and return.
if (-not $preferredJsonFile) {
Expand Down
55 changes: 55 additions & 0 deletions arm-ttk-extension-xplatform/arm-ttk/Format-Json.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Function Format-Json {
<#
.SYNOPSIS
Takes results from ARMTTK and exports them as a JSON blob.
.DESCRIPTION
Takes results from ARMTTK and exports them as JSON. The test cases include the filename, name of the test,
whether the test was successful, and help text for how to resolve the error if the test failed.
#>
[CmdletBinding()]
Param (
# Object containing a single test result or an array of test results
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[psobject]$TestResult
)

Begin {
# Initialize the array to collect processed test cases
$TestCases = @()
}

Process {
# Process each TestResult item one by one as they come from the pipeline
$TestCase = @{
filepath = $TestResult.file.fullpath
name = $TestResult.name
success = $TestResult.Passed
}

if ($TestResult.Passed) {
$TestCase.optional = $false
}
elseif ($null -ne $($TestResult.Warnings)) {
$TestCase.optional = $true
$TestCase.message = "$($TestResult.Warnings.Message.Replace('"', '\"')) in template file $($TestResult.file.name)"
}
elseif ($null -ne $($TestResult.Errors)) {
$TestCase.optional = $false
$TestCase.message = "$($TestResult.Errors.Exception.Message.Replace('"', '\"')) in template file $($TestResult.file.name)"
}
else {
$TestCase.optional = $true
$TestCase.message = "Unknown error in template file " + $TestResult.file.name
}

$TestCases += $TestCase
}

End {
# Convert the array of hashtables to JSON
$JSON = $TestCases | ConvertTo-Json

# Print the JSON string to the console
Write-Output $JSON
}
}
Binary file not shown.
9 changes: 8 additions & 1 deletion arm-ttk-extension-xplatform/arm-ttk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ This will run the full suite of applicable tests on your template. To run a spe
You can also skip tests any tests:

Test-AzTemplate -TemplatePath $thePathToYourTemplate -Skip apiVersions-Should-Be-Recent
# This will exclude the tests indicated by the -Skip parameter from the test run and results
# This will exclude the tests indicated by the -Skip parameter from the test run and results

You can also change the output format to get detailed test result descriptions in JSON:

Test-AzTemplate -TemplatePath $thePathToYourTemplate | Format-Json
# This will output the test results from Test-AzTemplate to the console in JSON format
Test-AzMarketplacePackage -TemplatePath $thePathToYourTemplate | Format-Json
# This will output the test results from AzMarketplacePackage to the console in JSON format

## Running Tests on Linux

Expand Down
Binary file not shown.
6 changes: 3 additions & 3 deletions arm-ttk-extension-xplatform/arm-ttk/Test-AzTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,9 @@ Each test script has access to a set of well-known variables:
# attempt to find one in the current directory and it's subdirectories
$possibleJsonFiles = @(Get-ChildItem -Filter *.json -Recurse |
Sort-Object Name -Descending) # | # (sort by name descending so that MainTemplate.json comes first).
# Where-Object {
# 'azureDeploy.json', 'mainTemplate.json' -contains $_.Name
# })
#Where-Object {
# 'azureDeploy.json', 'mainTemplate.json' -contains $_.Name
#})


# If more than one template was found, warn which one we'll be testing.
Expand Down
Empty file modified arm-ttk-extension-xplatform/arm-ttk/Test-AzTemplate.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion arm-ttk-extension-xplatform/arm-ttk/arm-ttk.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = 0.23
ModuleVersion = 0.25
ModuleToProcess = 'arm-ttk.psm1'
Description = 'Validation tools for Azure Resource Manager Templates'
FormatsToProcess = 'arm-ttk.format.ps1xml'
Expand Down
3 changes: 2 additions & 1 deletion arm-ttk-extension-xplatform/arm-ttk/arm-ttk.psm1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#region JSON Functions
if ($PSVersionTable.PSEdition -ne 'Core') {
#powershell 6+ provides support for json with comments
if ($PSVersionTable.PSVersion.Major -lt 6) {
. $psScriptRoot\ConvertFrom-Json.ps1 # Overwriting ConvertFrom-JSON to allow for comments within JSON (not on core)
}

Expand Down
Loading

0 comments on commit 7ea3bd4

Please sign in to comment.