tests/Remove-AWSVaultAlias.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
Describe "Remove-AWSVaultAlias" {
  Import-Module .\posh-awsvault.psd1

  Context "When called to remove a posh-awsvault alias" {
    New-AWSVaultAlias somecommand

    $ModuleName = (Get-Alias somecommand).Module.Name

    Remove-AWSVaultAlias somecommand

    It "Removes the alias" {
      (Get-Alias somecommand -ErrorAction SilentlyContinue) `
        | Should -BeNull
    }

    It "Removes the module" {
      (Get-Module $ModuleName -ErrorAction SilentlyContinue) `
        | Should -BeNull
    }
  }

  Context "When called to remove an alias that was not created by posh-awsvault" {
    It "Throws an error" {
      { Remove-AWSVaultAlias gc } | Should -Throw
    }
  }

  Context "When called to remove an alias that doesn't exist" {
    It "Throws an error" {
      { Remove-AWSVaultAlias nonexistentalias } | Should -Throw
    }
  }
}