forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoop-Install.Tests.ps1
124 lines (104 loc) · 4.02 KB
/
Scoop-Install.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
BeforeAll {
. "$PSScriptRoot\Scoop-TestLib.ps1"
. "$PSScriptRoot\..\lib\core.ps1"
. "$PSScriptRoot\..\lib\manifest.ps1"
. "$PSScriptRoot\..\lib\install.ps1"
}
Describe 'appname_from_url' -Tag 'Scoop' {
It 'should extract the correct name' {
appname_from_url 'https://example.org/directory/foobar.json' | Should -Be 'foobar'
}
}
Describe 'url_filename' -Tag 'Scoop' {
It 'should extract the real filename from an url' {
url_filename 'http://example.org/foo.txt' | Should -Be 'foo.txt'
url_filename 'http://example.org/foo.txt?var=123' | Should -Be 'foo.txt'
}
It 'can be tricked with a hash to override the real filename' {
url_filename 'http://example.org/foo-v2.zip#/foo.zip' | Should -Be 'foo.zip'
}
}
Describe 'url_remote_filename' -Tag 'Scoop' {
It 'should extract the real filename from an url' {
url_remote_filename 'http://example.org/foo.txt' | Should -Be 'foo.txt'
url_remote_filename 'http://example.org/foo.txt?var=123' | Should -Be 'foo.txt'
}
It 'can not be tricked with a hash to override the real filename' {
url_remote_filename 'http://example.org/foo-v2.zip#/foo.zip' | Should -Be 'foo-v2.zip'
}
}
Describe 'is_in_dir' -Tag 'Scoop', 'Windows' {
It 'should work correctly' {
is_in_dir 'C:\test' 'C:\foo' | Should -BeFalse
is_in_dir 'C:\test' 'C:\test\foo\baz.zip' | Should -BeTrue
is_in_dir 'test' "$PSScriptRoot" | Should -BeTrue
is_in_dir "$PSScriptRoot\..\" "$PSScriptRoot" | Should -BeFalse
}
}
Describe 'env add and remove path' -Tag 'Scoop', 'Windows' {
BeforeAll {
# test data
$manifest = @{
'env_add_path' = @('foo', 'bar')
}
$testdir = Join-Path $PSScriptRoot 'path-test-directory'
$global = $false
# store the original path to prevent leakage of tests
$origPath = $env:PATH
}
It 'should concat the correct path' {
Mock add_first_in_path {}
Mock remove_from_path {}
# adding
env_add_path $manifest $testdir $global
Assert-MockCalled add_first_in_path -Times 1 -ParameterFilter { $dir -like "$testdir\foo" }
Assert-MockCalled add_first_in_path -Times 1 -ParameterFilter { $dir -like "$testdir\bar" }
env_rm_path $manifest $testdir $global
Assert-MockCalled remove_from_path -Times 1 -ParameterFilter { $dir -like "$testdir\foo" }
Assert-MockCalled remove_from_path -Times 1 -ParameterFilter { $dir -like "$testdir\bar" }
}
}
Describe 'shim_def' -Tag 'Scoop' {
It 'should use strings correctly' {
$target, $name, $shimArgs = shim_def 'command.exe'
$target | Should -Be 'command.exe'
$name | Should -Be 'command'
$shimArgs | Should -BeNullOrEmpty
}
It 'should expand the array correctly' {
$target, $name, $shimArgs = shim_def @('foo.exe', 'bar')
$target | Should -Be 'foo.exe'
$name | Should -Be 'bar'
$shimArgs | Should -BeNullOrEmpty
$target, $name, $shimArgs = shim_def @('foo.exe', 'bar', '--test')
$target | Should -Be 'foo.exe'
$name | Should -Be 'bar'
$shimArgs | Should -Be '--test'
}
}
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'
}
}