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

Add MSFT_xBLBitlocker Unit Tests #38

Merged
merged 2 commits into from
Nov 21, 2018
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Defaults to false.
* Add remaining Unit Tests for xBitlockerCommon.
* Add Unit tests for MSFT_xBLTpm
* Add remaining Unit Tests for xBLAutoBitlocker
* Add Unit tests for MSFT_xBLBitlocker

### 1.2.0.0

Expand Down
104 changes: 104 additions & 0 deletions Tests/Unit/MSFT_xBLBitlocker.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#region HEADER
$script:DSCModuleName = 'xBitlocker'
$script:DSCResourceName = 'MSFT_xBLBitlocker'

# Unit Test Template Version: 1.2.4
$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force

$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:DSCModuleName `
-DSCResourceName $script:DSCResourceName `
-ResourceType 'Mof' `
-TestType Unit

#endregion HEADER

function Invoke-TestSetup
{

}

function Invoke-TestCleanup
{
Restore-TestEnvironment -TestEnvironment $TestEnvironment
}

# Begin Testing
try
{
Invoke-TestSetup

InModuleScope $script:DSCResourceName {
# Override helper functions
function CheckForPreReqs {}

# Setup common test variables
$testMountPoint = 'C:'
$testPrimaryProtector = 'TpmProtector'

# Setup common Mocks
Mock -CommandName CheckForPreReqs -Verifiable

Describe 'MSFT_xBLBitlocker\Get-TargetResource' -Tag 'Get' {
AfterEach {
Assert-VerifiableMock
}

Context 'When Get-TargetResource is called' {
It 'Should return a Hashtable with the input MountPoint' {
$getResult = Get-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector
$getResult | Should -Be -Not $null
$getResult.MountPoint | Should -Be $testMountPoint

}
}
}

Describe 'MSFT_xBLBitlocker\Set-TargetResource' -Tag 'Set' {
AfterEach {
Assert-VerifiableMock
}

Context 'When Set-TargetResource is called' {
It 'Should call EnableBitlocker' {
Mock -CommandName EnableBitlocker -Verifiable

Set-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector
}
}
}

Describe 'MSFT_xBLBitlocker\Test-TargetResource' -Tag 'Test' {
AfterEach {
Assert-VerifiableMock
}

Context 'When TestBitlocker returns True' {
It 'Should return True' {
Mock -CommandName TestBitlocker -Verifiable -MockWith { return $true }

Test-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector | Should -Be $true
}
}

Context 'When TestBitlocker returns False' {
It 'Should return False' {
Mock -CommandName TestBitlocker -Verifiable -MockWith { return $false }

Test-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector | Should -Be $false
}
}
}
}
}
finally
{
Invoke-TestCleanup
}
110 changes: 0 additions & 110 deletions Tests/Unit/unit_template.ps1

This file was deleted.