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
18 changes: 18 additions & 0 deletions .github/actions-config/.linkspector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
dirs:
- ./
#baseUrl: https://example.com
# ignorePatterns:
# - pattern: '^https://example.com/skip/.*$'
# - pattern: "^(ftp)://[^\\s/$?#]*\\.[^\\s]*$"
# replacementPatterns:
# - pattern: "(https?://example.com)/(\\w+)/(\\d+)"
# replacement: '$1/id/$3'
# - pattern: "\\[([^\\]]+)\\]\\((https?://example.com)/file\\)"
# replacement: '<a href="$2/file">$1</a>'
aliveStatusCodes:
- 200
- 201
- 204
useGitIgnore: true
modifiedFilesOnly: false
35 changes: 35 additions & 0 deletions .github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
###########################
###########################
## Markdown Linter rules ##
###########################
###########################

# Linter rules doc:
# - https://github.com/DavidAnson/markdownlint
#
# Note:
# To comment out a single error:
# <!-- markdownlint-disable -->
# any violations you want
# <!-- markdownlint-restore -->
#

###############
# Rules by id #
###############
MD004: false # Unordered list style
MD007:
indent: 2 # Unordered list indentation
MD013:
line_length: 900 # Line length 80 is far too short
MD026:
punctuation: ".,;:!。,;:" # List of not allowed
MD029: false # Ordered list item prefix
MD033: false # Allow inline HTML
MD036: false # Emphasis used instead of a heading

#################
# Rules by tags #
#################
blank_lines: false # Disable rules related to blank lines
7 changes: 7 additions & 0 deletions .github/linters/.yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
rules:
line-length:
max: 900
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: false
truthy: disable
7 changes: 7 additions & 0 deletions .github/linters/PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@{

# Disable specific rules by name
ExcludeRules = @(
'PSUseShouldProcessForStateChangingFunctions'
)
}
56 changes: 56 additions & 0 deletions .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
name: Code Review - Linting & Link Checks

on:
Comment thread
jfaurskov marked this conversation as resolved.
pull_request:
branches:
- main
workflow_dispatch: {}

jobs:
lint:
name: Lint code base
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run github/super-linter
uses: super-linter/super-linter@v7.3.0
env:
# Lint all code - disabled in as part of #262
VALIDATE_ALL_CODEBASE: false
# Need to define main branch as default is set to master in super-linter
DEFAULT_BRANCH: main
# Enable setting the status of each individual linter run in the Checks section of a pull request
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# The following linter types will be enabled:
VALIDATE_JSON: true
VALIDATE_MARKDOWN: true
VALIDATE_POWERSHELL: true
VALIDATE_YAML: true
POWERSHELL_CONFIG_FILE: PSScriptAnalyzerSettings.psd1
#VALIDATE_EDITORCONFIG: true
# Disable errors to only generate a report
#DISABLE_ERRORS: true

markdown-link-check:
name: Markdown Link Check
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run linkspector
uses: umbrelladocs/action-linkspector@v1.3.4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review
fail_on_error: true
config_file: ".github/actions-config/.linkspector.yml"
25 changes: 11 additions & 14 deletions 1-Collect/Get-AzureServices.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
BeforeAll {
$scriptPath = "$PSScriptRoot\Get-AzureServices.ps1"
$script:scriptContent = Get-Content $scriptPath -Raw
}

Describe "Get-AzureServices.ps1 Tests" {
Context "Parameter Validation" {
It "Should accept valid scopeType values" {
$validScopes = @('singleSubscription', 'resourceGroup', 'multiSubscription')

# Parse the script to check parameter validation
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'ValidateSet.*singleSubscription.*resourceGroup.*multiSubscription'

# Verify each scope is present in the script's ValidateSet
foreach ($scope in $validScopes) {
$script:scriptContent | Should -Match $scope
}
}

It "Should have required parameters defined" {
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($scriptPath, [ref]$null, [ref]$null)
$params = $scriptAst.FindAll({$args[0] -is [System.Management.Automation.Language.ParameterAst]}, $true)

$paramNames = $params | ForEach-Object { $_.Name.VariablePath.UserPath }
$paramNames | Should -Contain 'scopeType'
$paramNames | Should -Contain 'fullOutputFile'
$paramNames | Should -Contain 'summaryOutputFile'
}

It "Should have default values for output files" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'fullOutputFile.*=.*"resources.json"'
$scriptContent | Should -Match 'summaryOutputFile.*=.*"summary.json"'
$script:scriptContent | Should -Match 'fullOutputFile.*=.*"resources.json"'
$script:scriptContent | Should -Match 'summaryOutputFile.*=.*"summary.json"'
}
}

Context "Function Definitions" {
It "Should define Get-Property function" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'Function Get-Property'
$script:scriptContent | Should -Match 'Function Get-Property'
}

