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
9 changes: 6 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
{
"name": "PowerShell",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/powershell:lts-debian-11",
"image": "mcr.microsoft.com/powershell:lts-ubuntu-22.04",

"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers/features/powershell:1": {},
"ghcr.io/devcontainers/features/sshd:1": {},
"ghcr.io/devcontainers/features/dotnet:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
Expand All @@ -27,7 +27,9 @@
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.powershell",
"github.copilot"
"github.copilot",
"GitHub.copilot-chat",
"mhutchie.git-graph"
]
}
}
Expand All @@ -38,3 +40,4 @@
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}

2 changes: 1 addition & 1 deletion .github/copilot-commit-message-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ References:

- https://www.conventionalcommits.org/
- https://seesparkbox.com/foundry/semantic_commit_messages
- http://karma-runner.github.io/1.0/dev/git-commit-msg.html
- http://karma-runner.github.io/1.0/dev/git-commit-msg.html
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ function Test_GetUserName_UserNotFound{

Assert-NotImplemented
}
```
```
1 change: 1 addition & 0 deletions .github/workflows/deploy_module_on_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ jobs:
}

./deploy.ps1 -VersionTag $tag -NugetApiKey $env:NUGETAPIKEY

2 changes: 2 additions & 0 deletions .github/workflows/powershell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ jobs:
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif


1 change: 1 addition & 0 deletions .github/workflows/test_with_TestingHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ jobs:
{ "All test passed" | Write-Verbose -verbose ; exit 0 }
else
{ "Not all tests passed" | Write-Verbose -verbose ; exit 1 }

10 changes: 5 additions & 5 deletions CsvHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ $MODULE_PATH = $PSScriptRoot

# Load ps1 files on code folders in order
"config","helper","include","private","public" | ForEach-Object {

Get-ChildItem -Path $MODULE_PATH\$_\*.ps1 -Recurse -ErrorAction SilentlyContinue | ForEach-Object {
try { . $_.fullname }
catch { Write-Error -Message "Failed to import function $($import.fullname): $_" }
foreach ($import in Get-ChildItem -Path $MODULE_PATH\$_\*.ps1 -Recurse -ErrorAction SilentlyContinue) {
try { . $import.fullname }
catch { Write-Error -Message "Failed to import $($import.fullname): $_" }
}
}
}

1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

11 changes: 4 additions & 7 deletions Test/Test.psm1
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
Write-Information -Message ("Loading {0} ..." -f ($PSScriptRoot | Split-Path -Leaf)) -InformationAction continue
Write-Information -Message ("Loading {0} ..." -f ($PSCommandPath | Split-Path -LeafBase)) -InformationAction continue

Check warning

Code scanning / PSScriptAnalyzer

Cmdlet 'Write-Information' may be used incorrectly. Please check that all mandatory parameters are supplied. Warning

Cmdlet 'Write-Information' may be used incorrectly. Please check that all mandatory parameters are supplied.

#Module path is where resides the RootModule file. This file. :)
$MODULE_PATH = $PSScriptRoot

