Skip to content

Commit 7106479

Browse files
committed
Added automatic tests for jenv remove
1 parent f7d18e9 commit 7106479

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/jenv-remove.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ function Invoke-Remove {
1515
$config.jenvs = @($config.jenvs | Where-Object { $_.name -ne $name })
1616
# Remove any jenv local with that name
1717
$config.locals = @($config.locals | Where-Object { $_.name -ne $name })
18-
Write-Host Your JEnv was removed successfully
18+
Write-Output 'Your JEnv was removed successfully'
1919
}
2020
}

tests/test.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,40 @@ Describe 'JEnv local command' {
191191
})
192192
$config.locals | ConvertTo-Json | Should -Be ($template | ConvertTo-Json)
193193
}
194+
}
195+
196+
Describe 'JEnv remove command' {
197+
198+
It "Should remove jenv from jenvs and locals" {
199+
& $jenv remove fake1 | Should -Be 'Your JEnv was removed successfully'
200+
$config = Get-Content -Path ($Env:APPDATA + "\JEnv\jenv.config.json") -Raw | ConvertFrom-Json
201+
202+
$template = @()
203+
$config.locals | ConvertTo-Json | Should -Be ($template | ConvertTo-Json)
204+
205+
$template = @([PSCustomObject]@{
206+
name = "fake2"
207+
path = "$($PSScriptRoot)/Fake-Executables/java/v2"
208+
})
209+
$config.jenvs | ConvertTo-Json | Should -Be ($template | ConvertTo-Json)
210+
}
211+
212+
It "Should remove jenv from jenvs" {
213+
& $jenv remove fake2 | Should -Be 'Your JEnv was removed successfully'
214+
$config = Get-Content -Path ($Env:APPDATA + "\JEnv\jenv.config.json") -Raw | ConvertFrom-Json
215+
216+
$template = @()
217+
$config.jenvs | ConvertTo-Json | Should -Be ($template | ConvertTo-Json)
218+
}
219+
220+
It "Should not fail if it does not exist" {
221+
& $jenv remove fake2 | Should -Be 'Your JEnv was removed successfully'
222+
}
194223

195224
AfterAll {
196225
Set-Location ((get-item $PSScriptRoot).parent.fullname + "/tests")
197226
}
227+
198228
}
199229

200230

0 commit comments

Comments
 (0)