Tests/ARCADE_GraylogSidecarConfiguration.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')]
param ()

$Global:modulePath   = Resolve-Path -Path "$PSScriptRoot\..\.." | Select-Object -ExpandProperty Path
$Global:moduleName   = Resolve-Path -Path "$PSScriptRoot\.." | Get-Item | Select-Object -ExpandProperty BaseName
$Global:resourceName = 'ARCADE_GraylogSidecarConfiguration'

Remove-Module -Name $Global:moduleName -Force -ErrorAction SilentlyContinue
Import-Module -Name "$Global:modulePath\$Global:moduleName" -Force

Remove-Module -Name $Global:resourceName -Force -ErrorAction SilentlyContinue
Import-Module -Name "$Global:modulePath\$Global:moduleName\DSCResources\$Global:resourceName\$Global:resourceName.psm1" -Force

InModuleScope 'ARCADE_GraylogSidecarConfiguration' {

    Mock 'Get-GraylogSidecarNodeId' { '133bb51e-b8b7-433b-becc-7ed4bed71218' }

    Mock 'Get-GraylogSidecarConfigurationAssignment' { '5d02c71f98a35b06a4edb7fc' }

    Mock 'Add-GraylogSidecarConfigurationAssignment' { }

    Mock 'Remove-GraylogSidecarConfigurationAssignment' { }

    Context 'Get-TargetResource' {

        $getParams = @{
            ServerUrl   = 'https://graylog.contoso.com/'
            Credential  = [System.Management.Automation.PSCredential]::new('username', (Protect-String -String 'password'))
            CollectorId = '5d06f16771c02a78f6ed644f'
        }

        It 'Should return a System.Collections.Hashtable' {

            # Act
            $result = & "$Global:resourceName\Get-TargetResource" @getParams

            # Assert
            $result | Should -BeOfType 'System.Collections.Hashtable'
        }
    }

    Context 'Set-TargetResource' {

        $setParams = @{
            Ensure          = 'Present'
            ServerUrl       = 'https://graylog.contoso.com/'
            Credential      = [System.Management.Automation.PSCredential]::new('username', (Protect-String -String 'password'))
            CollectorId     = '5d06f16771c02a78f6ed644f'
            ConfigurationId = '5d02c71f98a35b06a4edb7fc'
        }

        It 'Should not return anything' {

            # Act
            $result = & "$Global:resourceName\Set-TargetResource" @setParams

            # Assert
            $result | Should -BeNullOrEmpty
        }
    }

    Context 'Test-TargetResource' {

        $testParams = @{
            Ensure          = 'Present'
            ServerUrl       = 'https://graylog.contoso.com/'
            Credential      = [System.Management.Automation.PSCredential]::new('username', (Protect-String -String 'password'))
            CollectorId     = '5d06f16771c02a78f6ed644f'
            ConfigurationId = '5d02c71f98a35b06a4edb7fc'
        }

        It 'Should return a System.Boolean' {

            # Act
            $result = & "$Global:resourceName\Test-TargetResource" @testParams

            # Assert
            $result | Should -BeOfType 'System.Boolean'
        }
    }
}