Skip to content

Commit

Permalink
Update Scoop-Test testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven committed May 16, 2019
1 parent 85c8cff commit d7a06b0
Show file tree
Hide file tree
Showing 5 changed files with 298 additions and 35 deletions.
43 changes: 40 additions & 3 deletions test/Scoop-Core.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,58 @@ describe "Test-CommandAvailable" -Tag 'Scoop' {
}


describe "is_directory" -Tag 'Scoop' {
describe "directory/junction/hardlink handling" -Tag 'Scoop' {
beforeall {
$working_dir = setup_working "is_directory"
}

it "is_directory recognize directories" {
it "is_directory recognizes directories" {
is_directory "$working_dir\i_am_a_directory" | should -be $true
}
it "is_directory recognize files" {

it "is_directory recognizes files" {
is_directory "$working_dir\i_am_a_file.txt" | should -be $false
}

it "is_directory is falsey on unknown path" {
is_directory "$working_dir\i_do_not_exist" | should -be $false
}

it "create_junction recognizes directories and creates junction" {
create_junction "$working_dir\i_am_a_junction" "$working_dir\i_am_a_directory" | should -be $true
Test-Path "$working_dir\i_am_a_junction" | should -be $true
}

it "create_junction recognizes existing target" {
create_junction "$working_dir\i_am_a_junction" "$working_dir\i_am_a_directory" | should -be $false
}

it "create_junction recognizes files" {
create_junction "$working_dir\i_am_a_junction_file.txt" "$working_dir\i_am_a_file.txt" | should -be $false
Test-Path "$working_dir\i_am_a_junction_file.txt" | should -be $false
}

it "create_junction is falsey on unknown path" {
create_junction "$working_dir\i_am_a_junction" "$working_dir\i_do_not_exist" | should -be $false
}

it "create_hardlink recognizes files and creates hardlink" {
create_hardlink "$working_dir\i_am_a_hardlinked_file.txt" "$working_dir\i_am_a_file.txt" | should -be $true
Test-Path "$working_dir\i_am_a_hardlinked_file.txt" | should -be $true
}

it "create_hardlink recognizes existing target" {
create_hardlink "$working_dir\i_am_a_hardlinked_file.txt" "$working_dir\i_am_a_file.txt" | should -be $false
}

it "create_hardlink recognizes directories" {
create_hardlink "$working_dir\i_am_a_hardlinked_directory" "$working_dir\i_am_a_directory" | should -be $false
Test-Path "$working_dir\i_am_a_hardlinked_directory" | should -be $false
}

it "create_hardlink is falsey on unknown path" {
create_hardlink "$working_dir\i_do_not_exist.txt" "$working_dir\i_do_not_exist.txt" | should -be $false
}
}

describe "movedir" -Tag 'Scoop' {
Expand Down
33 changes: 1 addition & 32 deletions test/Scoop-Install.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe "env add and remove path" -Tag 'Scoop' {
}
}

describe "shim_def" -Tag 'Scoop' {
describe "shim parsing" -Tag 'Scoop' {
it "should use strings correctly" {
$target, $name, $shimArgs = shim_def "command.exe"
$target | should -be "command.exe"
Expand All @@ -122,37 +122,6 @@ describe "shim_def" -Tag 'Scoop' {
}
}

describe 'persist_def' -Tag 'Scoop' {
it 'parses string correctly' {
$source, $target = persist_def "test"
$source | should -be "test"
$target | should -be "test"
}

it 'should handle sub-folder' {
$source, $target = persist_def "foo/bar"
$source | should -be "foo/bar"
$target | should -be "foo/bar"
}

it 'should handle arrays' {
# both specified
$source, $target = persist_def @("foo", "bar")
$source | should -be "foo"
$target | should -be "bar"

# only first specified
$source, $target = persist_def @("foo")
$source | should -be "foo"
$target | should -be "foo"

# null value specified
$source, $target = persist_def @("foo", $null)
$source | should -be "foo"
$target | should -be "foo"
}
}

describe 'compute_hash' -Tag 'Scoop' {
beforeall {
$working_dir = setup_working "manifest"
Expand Down
161 changes: 161 additions & 0 deletions test/Scoop-Persist.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\persist.ps1"
. "$psscriptroot\Scoop-TestLib.ps1"

describe 'persist parsing' -Tag 'Scoop' {
beforeall {
$working_dir = setup_working "persist"
}

context "parsing object" {
$objfile = "$working_dir\persist-object.json"
$objfile | should -exist
$obj = Get-Content $objfile -Raw -Encoding UTF8 | ConvertFrom-Json -ea Stop

it 'should handle directory' {
# explicitly defined
$persist_def = persist_def_obj $obj.persist_dir[0]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be $null

# implicitly defined
$persist_def = persist_def_obj $obj.persist_dir[1]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be $null

# sub-dir
$persist_def = persist_def_obj $obj.persist_dir[2]
$persist_def.source | should -be "foo\bar"
$persist_def.target | should -be "foo\bar"
$persist_def.content | should -be $null

# renaming
$persist_def = persist_def_obj $obj.persist_dir[3]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "bar"
$persist_def.content | should -be $null

# ignore other params if dir
$persist_def = persist_def_obj $obj.persist_dir[4]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.encoding | should -be $null
$persist_def.content | should -be $null

# passthru $method
$persist_def = persist_def_obj $obj.persist_dir[5]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be $null
$persist_def.method | should -be "merge"
}

it 'should handle file' {
# explicitly defined
$persist_def = persist_def_obj $obj.persist_file[0]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be ""

# implicitly defined
$persist_def = persist_def_obj $obj.persist_file[1]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be ""

# passthru file comtents
$persist_def = persist_def_obj $obj.persist_file[2]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be "file content"

# passthru array file content
$persist_def = persist_def_obj $obj.persist_file[3]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be "file`r`ncontent"

# using $glue to join array file content
$persist_def = persist_def_obj $obj.persist_file[4]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be "file content"

# decoding BASE64 string
$persist_def = persist_def_obj $obj.persist_file[5]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be "file`r`ncontent"

# passthru other params
$persist_def = persist_def_obj $obj.persist_file[6]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be "file`r`ncontent"
$persist_def.method | should -be "update"
$persist_def.encoding | should -be "UTF8"
}
}

context 'parsing string and array of string' {
$arrfile = "$working_dir\persist-array.json"
$arrfile | should -exist
$arr = Get-Content $arrfile -Raw -Encoding UTF8 | ConvertFrom-Json -ea Stop


it 'should handle directory' {
# parse string
$persist_def = persist_def_arr $arr.persist_dir[0]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be $null

# sub-folder
$persist_def = persist_def_arr $arr.persist_dir[1]
$persist_def.source | should -be "foo\bar"
$persist_def.target | should -be "foo\bar"
$persist_def.content | should -be $null

# both specified
$persist_def = persist_def_arr $arr.persist_dir[2]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "bar"
$persist_def.content | should -be $null

# null value specified
$persist_def = persist_def_arr $arr.persist_dir[3]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be $null
}

it 'should handle file' {

# no file content specified
$persist_def = persist_def_arr $arr.persist_file[0]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be ""

# file content specified
$persist_def = persist_def_arr $arr.persist_file[1]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be "file content"

# null and file content specified
$persist_def = persist_def_arr $arr.persist_file[2]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be "file content"

# several lines of file content specified
$persist_def = persist_def_arr $arr.persist_file[3]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be "file`r`ncontent"
}
}
}
35 changes: 35 additions & 0 deletions test/fixtures/persist/persist-array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"persist_dir": [
"foo",
"foo\\bar",
[
"foo",
"bar"
],
[
"foo",
null
]
],
"persist_file": [
[
"foo"
],
[
"foo",
"",
"file content"
],
[
"foo",
null,
"file content"
],
[
"foo",
"",
"file",
"content"
]
]
}
61 changes: 61 additions & 0 deletions test/fixtures/persist/persist-object.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"persist_dir": [
{
"name": "foo",
"type": "directory"
}, {
"name": "foo\\"
}, {
"name": "foo\\bar\\"
}, {
"name": "foo\\",
"target": "bar"
}, {
"name": "foo\\",
"encoding": "UTF8",
"content": "file content"
}, {
"name": "foo\\",
"method": "merge"
}
],
"persist_file": [
{
"name": "foo",
"type": "file"
}, {
"name": "foo"
}, {
"name": "foo",
"content": "file content"
}, {
"name": "foo",
"content": [
"file",
"content"
]
}, {
"name": "foo",
"content": [
"file",
"content"
],
"glue": " "
}, {
"name": "foo",
"content": [
"ZmlsZQ0K",
"Y29udGVudA=="
],
"base64": true
}, {
"name": "foo",
"content": [
"file",
"content"
],
"encoding": "UTF8",
"method": "update"
}
]
}

0 comments on commit d7a06b0

Please sign in to comment.