2023-09-05 11:40:42 +03:00
|
|
|
|
Get-Module TestActionsHelper | Remove-Module -Force
|
2023-02-13 15:32:16 +03:00
|
|
|
|
Import-Module (Join-Path $PSScriptRoot 'TestActionsHelper.psm1')
|
2024-05-14 10:27:47 +03:00
|
|
|
|
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
|
2023-02-13 15:32:16 +03:00
|
|
|
|
|
|
|
|
|
Describe 'VerifyPRChanges Action Tests' {
|
|
|
|
|
|
|
|
|
|
BeforeAll {
|
|
|
|
|
$actionName = "VerifyPRChanges"
|
|
|
|
|
$scriptRoot = Join-Path $PSScriptRoot "..\Actions\$actionName" -Resolve
|
|
|
|
|
$scriptName = "$actionName.ps1"
|
2023-09-05 11:40:42 +03:00
|
|
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'scriptPath', Justification = 'False positive.')]
|
2023-02-13 15:32:16 +03:00
|
|
|
|
$scriptPath = Join-Path $scriptRoot $scriptName
|
2023-09-05 11:40:42 +03:00
|
|
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'actionScript', Justification = 'False positive.')]
|
2023-02-13 15:32:16 +03:00
|
|
|
|
$actionScript = GetActionScript -scriptRoot $scriptRoot -scriptName $scriptName
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'should fail if the PR is from a fork and changes a script' {
|
2024-04-13 13:13:16 +03:00
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '{ "changed_files": 1 }' } } -ParameterFilter { $Uri -and $Uri -notmatch "/files"}
|
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '[{"filename": "Scripts/BuildScript.ps1", "status": "modified"}]' } } -ParameterFilter { $Uri -and $Uri -match "/files"}
|
2023-07-20 18:13:14 +03:00
|
|
|
|
|
2023-09-05 11:40:42 +03:00
|
|
|
|
{
|
2023-02-13 15:32:16 +03:00
|
|
|
|
& $scriptPath `
|
|
|
|
|
-prBaseRepository "microsoft/AL-Go" `
|
2023-07-20 18:13:14 +03:00
|
|
|
|
-pullRequestId "123456" `
|
2023-09-05 11:40:42 +03:00
|
|
|
|
-token "ABC"
|
2023-02-13 15:32:16 +03:00
|
|
|
|
} | Should -Throw
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'should fail if the PR is from a fork and adds a script' {
|
2024-04-13 13:13:16 +03:00
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '{ "changed_files": 1 }' } } -ParameterFilter { $Uri -and $Uri -notmatch "/files"}
|
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '[{"filename":"Scripts/BuildScript.ps1", "status": "added"}]' } } -ParameterFilter { $Uri -and $Uri -match "/files"}
|
2023-07-20 18:13:14 +03:00
|
|
|
|
|
2023-09-05 11:40:42 +03:00
|
|
|
|
{
|
2023-02-13 15:32:16 +03:00
|
|
|
|
& $scriptPath `
|
|
|
|
|
-prBaseRepository "microsoft/AL-Go" `
|
2023-07-20 18:13:14 +03:00
|
|
|
|
-pullRequestId "123456" `
|
2023-09-05 11:40:42 +03:00
|
|
|
|
-token "ABC"
|
2023-02-13 15:32:16 +03:00
|
|
|
|
} | Should -Throw
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'should fail if the PR is from a fork and removes a script' {
|
2024-04-13 13:13:16 +03:00
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '{ "changed_files": 1 }' } } -ParameterFilter { $Uri -and $Uri -notmatch "/files"}
|
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '[{"filename":"Scripts/BuildScript.ps1","status":"removed"}]' } } -ParameterFilter { $Uri -and $Uri -match "/files"}
|
2023-07-20 18:13:14 +03:00
|
|
|
|
|
2023-09-05 11:40:42 +03:00
|
|
|
|
{
|
2023-02-13 15:32:16 +03:00
|
|
|
|
& $scriptPath `
|
|
|
|
|
-prBaseRepository "microsoft/AL-Go" `
|
2023-07-20 18:13:14 +03:00
|
|
|
|
-pullRequestId "123456" `
|
2023-09-05 11:40:42 +03:00
|
|
|
|
-token "ABC"
|
2023-02-13 15:32:16 +03:00
|
|
|
|
} | Should -Throw
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'should fail if the PR is from a fork and changes the CODEOWNERS file' {
|
2024-04-13 13:13:16 +03:00
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '{ "changed_files": 1 }' } } -ParameterFilter { $Uri -and $Uri -notmatch "/files"}
|
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '[{"filename":"CODEOWNERS","status":"modified"}]' } } -ParameterFilter { $Uri -and $Uri -match "/files"}
|
2023-07-20 18:13:14 +03:00
|
|
|
|
|
2023-09-05 11:40:42 +03:00
|
|
|
|
{
|
2023-02-13 15:32:16 +03:00
|
|
|
|
& $scriptPath `
|
|
|
|
|
-prBaseRepository "microsoft/AL-Go" `
|
2023-07-20 18:13:14 +03:00
|
|
|
|
-pullRequestId "123456" `
|
2023-09-05 11:40:42 +03:00
|
|
|
|
-token "ABC"
|
2023-02-13 15:32:16 +03:00
|
|
|
|
} | Should -Throw
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'should fail if the PR is from a fork and changes anything in the .github folder' {
|
2024-04-13 13:13:16 +03:00
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '{ "changed_files": 1 }' } } -ParameterFilter { $Uri -and $Uri -notmatch "/files"}
|
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '[{"filename":".github/Settings.json","status":"modified"}]' } } -ParameterFilter { $Uri -and $Uri -match "/files"}
|
2023-07-20 18:13:14 +03:00
|
|
|
|
|
2023-09-05 11:40:42 +03:00
|
|
|
|
{
|
2023-07-20 18:13:14 +03:00
|
|
|
|
& $scriptPath `
|
|
|
|
|
-prBaseRepository "microsoft/AL-Go" `
|
|
|
|
|
-pullRequestId "123456" `
|
2023-09-05 11:40:42 +03:00
|
|
|
|
-token "ABC"
|
2023-07-20 18:13:14 +03:00
|
|
|
|
} | Should -Throw
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'should fail if the PR is from a fork and changes a yml file' {
|
2024-04-13 13:13:16 +03:00
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '{ "changed_files": 1 }' } } -ParameterFilter { $Uri -and $Uri -notmatch "/files"}
|
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '[{"filename":".github/workflows/test.yaml","status":"modified"}]' } } -ParameterFilter { $Uri -and $Uri -match "/files"}
|
2023-07-20 18:13:14 +03:00
|
|
|
|
|
2023-09-05 11:40:42 +03:00
|
|
|
|
{
|
2023-02-13 15:32:16 +03:00
|
|
|
|
& $scriptPath `
|
|
|
|
|
-prBaseRepository "microsoft/AL-Go" `
|
2023-07-20 18:13:14 +03:00
|
|
|
|
-pullRequestId "123456" `
|
2023-09-05 11:40:42 +03:00
|
|
|
|
-token "ABC"
|
2023-02-13 15:32:16 +03:00
|
|
|
|
} | Should -Throw
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'should succeed if the PR is from a fork and changes an .al file' {
|
2024-04-13 13:13:16 +03:00
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '{ "changed_files": 1 }' } } -ParameterFilter { $Uri -and $Uri -notmatch "/files"}
|
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '[{"filename":"ALModule/Test.Codeunit.al","status":"modified"}]' } } -ParameterFilter { $Uri -and $Uri -match "/files"}
|
2023-07-20 18:13:14 +03:00
|
|
|
|
|
2023-02-13 15:32:16 +03:00
|
|
|
|
Mock Write-Host {}
|
|
|
|
|
& $scriptPath `
|
|
|
|
|
-prBaseRepository "microsoft/AL-Go" `
|
2023-07-20 18:13:14 +03:00
|
|
|
|
-pullRequestId "123456" `
|
2023-09-05 11:40:42 +03:00
|
|
|
|
-token "ABC"
|
2023-02-13 15:32:16 +03:00
|
|
|
|
Assert-MockCalled Write-Host -Exactly 1 -Scope It -ParameterFilter { $Object -eq "Verification completed successfully." }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'should succeed if the PR is from a fork and adds an .al file' {
|
2024-04-13 13:13:16 +03:00
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '{ "changed_files": 1 }' } } -ParameterFilter { $Uri -and $Uri -notmatch "/files"}
|
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '[{"filename":"ALModule/Test.Codeunit.al","status":"added"}]' } } -ParameterFilter { $Uri -and $Uri -match "/files"}
|
2023-07-20 18:13:14 +03:00
|
|
|
|
|
2023-02-13 15:32:16 +03:00
|
|
|
|
Mock Write-Host {}
|
|
|
|
|
& $scriptPath `
|
|
|
|
|
-prBaseRepository "microsoft/AL-Go" `
|
2023-07-20 18:13:14 +03:00
|
|
|
|
-pullRequestId "123456" `
|
2023-09-05 11:40:42 +03:00
|
|
|
|
-token "ABC"
|
2023-02-13 15:32:16 +03:00
|
|
|
|
Assert-MockCalled Write-Host -Exactly 1 -Scope It -ParameterFilter { $Object -eq "Verification completed successfully." }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'should succeed if the PR is from a fork and removes an .al file' {
|
2024-04-13 13:13:16 +03:00
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '{ "changed_files": 1 }' } } -ParameterFilter { $Uri -and $Uri -notmatch "/files"}
|
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '[{"filename":"ALModule/Test.Codeunit.al","status":"removed"}]' } } -ParameterFilter { $Uri -and $Uri -match "/files"}
|
2023-07-20 18:13:14 +03:00
|
|
|
|
|
2023-02-13 15:32:16 +03:00
|
|
|
|
Mock Write-Host {}
|
|
|
|
|
& $scriptPath `
|
|
|
|
|
-prBaseRepository "microsoft/AL-Go" `
|
2023-07-20 18:13:14 +03:00
|
|
|
|
-pullRequestId "123456" `
|
2023-09-05 11:40:42 +03:00
|
|
|
|
-token "ABC"
|
2023-02-13 15:32:16 +03:00
|
|
|
|
Assert-MockCalled Write-Host -Exactly 1 -Scope It -ParameterFilter { $Object -eq "Verification completed successfully." }
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 18:13:14 +03:00
|
|
|
|
It 'should fail if the PR is from a fork and changes more than 3000 files' {
|
2024-04-13 13:13:16 +03:00
|
|
|
|
Mock -CommandName Invoke-WebRequest -MockWith { @{"Content" = '{ "changed_files": 5001 }' } } -ParameterFilter { $Uri -and $Uri -notmatch "/files"}
|
2023-07-20 18:13:14 +03:00
|
|
|
|
|
2023-09-05 11:40:42 +03:00
|
|
|
|
{
|
2023-07-20 18:13:14 +03:00
|
|
|
|
& $scriptPath `
|
|
|
|
|
-prBaseRepository "microsoft/AL-Go" `
|
|
|
|
|
-pullRequestId "123456" `
|
2023-09-05 11:40:42 +03:00
|
|
|
|
-token "ABC"
|
2023-07-20 18:13:14 +03:00
|
|
|
|
} | Should -Throw
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 15:32:16 +03:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|