-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapt_pkg_test.rb
134 lines (116 loc) · 4.16 KB
/
apt_pkg_test.rb
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
125
126
127
128
129
130
131
132
133
134
require_relative 'test_helper'
describe Debian::AptPkg do
it 'gem has a version number' do
refute_nil Debian::AptPkg::VERSION
end
it 'apt has a version number' do
refute_nil Debian::AptPkg::APT_VERSION
end
it 'libapt-pkg has a version number' do
refute_nil Debian::AptPkg::LIBAPT_PKG_VERSION
end
describe '.init' do
it 'returns a bool' do
_(Debian::AptPkg.init).must_equal true
end
end
describe '.cmp_version' do
it 'compare version' do
_(Debian::AptPkg.cmp_version('1.1', '1.0')).must_be :>, 0
_(Debian::AptPkg.cmp_version('1.0', '1.0')).must_be :==, 0
_(Debian::AptPkg.cmp_version('1.0', '1.1')).must_be :<, 0
end
end
describe '.check_dep' do
describe 'LessEq' do
it 'compare Debian version' do
_(Debian::AptPkg.check_dep('1', '<=', '2')).must_equal true
_(Debian::AptPkg.check_dep('2', '<=', '1')).must_equal false
_(Debian::AptPkg.check_dep('1', '<=', '1')).must_equal true
end
end
describe 'GreaterEq' do
it 'compare Debian version' do
_(Debian::AptPkg.check_dep('1', '>=', '2')).must_equal false
_(Debian::AptPkg.check_dep('2', '>=', '1')).must_equal true
_(Debian::AptPkg.check_dep('1', '>=', '1')).must_equal true
end
end
describe 'Less' do
it 'compare Debian version' do
_(Debian::AptPkg.check_dep('1', '<', '2')).must_equal true
_(Debian::AptPkg.check_dep('2', '<', '1')).must_equal false
_(Debian::AptPkg.check_dep('1', '<', '1')).must_equal false
end
end
describe 'Greater' do
it 'compare Debian version' do
_(Debian::AptPkg.check_dep('1', '>', '2')).must_equal false
_(Debian::AptPkg.check_dep('2', '>', '1')).must_equal true
_(Debian::AptPkg.check_dep('1', '>', '1')).must_equal false
end
end
describe 'Equals' do
it 'compare Debian version' do
_(Debian::AptPkg.check_dep('1', '=', '2')).must_equal false
_(Debian::AptPkg.check_dep('2', '=', '1')).must_equal false
_(Debian::AptPkg.check_dep('1', '=', '1')).must_equal true
end
end
describe 'NotEquals' do
it 'compare Debian version' do
_(Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '2'))
.must_equal true
_(Debian::AptPkg.check_dep('2', Debian::AptPkg::NOT_EQUALS, '1'))
.must_equal true
_(Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '1'))
.must_equal false
end
end
describe 'Errors' do
it 'raise argument error with bad comparison' do
_(lambda do
Debian::AptPkg.check_dep('1', 'bad', '2')
end).must_raise ArgumentError
end
end
end
describe '.uri_to_filename' do
it 'return a filename which can be used to store the file' do
_(Debian::AptPkg.uri_to_filename('http://debian.org/index.html'))
.must_equal 'debian.org_index.html'
end
end
describe '.upstream_version' do
it 'Return the upstream version for the Debian package version' do
_(Debian::AptPkg.upstream_version('3.4.15-1+b1')).must_equal '3.4.15'
end
end
describe '.time_to_str' do
it 'Format a given duration in human-readable manner' do
_(Debian::AptPkg.time_to_str(3601)).must_equal '1h 0min 1s'
end
end
describe '.size_to_str' do
it 'Return a string describing the size in a human-readable manner' do
_(Debian::AptPkg.size_to_str(10_000)).must_equal '10.0 k'
end
end
describe '.string_to_bool' do
it 'Parse the string input and return a boolean' do
_(Debian::AptPkg.string_to_bool('yes')).must_equal true
_(Debian::AptPkg.string_to_bool('no')).must_equal false
_(Debian::AptPkg.string_to_bool('no-recognized')).must_equal false
end
end
describe '.check_domain_list' do
it 'See if the host name given by host is one of the domains given' do
_(Debian::AptPkg.check_domain_list('alioth.debian.org',
'debian.net,debian.org'))
.must_equal true
_(Debian::AptPkg.check_domain_list('git.debian.org',
'spkdev.net'))
.must_equal false
end
end
end