Tests/Integration/ModuleConflict.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$script:DSCModuleName      = 'CertificateDsc'
<#
    These integration tests ensure that exported cmdlets names do not conflict
    with any other names that are exposed by other common resource kit modules.
#>

$script:ModulesToTest = @( 'NetworkingDsc','ComputerManagementDsc','DFSDsc' )

#region HEADER
# Integration Test Template Version: 1.1.0
[System.String] $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 (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath "$($script:DSCModuleName).psd1") -Force
$TestEnvironment = Initialize-TestEnvironment `
    -DSCModuleName $script:DSCModuleName `
    -DSCResourceName 'All' `
    -TestType Integration

#endregion

# Using try/finally to always cleanup even if something awful happens.
try
{
    Describe "$($script:DSCModuleName)_CommonModuleConflict" {

        foreach ($moduleToTest in $script:ModulesToTest)
        {
            It "Should be able to install DSC Resource module '$moduleToTest'" {
                {
                    Install-Module -Name $moduleToTest -ErrorAction Stop
                } | Should -Not -Throw
            }
        }
    }
}
finally
{
    #region FOOTER
    Restore-TestEnvironment -TestEnvironment $TestEnvironment
    #endregion
}