diff --git a/tests/Private/01_Get-DefaultCredentialStorePath.Tests.ps1 b/src/Private/Get-DefaultCredentialStorePath.Tests.ps1 similarity index 83% rename from tests/Private/01_Get-DefaultCredentialStorePath.Tests.ps1 rename to src/Private/Get-DefaultCredentialStorePath.Tests.ps1 index ac4b6dc..ee892fe 100644 --- a/tests/Private/01_Get-DefaultCredentialStorePath.Tests.ps1 +++ b/src/Private/Get-DefaultCredentialStorePath.Tests.ps1 @@ -1,3 +1,16 @@ +BeforeAll { + $ManifestFile = (Get-Item -Path "./src/*.psd1").FullName + Import-Module $ManifestFile -Force + + $PrivateFunctions = (Get-ChildItem -Path "./src/Private/*.ps1" | Where-Object { + $_.BaseName -notmatch '.Tests' + } + ).FullName + foreach ( $func in $PrivateFunctions) { + . $func + } +} + Describe "Get-DefaultCredentialStorePath" { Context "Basic syntax test" { It "Test1: Should not throw" { diff --git a/src/Private/Get-ModuleBase.Tests.ps1 b/src/Private/Get-ModuleBase.Tests.ps1 new file mode 100644 index 0000000..73f9c53 --- /dev/null +++ b/src/Private/Get-ModuleBase.Tests.ps1 @@ -0,0 +1,20 @@ +BeforeAll { + $ManifestFile = (Get-Item -Path "./src/*.psd1").FullName + Import-Module $ManifestFile -Force + + $PrivateFunctions = (Get-ChildItem -Path "./src/Private/*.ps1" | Where-Object { + $_.BaseName -notmatch '.Tests' + } + ).FullName + foreach ( $func in $PrivateFunctions) { + . $func + } +} + +Describe "Get-ModuleBase" { + Context "Basic syntax check" { + It "Test1: Should not throw" { + { Get-ModuleBase } | Should -Not -Throw + } + } +} diff --git a/src/Private/Get-RandomAESKey.Tests.ps1 b/src/Private/Get-RandomAESKey.Tests.ps1 new file mode 100644 index 0000000..21b6046 --- /dev/null +++ b/src/Private/Get-RandomAESKey.Tests.ps1 @@ -0,0 +1,26 @@ +BeforeAll { + $ManifestFile = (Get-Item -Path "./src/*.psd1").FullName + Import-Module $ManifestFile -Force + + $PrivateFunctions = (Get-ChildItem -Path "./src/Private/*.ps1" | Where-Object { + $_.BaseName -notmatch '.Tests' + } + ).FullName + foreach ( $func in $PrivateFunctions) { + . $func + } +} + +Describe "Get-RandomKey" { + Context "Basic input tests" { + It "Test1: Should not throw " { + { Get-RandomAESKey } | Should -Not -Throw + } + } + Context "Basic syntax check" { + It "Test2: Should return a key with a length of 32 bytes" { + $Key = Get-RandomAESKey + $Key.length | Should -Be 32 + } + } +} diff --git a/tests/Private/01_Get-TempDir.Tests.ps1 b/src/Private/Get-TempDir.Tests.ps1 similarity index 54% rename from tests/Private/01_Get-TempDir.Tests.ps1 rename to src/Private/Get-TempDir.Tests.ps1 index 34a3d5e..336471b 100644 --- a/tests/Private/01_Get-TempDir.Tests.ps1 +++ b/src/Private/Get-TempDir.Tests.ps1 @@ -1,7 +1,20 @@ +BeforeAll { + $ManifestFile = (Get-Item -Path "./src/*.psd1").FullName + Import-Module $ManifestFile -Force + + $PrivateFunctions = (Get-ChildItem -Path "./src/Private/*.ps1" | Where-Object { + $_.BaseName -notmatch '.Tests' + } + ).FullName + foreach ( $func in $PrivateFunctions) { + . $func + } +} + Describe "Get-TempDir" { Context "Basic tests" { It "Should not throw" { - {Get-TempDir} | Should -Not -Throw + { Get-TempDir } | Should -Not -Throw } It "Should return the correct os tmp path" { $Path = Get-TempDir @@ -17,7 +30,11 @@ Describe "Get-TempDir" { } } if ($Env:APPVEYOR) { - if (($isWindows) -or ($PSVersionTable.PSVersion.Major -lt 6) -or ($PSVersionTable.PSEdition -eq 'Desktop')) { + if ( + ($isWindows) -or + ($PSVersionTable.PSVersion.Major -lt 6) -or + ($PSVersionTable.PSEdition -eq 'Desktop') + ) { $RefPath = (Resolve-Path -Path $env:TEMP).Path $Path | Should -Be $RefPath } diff --git a/tests/Private/01_Resolve-Dependency.Tests.ps1 b/src/Private/Resolve-Dependency.Tests.ps1 similarity index 57% rename from tests/Private/01_Resolve-Dependency.Tests.ps1 rename to src/Private/Resolve-Dependency.Tests.ps1 index 755ce9a..380a259 100644 --- a/tests/Private/01_Resolve-Dependency.Tests.ps1 +++ b/src/Private/Resolve-Dependency.Tests.ps1 @@ -1,7 +1,20 @@ +BeforeAll { + $ManifestFile = (Get-Item -Path "./src/*.psd1").FullName + Import-Module $ManifestFile -Force + + $PrivateFunctions = (Get-ChildItem -Path "./src/Private/*.ps1" | Where-Object { + $_.BaseName -notmatch '.Tests' + } + ).FullName + foreach ( $func in $PrivateFunctions) { + . $func + } +} + Describe "Resolve-Dependency" { Context "Basic syntax check" { - Mock Get-ModuleBase {return (Join-Path -Path $PWD -ChildPath '/resources')} - Mock Test-Module {return $true} + Mock Get-ModuleBase { return (Join-Path -Path $PWD -ChildPath '/resources') } + Mock Test-Module { return $true } It "Test1: Should not throw" { { Resolve-Dependency -Name 'foobar2000' } | Should -Not -Throw } @@ -12,11 +25,11 @@ Describe "Resolve-Dependency" { Context "Enforce Error" { # Return incorrect module base to enforce there is no config file. Mock Get-ModuleBase { - if ($IsWindows) {return "C:\"} - elseif ($isLinux) {return "/"} + if ($IsWindows) { return "C:\" } + elseif ($isLinux) { return "/" } } It "Missing dependency file should not cause an error" { - { Resolve-Dependency -Name 'awesome'} | Should -Not -Throw + { Resolve-Dependency -Name 'awesome' } | Should -Not -Throw } It "Missing dependency file should return true" { @@ -24,7 +37,7 @@ Describe "Resolve-Dependency" { } } Context "Testing input variations" { - Mock Get-ModuleBase {return (Join-Path -Path $PWD -ChildPath '/resources')} + Mock Get-ModuleBase { return (Join-Path -Path $PWD -ChildPath '/resources') } It "Should return true if all given dependencies exist" { Resolve-Dependency -Name 'Existing' | Should -Be $true } diff --git a/tests/Private/01_Test-Module.Tests.ps1 b/src/Private/Test-Module.Tests.ps1 similarity index 68% rename from tests/Private/01_Test-Module.Tests.ps1 rename to src/Private/Test-Module.Tests.ps1 index c5747c8..1805d12 100644 --- a/tests/Private/01_Test-Module.Tests.ps1 +++ b/src/Private/Test-Module.Tests.ps1 @@ -1,3 +1,16 @@ +BeforeAll { + $ManifestFile = (Get-Item -Path "./src/*.psd1").FullName + Import-Module $ManifestFile -Force + + $PrivateFunctions = (Get-ChildItem -Path "./src/Private/*.ps1" | Where-Object { + $_.BaseName -notmatch '.Tests' + } + ).FullName + foreach ( $func in $PrivateFunctions) { + . $func + } +} + Describe "Test-ModuleName" { Context "Basic input tests" { It "Testing standard module should not throw" { @@ -20,7 +33,7 @@ Describe "Test-ModuleName" { Test-Module -Name 'foobar2000' | Should -Be $false } It "StopifFails switch should thrown an error" { - {Test-Module -Name 'foobar2000' -StopIfFails }| Should -Throw + { Test-Module -Name 'foobar2000' -StopIfFails } | Should -Throw } } } diff --git a/tests/Private/01_Get-ModuleBase.Tests.ps1 b/tests/Private/01_Get-ModuleBase.Tests.ps1 deleted file mode 100644 index 0e5d972..0000000 --- a/tests/Private/01_Get-ModuleBase.Tests.ps1 +++ /dev/null @@ -1,7 +0,0 @@ -Describe "Get-ModuleBase" { - Context "Basic syntax check" { - It "Test1: Should not throw" { - { Get-ModuleBase } | Should -Not -Throw - } - } -} diff --git a/tests/Private/01_Get-RandomAESKey.Tests.ps1 b/tests/Private/01_Get-RandomAESKey.Tests.ps1 deleted file mode 100644 index 9a9c72f..0000000 --- a/tests/Private/01_Get-RandomAESKey.Tests.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -Describe "Get-RandomKey" { - Context "Basic input tests" { - It "Test1: Should not throw " { - {Get-RandomAESKey} | Should -Not -Throw - } - } - Context "Basic syntax check" { - It "Test2: Should return a key with a length of 32 bytes" { - $Key = Get-RandomAESKey - $Key.length | Should -Be 32 - } - } -}