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

Init the test suite #20

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: pester tests
uses: zyborg/pester-tests-report@bb711b31e93f78f7423086d57f81928325829765 # v1.5.0
with:
include_paths: ./tests/GitHubActions_tests.ps1
include_paths: ./tests/action_tests.ps1
exclude_tags: SkipCI
report_name: action_base_tests
report_title: Action Base Tests
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
- name: pester tests
uses: zyborg/pester-tests-report@bb711b31e93f78f7423086d57f81928325829765 # v1.5.0
with:
include_paths: ./tests/GitHubActions_tests.ps1
include_paths: ./tests/action_tests.ps1
exclude_tags: SkipCI
report_name: action_base_tests-on-win
report_title: Action Base Tests (On Windows)
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sarif-viewer.connectToGithubCodeScanning": "on"
}
183 changes: 0 additions & 183 deletions tests/GitHubActions_tests.ps1

This file was deleted.

106 changes: 106 additions & 0 deletions tests/action_tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Import the Pester module
Import-Module Pester

# Define the tests
Describe "Require a token" {
BeforeAll {
# Set up any variables or conditions needed before running the tests
#$env:GITHUB_TOKEN = 'test_token'

# Run the script and capture the exit code
$output = .\..\action.ps1
Fixed Show fixed Hide fixed
}

It "action.ps1 should fail and require a token" {
$errorMessageFound = $output | Where-Object { $_ -match "::error::GitHubToken is not set" }
$errorMessageFound | Should -Not -BeNullOrEmpty
$LASTEXITCODE | Should -Be 1
}
}

Describe "Install Dependencies" {
BeforeAll {
# Set up any variables or conditions needed before running the tests
$env:GITHUB_REPOSITORY = 'octodemo/demo-vulnerabilities-ghas'
$env:GITHUB_REF = 'refs/pull/120/merge'
$env:GITHUB_STEP_SUMMARY = $(New-Item -Name /_temp/_runner_file_commands/step_summary_a01d8a3b-1412-4059-9cf1-f7c4b54cff76 -ItemType File -Force).FullName
$env:SSR_FAIL_ON_ALERT = "true"
$env:SSR_FAIL_ON_ALERT_EXCLUDE_CLOSED = "true"

# Delete all environment variables
# $env:GITHUB_TOKEN = $null
# $env:GITHUB_REPOSITORY = $null
# $env:GITHUB_REF = $null
# $env:GITHUB_STEP_SUMMARY = $null
# $env:SSR_FAIL_ON_ALERT = $null
# $env:SSR_FAIL_ON_ALERT_EXCLUDE_CLOSED = $null


# Run the script and capture the exit code
$output = .\..\action.ps1
Fixed Show fixed Hide fixed
}


It "GitHubActions module is installed" {
$module = Get-Module -ListAvailable -Name GitHubActions -ErrorAction SilentlyContinue
$module | Should -Not -BeNullOrEmpty
}

It "PowerShellForGitHub module is installed" {
$module = Get-Module -ListAvailable -Name PowerShellForGitHub -ErrorAction SilentlyContinue
$module | Should -Not -BeNullOrEmpty
}


}

# Import the module that contains the function to test
#Import-Module GitHubActions

# Define the tests
Describe "Mocked Tests" {
# Mock the Get-GitHubPullRequest function to return a predefined object
# Get-GitHubPullRequest -ModuleName GitHubActions {
# Mock Get-GitHubPullRequest{
# return @{
# Title = 'Test PR'
# commits = 1
# }
# }

# BeforeAll {
# # Set up any variables or conditions needed before running the tests
# $env:GITHUB_REPOSITORY = 'octodemo/demo-vulnerabilities-ghas'
# $env:GITHUB_REF = 'refs/pull/120/merge'
# $env:GITHUB_STEP_SUMMARY = $(New-Item -Name /_temp/_runner_file_commands/step_summary_a01d8a3b-1412-4059-9cf1-f7c4b54cff76 -ItemType File -Force).FullName
# $env:SSR_FAIL_ON_ALERT = "true"
# $env:SSR_FAIL_ON_ALERT_EXCLUDE_CLOSED = "true"
# }


# Context "context"{
# function Get-GitHubPullRequest {
# "placeholder function"
# }

# Mock Get-GitHubPullRequest{
# return @{
# Title = 'Test PR'
# commits = 1
# }
# }

# It "GitHubActions module is installed" {
# # Run the script and capture the exit code
# $output = & .\..\action.ps1 -GitHubToken 'test_token'


# Write-Host $output
# Assert-MockCalled Get-GitHubPullRequest -Times 1 -ModuleName 'GitHubActions'


# }

# }

}
Loading