Private/Update-AvailableTerraformVersions.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
BeforeAll {
    . $PSCommandPath.Replace('.Tests.ps1','.ps1')
    . $PSScriptRoot/../Class/TerrafunConfig.ps1
}

Describe 'Update-AvailableTerraformVersions.Unit' -Tag Unit {

    BeforeAll {
        Function Get-TerraformVersions{}
        Mock Get-TerraformVersions {
            return @()
        }
    }

    It 'Should check for new versions if the last check was more than 1 hour ago' {
        $Config = [TerrafunConfig]::new()
        $Config.Read()
        $Config.LastUpdateCheck = Get-Date -Format s (Get-Date).AddMinutes(-61).ToUniversalTime()

        Update-AvailableTerraformVersions -Config $Config
        Should -Invoke -CommandName Get-TerraformVersions -Times 1
    }

    It 'Should not for new versions if the last check was less than 1 hour ago' {
        $Config = [TerrafunConfig]::new()
        $Config.Read()
        $Config.LastUpdateCheck = Get-Date -Format s (Get-Date).AddMinutes(-59).ToUniversalTime()

        Update-AvailableTerraformVersions -Config $Config
        Should -Invoke -CommandName Get-TerraformVersions -Times 0
    }



}