Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
freddydk committed Nov 26, 2023
1 parent 23858e6 commit ab71d75
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
1 change: 0 additions & 1 deletion Actions/BuildReferenceDocumentation/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ runs:
steps:
- name: run
shell: ${{ inputs.shell }}
id: BuildReferenceDocumentation
env:
_token: ${{ inputs.token }}
_artifacts: ${{ inputs.artifacts }}
Expand Down
64 changes: 64 additions & 0 deletions Tests/BuildReferenceDocumentation.Action.Test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Get-Module TestActionsHelper | Remove-Module -Force
Import-Module (Join-Path $PSScriptRoot 'TestActionsHelper.psm1')

Describe "BuildReferenceDocumentation Action Tests" {
BeforeAll {
$actionName = "BuildReferenceDocumentation"
$scriptRoot = Join-Path $PSScriptRoot "..\Actions\$actionName" -Resolve
$scriptName = "$actionName.ps1"
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'scriptPath', Justification = 'False positive.')]
$scriptPath = Join-Path $scriptRoot $scriptName
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'actionScript', Justification = 'False positive.')]
$actionScript = GetActionScript -scriptRoot $scriptRoot -scriptName $scriptName
}

It 'Compile Action' {
Invoke-Expression $actionScript
}

It 'Test action.yaml matches script' {
$permissions = [ordered]@{
}
$outputs = [ordered]@{
}
YamlTest -scriptRoot $scriptRoot -actionName $actionName -actionScript $actionScript -permissions $permissions -outputs $outputs
}

It 'CalculateProjectsAndApps' {
. (Join-Path $scriptRoot 'BuildReferenceDocumentation.HelperFunctions.ps1')

Mock Get-ChildItem {
if ($directory) {
return @(
[PSCustomObject]@{ Name = 'P1-main-Apps-1.0.0.0'; FullName = Join-Path $path 'P1-main-Apps-1.0.0.0' }
[PSCustomObject]@{ Name = 'P2-main-Apps-1.0.0.0'; FullName = Join-Path $path 'P2-main-Apps-1.0.0.0' }
[PSCustomObject]@{ Name = 'P3-main-Apps-1.0.0.0'; FullName = Join-Path $path 'P3-main-Apps-1.0.0.0' }
[PSCustomObject]@{ Name = 'P4-main-Apps-1.0.0.0'; FullName = Join-Path $path 'P4-main-Apps-1.0.0.0' }
)
}
else {
$project = $path.Substring($path.LastIndexOf('\')+1,2)
$noOfApps = [int]$project.substring(1,1)
$apps = @()
for($i=1; $i -le $noOfApps; $i++) {
$apps += [PSCustomObject]@{ FullName = Join-Path $path "$($project)_app$i.app" }
}
return $apps
}
}

$allApps = CalculateProjectsAndApps -tempFolder 'c:\temp' -projects @('P1','P2') -excludeProjects @('P3')
$allApps.Count | Should -Be 2
$allApps[0].Keys.Count | Should -be 1
$allApps[0].ContainsKey('dummy') | Should -be $true
$allApps[0]."dummy".Count | Should -be 3

$allApps = CalculateProjectsAndApps -tempFolder 'c:\temp' -projects @('*') -excludeProjects @('P3') -useProjectsAsFolders
$allApps.Count | Should -Be 2
$allApps[0].Keys.Count | Should -be 3
$allApps[0].ContainsKey('dummy') | Should -be $false
$allApps[0]."P1".Count | Should -be 1
$allApps[0]."P2".Count | Should -be 2
$allApps[0]."P4".Count | Should -be 4
}
}

0 comments on commit ab71d75

Please sign in to comment.