apt-pkg 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'test_helper'
3
+
4
+ describe Debian::AptPkg::PkgCache do
5
+ describe 'not init' do
6
+ describe '.update' do
7
+ it 'can be called' do
8
+ _(lambda do
9
+ Debian::AptPkg::PkgCache.update
10
+ end).must_raise Debian::AptPkg::InitError
11
+ end
12
+ end
13
+
14
+ %i(package version depends package_file ver_file provides group).each do |m|
15
+ describe ".#{m}_count" do
16
+ it 'can be called' do
17
+ _(lambda do
18
+ Debian::AptPkg::PkgCache.public_send("#{m}_count")
19
+ end).must_raise Debian::AptPkg::InitError
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,78 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe Debian::AptPkg::Configuration do
4
+ before :all do
5
+ Debian::AptPkg.init
6
+ end
7
+
8
+ it 'architectures return an array' do
9
+ arches = Debian::AptPkg::Configuration.architectures
10
+ _(arches).must_be_instance_of Array
11
+ _(arches).wont_be_empty
12
+ end
13
+
14
+ it 'languages return an array' do
15
+ all_langs = Debian::AptPkg::Configuration.languages
16
+ _(all_langs).must_be_instance_of Array
17
+ _(all_langs).wont_be_empty
18
+
19
+ langs = Debian::AptPkg::Configuration.languages(false)
20
+ _(langs).must_be_instance_of Array
21
+ end
22
+
23
+ it 'check_architecture' do
24
+ _(Debian::AptPkg::Configuration.check_architecture('all')).must_equal true
25
+
26
+ arches = Debian::AptPkg::Configuration.architectures
27
+ c = Debian::AptPkg::Configuration.check_architecture(arches.first)
28
+ _(c).must_equal true
29
+
30
+ # http://buildd.debian-ports.org/status/fetch.php?pkg=ruby2.1&arch=m68k&ver=2.1.2-2&stamp=1400604298
31
+ _(Debian::AptPkg::Configuration.check_architecture('m68k')).must_equal false
32
+ end
33
+
34
+ it 'check_language' do
35
+ _(lambda do
36
+ Debian::AptPkg::Configuration.check_language
37
+ end).must_raise ArgumentError
38
+
39
+ langs = Debian::AptPkg::Configuration.languages
40
+ _(Debian::AptPkg::Configuration.check_language(langs.first)).must_equal true
41
+
42
+ c = Debian::AptPkg::Configuration.check_language('gallifreyan')
43
+ _(c).must_equal false
44
+ end
45
+
46
+ it 'compressors return an array' do
47
+ cmps = Debian::AptPkg::Configuration.compressors
48
+ _(cmps).must_be_instance_of Array
49
+ _(cmps).wont_be_empty
50
+ _(cmps).must_include 'gz'
51
+ end
52
+
53
+ it 'find configuration value' do
54
+ _(lambda do
55
+ Debian::AptPkg::Configuration.config_find
56
+ end).must_raise ArgumentError
57
+
58
+ _(Debian::AptPkg::Configuration.config_find('Dir::Etc::main'))
59
+ .must_equal 'apt.conf'
60
+ _(Debian::AptPkg::Configuration.config_find('Dir::Etc::netrc'))
61
+ .must_equal 'auth.conf'
62
+ _(Debian::AptPkg::Configuration.config_find('Dir::Etc::parts'))
63
+ .must_equal 'apt.conf.d'
64
+ _(Debian::AptPkg::Configuration.config_find('Spk', 'DebianUser'))
65
+ .must_equal 'DebianUser'
66
+ end
67
+
68
+ it 'find file' do
69
+ _(lambda do
70
+ Debian::AptPkg::Configuration.config_find_file
71
+ end).must_raise ArgumentError
72
+
73
+ _(Debian::AptPkg::Configuration.config_find_file('Dir::Etc::main'))
74
+ .must_equal '/etc/apt/apt.conf'
75
+ _(Debian::AptPkg::Configuration.config_find_file('Dir::Etc::netrc'))
76
+ .must_equal '/etc/apt/auth.conf'
77
+ end
78
+ end
@@ -0,0 +1,134 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe Debian::AptPkg do
4
+ it 'gem has a version number' do
5
+ refute_nil Debian::AptPkg::VERSION
6
+ end
7
+
8
+ it 'apt has a version number' do
9
+ refute_nil Debian::AptPkg::APT_VERSION
10
+ end
11
+
12
+ it 'libapt-pkg has a version number' do
13
+ refute_nil Debian::AptPkg::LIBAPT_PKG_VERSION
14
+ end
15
+
16
+ describe '.init' do
17
+ it 'returns a bool' do
18
+ _(Debian::AptPkg.init).must_equal true
19
+ end
20
+ end
21
+
22
+ describe '.cmp_version' do
23
+ it 'compare version' do
24
+ _(Debian::AptPkg.cmp_version('1.1', '1.0')).must_be :>, 0
25
+ _(Debian::AptPkg.cmp_version('1.0', '1.0')).must_be :==, 0
26
+ _(Debian::AptPkg.cmp_version('1.0', '1.1')).must_be :<, 0
27
+ end
28
+ end
29
+
30
+ describe '.check_dep' do
31
+ describe 'LessEq' do
32
+ it 'compare Debian version' do
33
+ _(Debian::AptPkg.check_dep('1', '<=', '2')).must_equal true
34
+ _(Debian::AptPkg.check_dep('2', '<=', '1')).must_equal false
35
+ _(Debian::AptPkg.check_dep('1', '<=', '1')).must_equal true
36
+ end
37
+ end
38
+
39
+ describe 'GreaterEq' do
40
+ it 'compare Debian version' do
41
+ _(Debian::AptPkg.check_dep('1', '>=', '2')).must_equal false
42
+ _(Debian::AptPkg.check_dep('2', '>=', '1')).must_equal true
43
+ _(Debian::AptPkg.check_dep('1', '>=', '1')).must_equal true
44
+ end
45
+ end
46
+
47
+ describe 'Less' do
48
+ it 'compare Debian version' do
49
+ _(Debian::AptPkg.check_dep('1', '<', '2')).must_equal true
50
+ _(Debian::AptPkg.check_dep('2', '<', '1')).must_equal false
51
+ _(Debian::AptPkg.check_dep('1', '<', '1')).must_equal false
52
+ end
53
+ end
54
+
55
+ describe 'Greater' do
56
+ it 'compare Debian version' do
57
+ _(Debian::AptPkg.check_dep('1', '>', '2')).must_equal false
58
+ _(Debian::AptPkg.check_dep('2', '>', '1')).must_equal true
59
+ _(Debian::AptPkg.check_dep('1', '>', '1')).must_equal false
60
+ end
61
+ end
62
+
63
+ describe 'Equals' do
64
+ it 'compare Debian version' do
65
+ _(Debian::AptPkg.check_dep('1', '=', '2')).must_equal false
66
+ _(Debian::AptPkg.check_dep('2', '=', '1')).must_equal false
67
+ _(Debian::AptPkg.check_dep('1', '=', '1')).must_equal true
68
+ end
69
+ end
70
+
71
+ describe 'NotEquals' do
72
+ it 'compare Debian version' do
73
+ _(Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '2'))
74
+ .must_equal true
75
+ _(Debian::AptPkg.check_dep('2', Debian::AptPkg::NOT_EQUALS, '1'))
76
+ .must_equal true
77
+ _(Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '1'))
78
+ .must_equal false
79
+ end
80
+ end
81
+
82
+ describe 'Errors' do
83
+ it 'raise argument error with bad comparison' do
84
+ _(lambda do
85
+ Debian::AptPkg.check_dep('1', 'bad', '2')
86
+ end).must_raise ArgumentError
87
+ end
88
+ end
89
+ end
90
+
91
+ describe '.uri_to_filename' do
92
+ it 'return a filename which can be used to store the file' do
93
+ _(Debian::AptPkg.uri_to_filename('http://debian.org/index.html'))
94
+ .must_equal 'debian.org_index.html'
95
+ end
96
+ end
97
+
98
+ describe '.upstream_version' do
99
+ it 'Return the upstream version for the Debian package version' do
100
+ _(Debian::AptPkg.upstream_version('3.4.15-1+b1')).must_equal '3.4.15'
101
+ end
102
+ end
103
+
104
+ describe '.time_to_str' do
105
+ it 'Format a given duration in human-readable manner' do
106
+ _(Debian::AptPkg.time_to_str(3601)).must_equal '1h 0min 1s'
107
+ end
108
+ end
109
+
110
+ describe '.size_to_str' do
111
+ it 'Return a string describing the size in a human-readable manner' do
112
+ _(Debian::AptPkg.size_to_str(10_000)).must_equal '10.0 k'
113
+ end
114
+ end
115
+
116
+ describe '.string_to_bool' do
117
+ it 'Parse the string input and return a boolean' do
118
+ _(Debian::AptPkg.string_to_bool('yes')).must_equal true
119
+ _(Debian::AptPkg.string_to_bool('no')).must_equal false
120
+ _(Debian::AptPkg.string_to_bool('no-recognized')).must_equal false
121
+ end
122
+ end
123
+
124
+ describe '.check_domain_list' do
125
+ it 'See if the host name given by host is one of the domains given' do
126
+ _(Debian::AptPkg.check_domain_list('alioth.debian.org',
127
+ 'debian.net,debian.org'))
128
+ .must_equal true
129
+ _(Debian::AptPkg.check_domain_list('git.debian.org',
130
+ 'spkdev.net'))
131
+ .must_equal false
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../../test_helper'
3
+
4
+ describe Debian::AptPkg::Package do
5
+ let(:id) { 42 }
6
+ let(:pkg_name) { "ed" }
7
+ let(:full_name) { "ed:i386" }
8
+ let(:arch) { "i386" }
9
+ let(:essential) { false }
10
+ let(:important) { false }
11
+ let(:current_version) { nil }
12
+
13
+ describe '.new' do
14
+ describe 'with correct number of arguments' do
15
+ it 'can initialize a Package class' do
16
+ Debian::AptPkg::Package.new(id, pkg_name, full_name, arch,
17
+ essential, important, current_version)
18
+ end
19
+ end
20
+
21
+ describe 'with wrong number of arguments' do
22
+ it 'cannot initialize a Package class' do
23
+ _(lambda do
24
+ Debian::AptPkg::Package.new(id, pkg_name, full_name, arch,
25
+ essential, important)
26
+ end).must_raise ArgumentError
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#is_installed' do
32
+ subject do
33
+ Debian::AptPkg::Package.new(id, pkg_name, full_name, arch,
34
+ essential, important,
35
+ current_version).is_installed
36
+ end
37
+
38
+ describe 'when current_version is present' do
39
+ let(:current_version) do
40
+ Debian::AptPkg::Version.new("ed", "1", "editors", "i386", 0, 0, 0, 0, 4)
41
+ end
42
+
43
+ it 'returns true' do
44
+ _(subject).must_equal true
45
+ end
46
+ end
47
+
48
+ describe 'when current_version is not present' do
49
+ let(:current_version) { nil }
50
+
51
+ it 'returns false' do
52
+ _(subject).must_equal false
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../../test_helper'
3
+
4
+ describe Debian::AptPkg::PkgCache do
5
+ before :all do
6
+ Debian::AptPkg.init
7
+ end
8
+
9
+ describe '.update' do
10
+ it 'can be called' do
11
+ Debian::AptPkg::PkgCache.update
12
+ end
13
+ end
14
+
15
+ describe '.gen_caches' do
16
+ it 'return boolean' do
17
+ if Process.uid == 0
18
+ _(Debian::AptPkg::PkgCache.gen_caches).must_equal true
19
+ else
20
+ _(Debian::AptPkg::PkgCache.gen_caches).must_equal false
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '.is_multi_arch' do
26
+ it 'can be called' do
27
+ Debian::AptPkg::PkgCache.is_multi_arch
28
+ end
29
+ end
30
+
31
+ describe '.packages' do
32
+ it 'returns an array of Package' do
33
+ packages = Debian::AptPkg::PkgCache.packages
34
+ _(packages).must_be_kind_of Array
35
+ _(packages.first).must_be_kind_of Debian::AptPkg::Package
36
+ libapt = packages.find { |pkg| pkg.name == 'libapt-pkg-dev' }
37
+ _(libapt.id).must_be_kind_of Numeric
38
+ _(libapt.name).must_equal 'libapt-pkg-dev'
39
+ _(libapt.full_name).must_match(/libapt-pkg-dev:(\w)/)
40
+ _(libapt.arch).must_match(/(\w)/)
41
+ _([true, false]).must_include libapt.essential
42
+ _([true, false]).must_include libapt.important
43
+ _(libapt.current_version).must_be_kind_of Debian::AptPkg::Version
44
+ _(libapt.current_version.parent_package_name).must_equal libapt.name
45
+ _(libapt.current_version.version_string).must_be_kind_of String
46
+ _(libapt.current_version.section).must_equal 'libdevel'
47
+ _(libapt.current_version.arch).must_equal libapt.arch
48
+ _(libapt.current_version.size).must_be_kind_of Numeric
49
+ _(libapt.current_version.installed_size).must_be_kind_of Numeric
50
+ _(libapt.current_version.hash).must_be_kind_of Numeric
51
+ _(libapt.current_version.id).must_be_kind_of Numeric
52
+ _(libapt.current_version.priority).must_be_kind_of Numeric
53
+ end
54
+ end
55
+
56
+ describe '.pkg_names' do
57
+ it 'is deprecated' do
58
+ out, err = capture_io do
59
+ Debian::AptPkg::PkgCache.pkg_names('libapt-pkg-dev')
60
+ end
61
+ _(out).must_equal ''
62
+ regexp = /warning:\sDebian::AptPkg::PkgCache\.pkg_names\sis\sdeprecated;\s
63
+ use\sDebian::AptPkg::PkgCache\.packages\sinstead/x
64
+ _(err).must_match(regexp)
65
+ end
66
+
67
+ it 'no argument' do
68
+ _(lambda do
69
+ capture_io do
70
+ Debian::AptPkg::PkgCache.pkg_names
71
+ end
72
+ end).must_raise ArgumentError
73
+ end
74
+
75
+ it 'nil argument' do
76
+ _(lambda do
77
+ capture_io do
78
+ Debian::AptPkg::PkgCache.pkg_names(nil)
79
+ end
80
+ end).must_raise ArgumentError
81
+ end
82
+
83
+ it 'blank argument' do
84
+ _(lambda do
85
+ capture_io do
86
+ Debian::AptPkg::PkgCache.pkg_names('')
87
+ end
88
+ end).must_raise ArgumentError
89
+ end
90
+
91
+ it 'be filtered' do
92
+ capture_io do
93
+ search = Debian::AptPkg::PkgCache.pkg_names('vim')
94
+ # CI specific cache can not be present
95
+ unless search.nil? || search.empty?
96
+ _(search).must_include 'vim'
97
+ _(search).must_include 'vim-nox'
98
+ _(search).must_include 'vim-gtk'
99
+ _(search).wont_include 'emacs'
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ %i(package version depends package_file ver_file provides group).each do |m|
106
+ describe ".#{m}_count" do
107
+ it 'return an int' do
108
+ if Process.uid == 0
109
+ _(Debian::AptPkg::PkgCache.public_send("#{m}_count")).must_be :>=, 0
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,6 @@
1
+ $VERBOSE = true
2
+ require 'minitest/autorun'
3
+ require 'minitest/pride'
4
+ require 'pp'
5
+
6
+ require_relative '../lib/debian/apt_pkg'
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apt-pkg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Laurent Arnoud
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake-compiler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.13'
55
+ description: Ruby interface to apt-pkg
56
+ email: laurent@spkdev.net
57
+ executables: []
58
+ extensions:
59
+ - ext/apt_pkg/extconf.rb
60
+ extra_rdoc_files:
61
+ - History.md
62
+ - README.md
63
+ - ext/apt_pkg/configuration.cpp
64
+ - ext/apt_pkg/apt-pkg.cpp
65
+ - ext/apt_pkg/pkgcache.cpp
66
+ files:
67
+ - Gemfile
68
+ - History.md
69
+ - LICENSE
70
+ - README.md
71
+ - ext/apt_pkg/apt-pkg.cpp
72
+ - ext/apt_pkg/apt-pkg.h
73
+ - ext/apt_pkg/configuration.cpp
74
+ - ext/apt_pkg/configuration.h
75
+ - ext/apt_pkg/extconf.rb
76
+ - ext/apt_pkg/pkgcache.cpp
77
+ - ext/apt_pkg/pkgcache.h
78
+ - lib/debian/apt_pkg.rb
79
+ - lib/debian/apt_pkg/gem_version.rb
80
+ - lib/debian/apt_pkg/package.rb
81
+ - test/apt_pkg_cache_not_init_integration.rb
82
+ - test/apt_pkg_configuration_test.rb
83
+ - test/apt_pkg_test.rb
84
+ - test/debian/apt_pkg/package_test.rb
85
+ - test/debian/apt_pkg/pkg_cache_test.rb
86
+ - test/test_helper.rb
87
+ homepage: http://github.com/spk/ruby-apt-pkg
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options:
93
+ - "--charset=UTF-8"
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.1.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Ruby interface to libapt-pkg
111
+ test_files: []