Variables.Tests.ps1

####################################################################################################
# Declarations
####################################################################################################

# Set InformationPreference
$InformationPreference = "Continue"

####################################################################################################
# Functions
####################################################################################################

# Import other BitTitan.Runbooks modules
Import-BT_Module BitTitan.Runbooks.Common

####################################################################################################
# The tests
####################################################################################################

describe "Modules/BitTitan.Runbooks.Common/Variables/Set-DefaultValue" -Tags "module", "common", "unit" {

    context "when given a variable containing null" {

        it "sets the variable to the default value" {
            $Global:variable = $null
            $variable | Set-DefaultValue 42
            $variable | Should Be 42

            $Global:variable = $null
            $variable | Set-DefaultValue "string"
            $variable | Should Be "string"

            $Global:variable = $null
            $variable | Set-DefaultValue @(1, 2, 3)
            $variable | Should Be @(1, 2, 3)
        }
    }

    context "when given a variable already containing a value" {

        it "does not change the value of the variable" {
            $Global:variable = 5
            $variable | Set-DefaultValue 42
            $variable | Should Be 5

            $Global:variable = "foo"
            $variable | Set-DefaultValue "bar"
            $variable | Should Be "foo"

            $Global:variable = @(1, 2)
            $variable | Set-DefaultValue @(1, 2, 3)
            $variable | Should Be @(1, 2)
        }
    }
}