-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathare_all_packages_installed.bats
72 lines (56 loc) · 1.69 KB
/
are_all_packages_installed.bats
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
#!/usr/bin/env bats
load ../src/functions
load test-data
load test-helpers
load test-mocks
# Mock
load mocks/pkgutil--pkg-info
@test "should return OK status when package is found" {
# Given:
mocks_setup pkgutil
pkgutil_finds_package=yes
# When:
run are_all_packages_installed com.example.Pkg.ID.1 com.example.Pkg.ID.2
# Then:
mocks_fetch_args
[ ${#args[@]} -eq 4 ]
[ "${args[0]}" == --pkg-info ]
[ "${args[1]}" == com.example.Pkg.ID.1 ]
[ "${args[2]}" == --pkg-info ]
[ "${args[3]}" == com.example.Pkg.ID.2 ]
[ $status -eq 0 ]
}
@test "should return KO status when packages are not found" {
# Given:
mocks_setup pkgutil
pkgutil_finds_package=no
# When:
run are_all_packages_installed com.example.Pkg.ID.1 com.example.Pkg.ID.7
# Then:
mocks_fetch_args
[ ${#args[@]} -eq 4 ]
[ "${args[0]}" == --pkg-info ]
[ "${args[1]}" == com.example.Pkg.ID.1 ]
[ "${args[2]}" == --pkg-info ]
[ "${args[3]}" == com.example.Pkg.ID.7 ]
[ ${#lines[@]} -eq 2 ]
[ $status -ne 0 ]
}
@test "should fail when packages are not found, telling the user which ones" {
# Given:
mocks_setup pkgutil
pkgutil_finds_package=no
# When:
run_with_muted_stdout are_all_packages_installed com.example.Pkg.ID.1 com.example.Pkg.ID.7
# Then:
mocks_fetch_args
[ ${#args[@]} -eq 4 ]
[ ${#lines[@]} -eq 2 ]
echo_actual_output
[[ "${lines[0]}" =~ $(echo "'com.example.Pkg.ID.1' .* not installed.* Aborting.") ]] && true || false
[[ "${lines[1]}" =~ $(echo "'com.example.Pkg.ID.7' .* not installed.* Aborting.") ]] && true || false
[ $status -ne 0 ]
}
# Local Variables:
# indent-tabs-mode: nil
# End: