tests/ModuleBehavior.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
Describe "The posh-awsvault module" {
  Context "When imported and used to create an alias" {
    $TestState = @{}

    Import-Module .\posh-awsvault.psd1

    New-AWSVaultAlias somecommand

    It "Creates a dynamic module for that alias" {
      $TestState["Module"] = (Get-Module posh-awsvault-somecommand)
      $TestState["Module"] | Should -Not -BeNullOrEmpty
    }

    It "Exports the alias and the associated function" {
      $TestState["Module"].ExportedAliases.Keys | Should -Contain "somecommand"
    }

    Remove-Module posh-awsvault

    It "Removes the dynamic module when itself is removed" {
      (Get-Module posh-awsvault-somecommand `
        -ErrorAction SilentlyContinue `
      ) | Should -BeNullOrEmpty
    }
  }
}