|
1 | | -$Global:DSCModuleName = 'xComputerManagement' |
2 | | -$Global:DSCResourceName = 'MSFT_xOfflineDomainJoin' |
| 1 | +$script:DSCModuleName = 'xComputerManagement' |
| 2 | +$script:DSCResourceName = 'MSFT_xOfflineDomainJoin' |
3 | 3 |
|
4 | | -#region HEADER |
5 | | -[String] $moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)) |
6 | | -if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` |
7 | | - (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) |
8 | | -{ |
9 | | - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\')) |
10 | | -} |
11 | | -else |
| 4 | +Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global |
| 5 | + |
| 6 | +# Unit Test Template Version: 1.2.0 |
| 7 | +$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) |
| 8 | +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` |
| 9 | + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) |
12 | 10 | { |
13 | | - & git @('-C',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\'),'pull') |
| 11 | + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) |
14 | 12 | } |
15 | | -Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force |
| 13 | + |
| 14 | +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force |
| 15 | + |
16 | 16 | $TestEnvironment = Initialize-TestEnvironment ` |
17 | | - -DSCModuleName $Global:DSCModuleName ` |
18 | | - -DSCResourceName $Global:DSCResourceName ` |
19 | | - -TestType Unit |
20 | | -#endregion |
| 17 | + -DSCModuleName $script:DSCModuleName ` |
| 18 | + -DSCResourceName $script:DSCResourceName ` |
| 19 | + -TestType Unit |
| 20 | +#endregion HEADER |
21 | 21 |
|
22 | 22 | # Begin Testing |
23 | 23 | try |
24 | 24 | { |
25 | 25 | #region Pester Tests |
26 | 26 |
|
27 | | - InModuleScope $Global:DSCResourceName { |
| 27 | + InModuleScope $script:DSCResourceName { |
| 28 | + $script:DSCResourceName = 'MSFT_xOfflineDomainJoin' |
28 | 29 |
|
29 | 30 | $TestOfflineDomainJoin = @{ |
30 | 31 | IsSingleInstance = 'Yes' |
31 | 32 | RequestFile = 'C:\ODJRequest.txt' |
32 | 33 | } |
33 | 34 |
|
34 | | - Describe "$($Global:DSCResourceName)\Get-TargetResource" { |
| 35 | + Describe "$($script:DSCResourceName)\Get-TargetResource" { |
35 | 36 |
|
36 | 37 | It 'should return the correct values' { |
37 | 38 | $Result = Get-TargetResource ` |
|
42 | 43 | } |
43 | 44 | } |
44 | 45 |
|
45 | | - Describe "$($Global:DSCResourceName)\Set-TargetResource" { |
| 46 | + Describe "$($script:DSCResourceName)\Set-TargetResource" { |
46 | 47 | Mock Test-Path -MockWith { return $True } |
47 | 48 | Mock Join-Domain |
48 | 49 |
|
|
77 | 78 | } |
78 | 79 | } |
79 | 80 | } |
80 | | - |
81 | | - Describe "$($Global:DSCResourceName)\Test-TargetResource" { |
| 81 | + |
| 82 | + Describe "$($script:DSCResourceName)\Test-TargetResource" { |
82 | 83 | Mock Test-Path -MockWith { return $True } |
83 | 84 | Mock Get-DomainName -MockWith { return $null } |
84 | 85 |
|
|
126 | 127 | } |
127 | 128 | } |
128 | 129 |
|
129 | | - Describe "$($Global:DSCResourceName)\Join-Domain" { |
130 | | - Mock djoin.exe -MockWith { $Global:LASTEXITCODE = 0; return "OK" } |
| 130 | + Describe "$($script:DSCResourceName)\Join-Domain" { |
| 131 | + Mock djoin.exe -MockWith { $script:LASTEXITCODE = 0; return "OK" } |
131 | 132 |
|
132 | 133 | Context 'Domain Join successful' { |
133 | 134 | It 'should not throw' { |
|
138 | 139 | } |
139 | 140 | } |
140 | 141 |
|
141 | | - Mock djoin.exe -MockWith { $Global:LASTEXITCODE = 99; return "ERROR" } |
| 142 | + Mock djoin.exe -MockWith { $script:LASTEXITCODE = 99; return "ERROR" } |
142 | 143 |
|
143 | 144 | Context 'Domain Join successful' { |
144 | 145 | $errorId = 'DjoinError' |
|
0 commit comments