github.com/cloudfoundry-incubator/stembuild@v0.0.0-20211223202937-5b61d62226c6/modules/BOSH.Account/BOSH.Account.Tests.ps1 (about)

     1  Remove-Module -Name BOSH.Account -ErrorAction Ignore
     2  Import-Module ./BOSH.Account.psm1
     3  
     4  Remove-Module -Name BOSH.Utils -ErrorAction Ignore
     5  Import-Module ../BOSH.Utils/BOSH.Utils.psm1
     6  
     7  Describe "Account" {
     8  
     9      Context "when username is not provided" {
    10          It "throws" {
    11              { Add-Account } | Should Throw "Provide a user name"
    12          }
    13      }
    14  
    15      Context "when password is not provided" {
    16          It "throws" {
    17              { Add-Account -User hello } | Should Throw "Provide a password"
    18          }
    19      }
    20  
    21      Context "when the username and password are valid" {
    22          $timestamp=(get-date -UFormat "%s" -Millisecond 0)
    23          $user = "TestUser_$timestamp"
    24          $password = "Password123!"
    25  
    26           BeforeEach {
    27              $userExists = !!(Get-LocalUser | Where {$_.Name -eq $user})
    28              if($userExists) {
    29                  Remove-LocalUser -Name $user
    30              }
    31          }
    32  
    33          It "Adds and removes a new user account" {
    34              Add-Account -User $user -Password $password
    35              mkdir "C:\Users\$user" -ErrorAction Ignore
    36              $adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
    37              $existing = $adsi.Children | where {$_.SchemaClassName -eq 'user' -and $_.Name -eq $user }
    38              $existing | Should Not Be $null
    39              Remove-Account -User $user
    40              $existing = $adsi.Children | where {$_.SchemaClassName -eq 'user' -and $_.Name -eq $user }
    41              $existing | Should Be $null
    42          }
    43      }
    44  }
    45  
    46  Remove-Module -Name BOSH.Account -ErrorAction Ignore
    47  Remove-Module -Name BOSH.Utils -ErrorAction Ignore