From 9b624680fdef63d0f311c7cfd1af5eea2c80fcc8 Mon Sep 17 00:00:00 2001 From: DrIOS <58635327+DrIOSX@users.noreply.github.com> Date: Sun, 16 Jun 2024 11:01:16 -0500 Subject: [PATCH] add: test function --- source/Private/Initialize-LargeTestTable.ps1 | 41 ++++++++++++++----- .../Initialize-LargeTestTable.tests.ps1 | 27 ++++++++++++ 2 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 tests/Unit/Private/Initialize-LargeTestTable.tests.ps1 diff --git a/source/Private/Initialize-LargeTestTable.ps1 b/source/Private/Initialize-LargeTestTable.ps1 index d3cc9e6..f5e2d52 100644 --- a/source/Private/Initialize-LargeTestTable.ps1 +++ b/source/Private/Initialize-LargeTestTable.ps1 @@ -1,15 +1,36 @@ +<# + .SYNOPSIS + This function generates a large table with the specified number of lines. + .DESCRIPTION + This function generates a large table with the specified number of lines. The table has a header and each line has the same format. + .EXAMPLE + Initialize-LargeTestTable -lineCount 1000 + .PARAMETER lineCount + The number of lines to generate. + .INPUTS + System.Int32 + .OUTPUTS + System.String + .NOTES + The function is intended for testing purposes. +#> function Initialize-LargeTestTable { - param ( + [cmdletBinding()] + [OutputType([string])] + param( + [Parameter()] [int]$lineCount = 1000 # Number of lines to generate ) - $header = "UserPrincipalName|AuditEnabled|AdminActionsMissing|DelegateActionsMissing|OwnerActionsMissing" - $lineTemplate = "user{0}@criticalsolutions.net|True|FB,CP,MV|FB,MV|ML,MV,CR" - - $lines = @($header) - for ($i = 1; $i -le $lineCount; $i++) { - $lines += [string]::Format($lineTemplate, $i) + process { + $header = "UserPrincipalName|AuditEnabled|AdminActionsMissing|DelegateActionsMissing|OwnerActionsMissing" + $lineTemplate = "user{0}@contosonorthwind.net|True|FB,CP,MV|FB,MV|ML,MV,CR" + # Generate the header and lines + $lines = @($header) + for ($i = 1; $i -le $lineCount; $i++) { + $lines += [string]::Format($lineTemplate, $i) + } + $output = $lines -join "`n" + Write-Host "Details character count: $($output.Length)" + return $output } - $output = $lines -join "`n" - Write-Host "Details character count: $($output.Length)" - return $output } \ No newline at end of file diff --git a/tests/Unit/Private/Initialize-LargeTestTable.tests.ps1 b/tests/Unit/Private/Initialize-LargeTestTable.tests.ps1 new file mode 100644 index 0000000..4a2aa69 --- /dev/null +++ b/tests/Unit/Private/Initialize-LargeTestTable.tests.ps1 @@ -0,0 +1,27 @@ +$ProjectPath = "$PSScriptRoot\..\..\.." | Convert-Path +$ProjectName = ((Get-ChildItem -Path $ProjectPath\*\*.psd1).Where{ + ($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and + $(try { Test-ModuleManifest $_.FullName -ErrorAction Stop } catch { $false } ) + }).BaseName + + +Import-Module $ProjectName + +InModuleScope $ProjectName { + Describe Get-PrivateFunction { + Context 'Default' { + BeforeEach { + $return = Get-PrivateFunction -PrivateData 'string' + } + + It 'Returns a single object' { + ($return | Measure-Object).Count | Should -Be 1 + } + + It 'Returns a string based on the parameter PrivateData' { + $return | Should -Be 'string' + } + } + } +} +