# Load ps1 files on code folders in order
"config","helper","include","private","public" | ForEach-Object {

Get-ChildItem -Path $MODULE_PATH\$_\*.ps1 -Recurse -ErrorAction SilentlyContinue | ForEach-Object {
try { . $_.fullname }
catch { Write-Error -Message "Failed to import function $($import.fullname): $_" }
foreach ($import in Get-ChildItem -Path $MODULE_PATH\$_\*.ps1 -Recurse -ErrorAction SilentlyContinue) {
try { . $import.fullname }
catch { Write-Error -Message "Failed to import $($import.fullname): $_" }
}
}

Export-ModuleMember -Function Test_*

171 changes: 171 additions & 0 deletions Test/helper/module.helper.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# Helper for module variables

function Find-ModuleRootPath{
[CmdletBinding()]
param(
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[string]$Path

Check warning

Code scanning / PSScriptAnalyzer

Command accepts pipeline input but has not defined a process block. Warning

Command accepts pipeline input but has not defined a process block.
)

$path = Convert-Path -Path $Path

while (-not [string]::IsNullOrWhiteSpace($Path)){
$psd1 = Get-ChildItem -Path $Path -Filter *.psd1 | Select-Object -First 1

if ($psd1 | Test-Path) {

if($psd1.BaseName -eq "Test"){
#foudn testing module. Continue
$path = $path | Split-Path -Parent
continue
}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# foudn module
return $path
}
# folder without psd1 file
$path = $path | Split-Path -Parent
}

# Path is null. Reached driver root. Module not found
return $null
}

$MODULE_ROOT_PATH = $PSScriptRoot | Find-ModuleRootPath
$MODULE_NAME = (Get-ChildItem -Path $MODULE_ROOT_PATH -Filter *.psd1 | Select-Object -First 1).BaseName

# Helper for module variables


$VALID_FOLDER_NAMES = @('Include', 'Private', 'Public', 'Root', 'TestInclude', 'TestPrivate', 'TestPublic', 'TestRoot', 'Tools', 'DevContainer', 'WorkFlows', 'GitHub', 'Helper', 'Config', 'TestHelper', 'TestConfig')

class ValidFolderNames : System.Management.Automation.IValidateSetValuesGenerator {
[String[]] GetValidValues() {
return $script:VALID_FOLDER_NAMES
}
}

function Get-Ps1FullPath{
[CmdletBinding()]
param(
[Parameter(Mandatory,Position = 0)][string]$Name,
[Parameter(Position = 1)][ValidateSet([ValidFolderNames])][string]$FolderName,
[Parameter(Position = 0)][string]$ModuleRootPath
)

# If folderName is not empty
if($FolderName -ne $null){

Check warning

Code scanning / PSScriptAnalyzer

$null should be on the left side of equality comparisons. Warning

$null should be on the left side of equality comparisons.
$folder = Get-ModuleFolder -FolderName $FolderName -ModuleRootPath $ModuleRootPath
$path = $folder | Join-Path -ChildPath $Name
} else {
$path = $Name
}

# Check if file exists
if(-Not (Test-Path $path)){
throw "File $path not found"
}

# Get Path item
$item = Get-item -Path $path

return $item
}
function Get-ModuleRootPath{
[CmdletBinding()]
param(
[Parameter(Position = 0)][string]$ModuleRootPath
)

# if ModuleRootPath is not provided, default to local module path
if([string]::IsNullOrWhiteSpace($ModuleRootPath)){
$ModuleRootPath = $MODULE_ROOT_PATH
}

# Convert to full path
$ModuleRootPath = Convert-Path -Path $ModuleRootPath

return $ModuleRootPath
}

function Get-ModuleName{
[CmdletBinding()]
param(
[Parameter(Position = 0)] [string]$ModuleRootPath
)

$ModuleRootPath = Get-ModuleRootPath -ModuleRootPath $ModuleRootPath

$MODULE_NAME = (Get-ChildItem -Path $MODULE_ROOT_PATH -Filter *.psd1 | Select-Object -First 1).BaseName


return $MODULE_NAME
}

function Get-ModuleFolder{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-ModuleFolder' does not have a help comment. Note

The cmdlet 'Get-ModuleFolder' does not have a help comment.
[CmdletBinding()]
param(
[Parameter(Mandatory,Position = 0)][ValidateSet([ValidFolderNames])][string]$FolderName,
[Parameter(Position = 1)][string]$ModuleRootPath
)

$ModuleRootPath = Get-ModuleRootPath -ModuleRootPath $ModuleRootPath

# TestRootPath
$testRootPath = $ModuleRootPath | Join-Path -ChildPath "Test"

switch ($FolderName){
'Public'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "public"
}
'Private'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "private"
}
'Include'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "include"
}
'TestInclude'{
$moduleFolder = $testRootPath | Join-Path -ChildPath "include"
}
'TestPrivate'{
$moduleFolder = $testRootPath | Join-Path -ChildPath "private"
}
'TestPublic'{
$moduleFolder = $testRootPath | Join-Path -ChildPath "public"
}
'Root'{
$moduleFolder = $ModuleRootPath
}
'TestRoot'{
$moduleFolder = $testRootPath
}
'Tools'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "tools"
}
'DevContainer'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".devcontainer"
}
'WorkFlows'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github/workflows"
}
'GitHub'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github"
}
'Helper'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "helper"
}
'Config'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "config"
}
'TestHelper'{
$moduleFolder = $testRootPath | Join-Path -ChildPath "helper"
}
'TestConfig'{
$moduleFolder = $testRootPath | Join-Path -ChildPath "config"
}
default{
throw "Folder [$FolderName] is unknown"
}
}
return $moduleFolder
} Export-ModuleMember -Function Get-ModuleFolder
21 changes: 7 additions & 14 deletions Test/include/database.mock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,19 @@
# This file is used to mock the database path and the database file
# for the tests. It creates a mock database path and a mock database file
# and sets the database path to the mock database path.
# We need to define variables for this include to work
# $MOCK_DATABASE_PATH : The path used as the mock database folder
# $DB_INVOKE_GET_ROOT_PATH_CMD : Invoke command that is needed to be mocked
# $DB_INVOKE_GET_ROOT_PATH_ALIAS : Invoke function to retreive the root path of the database
#
# Sample file
# # DATABASE MOCK VARIABLES
# # This file is required for DATABASE MOCK to work
# $DB_INVOKE_GET_ROOT_PATH_ALIAS = "MyModuleGetDbRootPath"
#
# THIS INCLUDE REQURED module.helper.ps1
if(-not $MODULE_NAME){ throw "Missing MODULE_NAME varaible initialization. Check for module.helerp.ps1 file." }

$DB_INVOKE_GET_ROOT_PATH_CMD = "Invoke-$DB_INVOKE_GET_ROOT_PATH_ALIAS"
$DB_INVOKE_GET_ROOT_PATH_CMD = "Invoke-$($MODULE_NAME)GetDbRootPath"
$MOCK_DATABASE_PATH = "test_database_path"

function Mock_Database([switch]$ResetDatabase){

MockCallToString $DB_INVOKE_GET_ROOT_PATH_CMD -OutString "test_database_path"
MockCallToString $DB_INVOKE_GET_ROOT_PATH_CMD -OutString $MOCK_DATABASE_PATH

$dbstore = Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_CMD
Assert-AreEqual -Expected "test_database_path" -Presented $dbstore
Assert-AreEqual -Expected $MOCK_DATABASE_PATH -Presented $dbstore

if($ResetDatabase){
Reset-DatabaseStore
Expand All @@ -39,10 +32,10 @@ function Reset-DatabaseStore{
[CmdletBinding()]
param()

$databaseRoot = Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_ALIAS
$databaseRoot = Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_CMD

Remove-Item -Path $databaseRoot -Recurse -Force -ErrorAction SilentlyContinue

New-Item -Path $databaseRoot -ItemType Directory

}
}
Loading