Private/Resolve-Version.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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
BeforeAll { . $PSCommandPath.Replace('.Tests.ps1','.ps1') } Describe 'Resolve-Version' -Tag Unit { BeforeEach { Push-Location Set-Location -Path "TestDrive:\" $env:terraformversion=$null Remove-Item "env:/terraformversion" -ErrorAction SilentlyContinue -Force Remove-Item "TestDrive:\.terraformversion" -ErrorAction SilentlyContinue -Force } AfterEach { $env:terraformversion=$null Remove-Item "env:/terraformversion" -ErrorAction SilentlyContinue -Force Remove-Item "TestDrive:\.terraformversion" -ErrorAction SilentlyContinue -Force Pop-Location } It 'It should default to the latest version' { $Config = @{ AvailableVersions = @( "1.0.0" "2.0.0" "3.0.0" ) } $Version = Resolve-Version -Config $Config $Version.DesiredVersion | Should -BeExactly "3.0.0" $Version.Source | Should -BeExactly "latest" } It 'It should resolve the correct version specified by .terraformversion file' { $Config = @{ AvailableVersions = @( "1.0.0" "2.0.0" ) DesiredVersion = "1.0.0" } Set-Content "TestDrive:\.terraformversion" -value "2.0.0" $Version = Resolve-Version -Config $Config $Version.DesiredVersion | Should -BeExactly "2.0.0" $Version.Source | Should -BeExactly "file" } It 'It should resolve the correct version specified by environment variable' { $Config = @{ AvailableVersions = @( "1.0.0" "2.0.0" "3.0.0" ) DesiredVersion = "1.0.0" } Set-Content "TestDrive:\.terraformversion" -value "2.0.0" $env:terraformversion="3.0.0" $Version = Resolve-Version -Config $Config $Version.DesiredVersion | Should -BeExactly "3.0.0" $Version.Source | Should -BeExactly "environment" } It 'It should resolve the correct version specified by profile configuration' { $Config = @{ AvailableVersions = @( "1.0.0" "2.0.0" ) DesiredVersion = "2.0.0" } $Version = Resolve-Version -Config $Config $Version.DesiredVersion | Should -BeExactly "2.0.0" $Version.Source | Should -BeExactly "profile" } It 'It should fail to resolve a non-existent version provided by configuration' { $Config = @{ AvailableVersions = @( "1.0.0" ) DesiredVersion = "999.999.999" } {Resolve-Version -Config $Config} | Should -Throw "unable to find specified terraform version: source=profile, version=999.999.999" } It 'It should fail to resolve a non-existent version provided by environment variable' { $Config = @{ AvailableVersions = @( "1.0.0" ) } $env:terraformversion = "999.999.999" {Resolve-Version -Config $Config} | Should -Throw "unable to find specified terraform version: source=environment, version=999.999.999" $env:terraformversion = $null } It 'It should fail to resolve a non-existent version provided by file' { $Config = @{ AvailableVersions = @( "1.0.0" ) } Push-Location Set-Location -Path "TestDrive:\" Set-Content "TestDrive:\.terraformversion" -value "999.999.999" {Resolve-Version -Config $Config} | Should -Throw "unable to find specified terraform version: source=file, version=999.999.999" Pop-Location } } |