It "Should define Get-SingleData function" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'Function Get-SingleData'
$script:scriptContent | Should -Match 'Function Get-SingleData'
}

It "Should define Get-Method function" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'Function Get-Method'
$script:scriptContent | Should -Match 'Function Get-Method'
}
}

Expand Down
47 changes: 23 additions & 24 deletions 1-Collect/Get-RessourcesFromAM.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
BeforeAll {
$scriptPath = "$PSScriptRoot\Get-RessourcesFromAM.ps1"
$script:scriptContent = Get-Content $scriptPath -Raw
}

Describe "Get-RessourcesFromAM.ps1 Tests" {
Context "Parameter Validation" {
It "Should require filePath parameter" {
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($scriptPath, [ref]$null, [ref]$null)
$params = $scriptAst.FindAll({$args[0] -is [System.Management.Automation.Language.ParameterAst]}, $true)

$params = $scriptAst.FindAll({ $args[0] -is [System.Management.Automation.Language.ParameterAst] }, $true)
$filePathParam = $params | Where-Object { $_.Name.VariablePath.UserPath -eq 'filePath' }
$filePathParam | Should -Not -BeNullOrEmpty

# Check if parameter is mandatory
$isMandatory = $filePathParam.Attributes | Where-Object {
$_.TypeName.Name -eq 'Parameter' -and
$isMandatory = $filePathParam.Attributes | Where-Object {
$_.TypeName.Name -eq 'Parameter' -and
$_.NamedArguments.ArgumentName -contains 'Mandatory'
}
$isMandatory | Should -Not -BeNullOrEmpty
}

It "Should have default output file" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'outputFile.*=.*".*summary\.json"'
}
}

Context "Excel File Processing" {
It "Should check for Excel file existence" {
Mock Test-Path { return $false }

# Test would validate file existence check

$true | Should -Be $true
}

Expand All @@ -44,31 +43,31 @@ Describe "Get-RessourcesFromAM.ps1 Tests" {
It "Should convert Premium disk SKU correctly" {
$testSku = "Premium SSD P30"
$expected = "Premium_LRS"

$result = switch -Wildcard ($testSku) {
"PremiumV2*" { "PremiumV2_LRS"; break }
"Premium*" { "Premium_LRS"; break }
"StandardSSD*" { "StandardSSD_LRS"; break }
"Standard*" { "Standard_LRS"; break }
"Ultra*" { "UltraSSD_LRS"; break }
default { "Unknown" }
"PremiumV2*" { "PremiumV2_LRS"; break }
"Premium*" { "Premium_LRS"; break }
"StandardSSD*" { "StandardSSD_LRS"; break }
"Standard*" { "Standard_LRS"; break }
"Ultra*" { "UltraSSD_LRS"; break }
default { "Unknown" }
}

$result | Should -Be $expected
}

It "Should convert StandardSSD disk SKU correctly" {
$testSku = "StandardSSD E10"

$result = switch -Wildcard ($testSku) {
"PremiumV2*" { "PremiumV2_LRS"; break }
"Premium*" { "Premium_LRS"; break }
"StandardSSD*" { "StandardSSD_LRS"; break }
"Standard*" { "Standard_LRS"; break }
"Ultra*" { "UltraSSD_LRS"; break }
default { "Unknown" }
"PremiumV2*" { "PremiumV2_LRS"; break }
"Premium*" { "Premium_LRS"; break }
"StandardSSD*" { "StandardSSD_LRS"; break }
"Standard*" { "Standard_LRS"; break }
"Ultra*" { "UltraSSD_LRS"; break }
default { "Unknown" }
}

$result | Should -Be "StandardSSD_LRS"
}
}
Expand Down
11 changes: 2 additions & 9 deletions 2-AvailabilityCheck/Get-AvailabilityInformation.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,48 +1,41 @@
BeforeAll {
$scriptPath = "$PSScriptRoot\Get-AvailabilityInformation.ps1"
$script:scriptContent = Get-Content $scriptPath -Raw
}

Describe "Get-AvailabilityInformation.ps1 Tests" {
Context "Function Definitions" {
It "Should define Out-JSONFile function" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'function Out-JSONFile'
}

It "Should define Convert-LocationsToRegionCodes function" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'Function Convert-LocationsToRegionCodes'
$scriptContent | Should -Match 'Function Convert-LocationsToRegionCode'
}

It "Should define Import-Provider function" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'Function Import-Provider'
}

It "Should define Import-Region function" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'function Import-Region'
}

It "Should define Get-Property function" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'Function Get-Property'
}

It "Should define Expand-NestedCollection function" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'Function Expand-NestedCollection'
}
}

Context "Logic Validation" {
It "Should have region map creation logic" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'RegionMap'
}

It "Should have SKU availability checking logic" {
$scriptContent = Get-Content $scriptPath -Raw
$scriptContent | Should -Match 'available'
}
}
Expand Down
Loading
Loading