Skip to content

Commit

Permalink
Added automatic tests for jenv remove
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixSelter committed Apr 7, 2022
1 parent f7d18e9 commit 7106479
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jenv-remove.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ function Invoke-Remove {
$config.jenvs = @($config.jenvs | Where-Object { $_.name -ne $name })
# Remove any jenv local with that name
$config.locals = @($config.locals | Where-Object { $_.name -ne $name })
Write-Host Your JEnv was removed successfully
Write-Output 'Your JEnv was removed successfully'
}
}
30 changes: 30 additions & 0 deletions tests/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,40 @@ Describe 'JEnv local command' {
})
$config.locals | ConvertTo-Json | Should -Be ($template | ConvertTo-Json)
}
}

Describe 'JEnv remove command' {

It "Should remove jenv from jenvs and locals" {
& $jenv remove fake1 | Should -Be 'Your JEnv was removed successfully'
$config = Get-Content -Path ($Env:APPDATA + "\JEnv\jenv.config.json") -Raw | ConvertFrom-Json

$template = @()
$config.locals | ConvertTo-Json | Should -Be ($template | ConvertTo-Json)

$template = @([PSCustomObject]@{
name = "fake2"
path = "$($PSScriptRoot)/Fake-Executables/java/v2"
})
$config.jenvs | ConvertTo-Json | Should -Be ($template | ConvertTo-Json)
}

It "Should remove jenv from jenvs" {
& $jenv remove fake2 | Should -Be 'Your JEnv was removed successfully'
$config = Get-Content -Path ($Env:APPDATA + "\JEnv\jenv.config.json") -Raw | ConvertFrom-Json

$template = @()
$config.jenvs | ConvertTo-Json | Should -Be ($template | ConvertTo-Json)
}

It "Should not fail if it does not exist" {
& $jenv remove fake2 | Should -Be 'Your JEnv was removed successfully'
}

AfterAll {
Set-Location ((get-item $PSScriptRoot).parent.fullname + "/tests")
}

}


Expand Down

0 comments on commit 7106479

Please sign in to comment.