dk-pkg 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dk-pkg.gemspec +4 -1
- data/lib/dk-pkg.rb +5 -4
- data/lib/dk-pkg/constants.rb +11 -0
- data/lib/dk-pkg/install_pkg.rb +83 -0
- data/lib/dk-pkg/manifest.rb +27 -0
- data/lib/dk-pkg/validate.rb +55 -0
- data/lib/dk-pkg/version.rb +1 -1
- data/test/support/factory.rb +5 -0
- data/test/unit/dk-pkg_tests.rb +26 -0
- data/test/unit/install_pkg_tests.rb +162 -0
- data/test/unit/manifest_tests.rb +63 -0
- data/test/unit/validate_tests.rb +197 -0
- metadata +37 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
|
4
|
-
|
3
|
+
metadata.gz: 11771e7a75edaca8db188e72bd1227074b519b40
|
4
|
+
data.tar.gz: bacebe6f8f0ef66f8338ac97326ea98e9df23b46
|
5
5
|
SHA512:
|
6
|
-
|
7
|
-
|
6
|
+
metadata.gz: f00bd74d6913fc2511fd86c71599285b544ea1309f24e426d253b3f59890320f1a7e512d7502dcdadd1f484689d989772d2cc6ff2ab16f84d63851bb0d3c637a
|
7
|
+
data.tar.gz: 7144274536ee8403fc32138e20339881cdcefa82a65db83d3cc89d97cd17d6a955cdbc30c5c932d00bafb067292fe87edd527d52f5d196090c7e37848608dbc3
|
data/dk-pkg.gemspec
CHANGED
@@ -18,6 +18,9 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.add_development_dependency("assert", ["~> 2.16.
|
21
|
+
gem.add_development_dependency("assert", ["~> 2.16.3"])
|
22
|
+
|
23
|
+
gem.add_dependency("dk", ["~> 0.1.0"])
|
24
|
+
gem.add_dependency("much-plugin", ["~> 0.2.0"])
|
22
25
|
|
23
26
|
end
|
data/lib/dk-pkg.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
module Dk; end
|
2
|
+
module Dk::Pkg
|
3
|
+
|
4
|
+
MANIFEST_PATH_PARAM_NAME = 'dk_pkg_manifest_path'.freeze
|
5
|
+
MANIFEST_MODE_PARAM_NAME = 'dk_pkg_manifest_mode'.freeze
|
6
|
+
MANIFEST_OWNER_PARAM_NAME = 'dk_pkg_manifest_owner'.freeze
|
7
|
+
INSTALLED_PKGS_PARAM_NAME = 'dk_pkg_installed_pkgs'.freeze
|
8
|
+
|
9
|
+
MANIFEST_SEPARATOR = "\n".freeze
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'dk/task'
|
2
|
+
require 'much-plugin'
|
3
|
+
require 'dk-pkg/constants'
|
4
|
+
require 'dk-pkg/validate'
|
5
|
+
|
6
|
+
module Dk::Pkg
|
7
|
+
|
8
|
+
module InstallPkg
|
9
|
+
include MuchPlugin
|
10
|
+
|
11
|
+
WRITE_MANIFEST_CMD_STR_PROC = proc{ |manifest_path| "tee #{manifest_path}" }
|
12
|
+
|
13
|
+
plugin_included do
|
14
|
+
include Dk::Task
|
15
|
+
include InstanceMethods
|
16
|
+
|
17
|
+
before Dk::Pkg::Validate
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
module InstanceMethods
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def install_pkg(name)
|
26
|
+
raise(ArgumentError, "a pkg name must be provided") if name.to_s.empty?
|
27
|
+
raise(ArgumentError, "no block given") unless block_given?
|
28
|
+
|
29
|
+
if !params[INSTALLED_PKGS_PARAM_NAME].include?(name)
|
30
|
+
yield
|
31
|
+
dk_pkg_write_pkg_to_manifest(name)
|
32
|
+
else
|
33
|
+
log_info "#{name.inspect} has already been installed"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def dk_pkg_write_pkg_to_manifest(name)
|
38
|
+
pkgs = params[INSTALLED_PKGS_PARAM_NAME] + [name]
|
39
|
+
serialized_pkgs = Manifest.serialize(pkgs)
|
40
|
+
cmd!(
|
41
|
+
WRITE_MANIFEST_CMD_STR_PROC.call(params[MANIFEST_PATH_PARAM_NAME]),
|
42
|
+
serialized_pkgs
|
43
|
+
)
|
44
|
+
set_param INSTALLED_PKGS_PARAM_NAME, Manifest.deserialize(serialized_pkgs)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
module TestHelpers
|
50
|
+
include MuchPlugin
|
51
|
+
|
52
|
+
plugin_included do
|
53
|
+
include Dk::Pkg::Validate::TestHelpers
|
54
|
+
include InstanceMethods
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
module InstanceMethods
|
59
|
+
|
60
|
+
def assert_dk_pkg_installed(test_runner, pkg_name)
|
61
|
+
assert_includes pkg_name, test_runner.params[INSTALLED_PKGS_PARAM_NAME]
|
62
|
+
end
|
63
|
+
|
64
|
+
def non_dk_install_pkg_runs(test_runner, test_runner_runs)
|
65
|
+
manifest_path = test_runner.params[MANIFEST_PATH_PARAM_NAME]
|
66
|
+
write_manifest_cmd_str = WRITE_MANIFEST_CMD_STR_PROC.call(manifest_path)
|
67
|
+
|
68
|
+
test_runner_runs.reject do |run|
|
69
|
+
validate_task_run = run.kind_of?(Dk::TaskRun) &&
|
70
|
+
run.task_class == Dk::Pkg::Validate
|
71
|
+
write_manifest_cmd = run.kind_of?(Dk::Local::CmdSpy) &&
|
72
|
+
run.cmd_str == write_manifest_cmd_str
|
73
|
+
validate_task_run || write_manifest_cmd
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'dk-pkg/constants'
|
2
|
+
|
3
|
+
module Dk::Pkg
|
4
|
+
|
5
|
+
module Manifest
|
6
|
+
|
7
|
+
def self.serialize(pkgs)
|
8
|
+
raise ArgumentError, "pkgs must be an array" if !pkgs.kind_of?(Array)
|
9
|
+
sanitize_array(pkgs).join(MANIFEST_SEPARATOR)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.deserialize(serialized_pkgs)
|
13
|
+
if !serialized_pkgs.kind_of?(String)
|
14
|
+
raise ArgumentError, "serialized pkgs must be a string"
|
15
|
+
end
|
16
|
+
sanitize_array(serialized_pkgs.split(MANIFEST_SEPARATOR))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.sanitize_array(array)
|
22
|
+
array.compact.uniq.map(&:to_s).reject(&:empty?).sort
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'dk/task'
|
2
|
+
require 'dk-pkg/constants'
|
3
|
+
require 'dk-pkg/manifest'
|
4
|
+
|
5
|
+
module Dk::Pkg
|
6
|
+
|
7
|
+
class Validate
|
8
|
+
include Dk::Task
|
9
|
+
|
10
|
+
desc "(dk-pkg) validate the required dk-pkg params"
|
11
|
+
|
12
|
+
run_only_once true
|
13
|
+
|
14
|
+
def run!
|
15
|
+
# validate that a manifest path has been set, so we can parse it
|
16
|
+
if params[MANIFEST_PATH_PARAM_NAME].to_s.empty?
|
17
|
+
raise ArgumentError, "no #{MANIFEST_PATH_PARAM_NAME.inspect} param set"
|
18
|
+
end
|
19
|
+
|
20
|
+
if !cmd("test -e #{params[MANIFEST_PATH_PARAM_NAME]}").success?
|
21
|
+
cmd! "touch #{params[MANIFEST_PATH_PARAM_NAME]}"
|
22
|
+
if param?(MANIFEST_MODE_PARAM_NAME)
|
23
|
+
cmd! "chmod #{params[MANIFEST_MODE_PARAM_NAME]} " \
|
24
|
+
"#{params[MANIFEST_PATH_PARAM_NAME]}"
|
25
|
+
end
|
26
|
+
if param?(MANIFEST_OWNER_PARAM_NAME)
|
27
|
+
cmd! "chown #{params[MANIFEST_OWNER_PARAM_NAME]} " \
|
28
|
+
"#{params[MANIFEST_PATH_PARAM_NAME]}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
serialized_pkgs = cmd!("cat #{params[MANIFEST_PATH_PARAM_NAME]}").stdout
|
32
|
+
set_param INSTALLED_PKGS_PARAM_NAME, Manifest.deserialize(serialized_pkgs)
|
33
|
+
end
|
34
|
+
|
35
|
+
module TestHelpers
|
36
|
+
include MuchPlugin
|
37
|
+
|
38
|
+
plugin_included do
|
39
|
+
include Dk::Task::TestHelpers
|
40
|
+
|
41
|
+
setup do
|
42
|
+
@dk_pkg_installed_pkgs ||= []
|
43
|
+
|
44
|
+
@params ||= {}
|
45
|
+
@params[MANIFEST_PATH_PARAM_NAME] ||= Factory.file_path
|
46
|
+
@params[INSTALLED_PKGS_PARAM_NAME] ||= @dk_pkg_installed_pkgs
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/lib/dk-pkg/version.rb
CHANGED
data/test/support/factory.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'dk-pkg'
|
3
|
+
|
4
|
+
module Dk::Pkg
|
5
|
+
|
6
|
+
class UnitTests < Assert::Context
|
7
|
+
desc "Dk::Pkg"
|
8
|
+
setup do
|
9
|
+
@module = Dk::Pkg
|
10
|
+
end
|
11
|
+
subject{ @module }
|
12
|
+
|
13
|
+
should "know its param names" do
|
14
|
+
assert_equal 'dk_pkg_manifest_path', MANIFEST_PATH_PARAM_NAME
|
15
|
+
assert_equal 'dk_pkg_manifest_mode', MANIFEST_MODE_PARAM_NAME
|
16
|
+
assert_equal 'dk_pkg_manifest_owner', MANIFEST_OWNER_PARAM_NAME
|
17
|
+
assert_equal 'dk_pkg_installed_pkgs', INSTALLED_PKGS_PARAM_NAME
|
18
|
+
end
|
19
|
+
|
20
|
+
should "know its manifest separator" do
|
21
|
+
assert_equal "\n", MANIFEST_SEPARATOR
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'dk-pkg/install_pkg'
|
3
|
+
|
4
|
+
require 'dk/task'
|
5
|
+
require 'much-plugin'
|
6
|
+
require 'dk-pkg/constants'
|
7
|
+
require 'dk-pkg/validate'
|
8
|
+
|
9
|
+
module Dk::Pkg::InstallPkg
|
10
|
+
|
11
|
+
class UnitTests < Assert::Context
|
12
|
+
include Dk::Pkg::Validate::TestHelpers
|
13
|
+
|
14
|
+
desc "Dk::Pkg::InstallPkg"
|
15
|
+
subject{ Dk::Pkg::InstallPkg }
|
16
|
+
|
17
|
+
should "use much-plugin" do
|
18
|
+
assert_includes MuchPlugin, subject
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class MixinTests < UnitTests
|
24
|
+
desc "mixin"
|
25
|
+
setup do
|
26
|
+
@task_class = Class.new{ include Dk::Pkg::InstallPkg }
|
27
|
+
end
|
28
|
+
subject{ @task_class }
|
29
|
+
|
30
|
+
should "be a Dk task" do
|
31
|
+
assert_includes Dk::Task, subject
|
32
|
+
end
|
33
|
+
|
34
|
+
should "run the Validate task as a before callback" do
|
35
|
+
assert_equal [Dk::Pkg::Validate], subject.before_callback_task_classes
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class InitTests < MixinTests
|
41
|
+
desc "when init"
|
42
|
+
setup do
|
43
|
+
@task_class.class_eval do
|
44
|
+
def run!
|
45
|
+
install_pkg params['pkg-name'] do
|
46
|
+
set_param 'install-pkg-yielded', true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
@params['pkg-name'] = Factory.string
|
51
|
+
@params['install-pkg-yielded'] = false
|
52
|
+
|
53
|
+
@runner = test_runner(@task_class, :params => @params)
|
54
|
+
end
|
55
|
+
subject{ @runner }
|
56
|
+
|
57
|
+
should "provide an install pkg helper" do
|
58
|
+
subject.run
|
59
|
+
|
60
|
+
assert_true subject.params['install-pkg-yielded']
|
61
|
+
# there will always be +1 because of the Validate task being run
|
62
|
+
assert_equal 2, subject.runs.size
|
63
|
+
tee_cmd = subject.runs.last
|
64
|
+
exp = "tee #{@params[Dk::Pkg::MANIFEST_PATH_PARAM_NAME]}"
|
65
|
+
assert_equal exp, tee_cmd.cmd_str
|
66
|
+
|
67
|
+
exp_pkgs = [@params['pkg-name']]
|
68
|
+
assert_equal Dk::Pkg::Manifest.serialize(exp_pkgs), tee_cmd.run_input
|
69
|
+
|
70
|
+
assert_equal exp_pkgs, subject.params[Dk::Pkg::INSTALLED_PKGS_PARAM_NAME]
|
71
|
+
end
|
72
|
+
|
73
|
+
should "not yield or run any commands if the pkg is already installed" do
|
74
|
+
@params[Dk::Pkg::INSTALLED_PKGS_PARAM_NAME] << @params['pkg-name']
|
75
|
+
runner = test_runner(@task_class, :params => @params)
|
76
|
+
runner.run
|
77
|
+
|
78
|
+
assert_false runner.params['install-pkg-yielded']
|
79
|
+
# there will always be +1 because of the Validate task being run
|
80
|
+
assert_equal 1, runner.runs.size
|
81
|
+
end
|
82
|
+
|
83
|
+
should "complain if passed invalid args" do
|
84
|
+
assert_raises(ArgumentError) do
|
85
|
+
subject.task.instance_eval{ install_pkg([nil, ''].sample){ } }
|
86
|
+
end
|
87
|
+
assert_raises(ArgumentError) do
|
88
|
+
subject.task.instance_eval{ install_pkg(Factory.string) }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
class TestHelpersTests < UnitTests
|
95
|
+
desc "TestHelpers"
|
96
|
+
setup do
|
97
|
+
@task_class = Class.new do
|
98
|
+
include Dk::Pkg::InstallPkg
|
99
|
+
|
100
|
+
def run!
|
101
|
+
params['pkgs'].each do |(pkg_name, pkg_cmd)|
|
102
|
+
install_pkg(pkg_name){ cmd(pkg_cmd) }
|
103
|
+
end
|
104
|
+
run_task TestTask
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# use an array of tuples so we don't have to worry about hash randomly
|
109
|
+
# ordering its key/values when testing
|
110
|
+
@params['pkgs'] = Factory.integer(3).times.map do
|
111
|
+
[Factory.string, Factory.string]
|
112
|
+
end
|
113
|
+
@runner = test_runner(@task_class, :params => @params)
|
114
|
+
@runner.run
|
115
|
+
|
116
|
+
@context_class = Class.new do
|
117
|
+
def self.setup(&block); end # needed for `Dk::Pkg::Validate::TestHelpers`
|
118
|
+
include Dk::Pkg::InstallPkg::TestHelpers
|
119
|
+
|
120
|
+
def initialize(assert_context)
|
121
|
+
@assert_context = assert_context
|
122
|
+
end
|
123
|
+
|
124
|
+
# needed to test `assert_dk_pkg_installed`
|
125
|
+
def assert_includes(*args)
|
126
|
+
@assert_context.assert_includes(*args)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
@context = @context_class.new(self)
|
130
|
+
end
|
131
|
+
subject{ @context }
|
132
|
+
|
133
|
+
should have_imeths :assert_dk_pkg_installed, :non_dk_install_pkg_runs
|
134
|
+
|
135
|
+
should "use much-plugin" do
|
136
|
+
assert_includes MuchPlugin, Dk::Pkg::InstallPkg::TestHelpers
|
137
|
+
end
|
138
|
+
|
139
|
+
should "include dk-pkg Validate test helpers" do
|
140
|
+
assert_includes Dk::Pkg::Validate::TestHelpers, @context_class
|
141
|
+
end
|
142
|
+
|
143
|
+
should "provide a helper for asserting a pkg was installed" do
|
144
|
+
@params['pkgs'].each do |pkg_name, pkg_cmd|
|
145
|
+
subject.assert_dk_pkg_installed(@runner, pkg_name)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
should "know how to select non dk-pkg install pkg runs" do
|
150
|
+
runs = subject.non_dk_install_pkg_runs(@runner, @runner.runs)
|
151
|
+
assert_not_equal runs, @runner.runs
|
152
|
+
assert_equal @params['pkgs'].size + 1, runs.size
|
153
|
+
cmd_runs = runs[0, @params['pkgs'].size]
|
154
|
+
assert_equal @params['pkgs'].map(&:last), cmd_runs.map(&:cmd_str)
|
155
|
+
assert_equal TestTask, runs.last.task_class
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
TestTask = Class.new{ include Dk::Task }
|
161
|
+
|
162
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'dk-pkg/manifest'
|
3
|
+
|
4
|
+
require 'dk-pkg/constants'
|
5
|
+
|
6
|
+
module Dk::Pkg::Manifest
|
7
|
+
|
8
|
+
class UnitTests < Assert::Context
|
9
|
+
desc "Dk::Pkg::Manifest"
|
10
|
+
setup do
|
11
|
+
@pkgs = Factory.manifest_pkgs
|
12
|
+
end
|
13
|
+
subject{ Dk::Pkg::Manifest }
|
14
|
+
|
15
|
+
should have_imeths :serialize, :deserialize
|
16
|
+
|
17
|
+
should "know how to serialize and deserialize" do
|
18
|
+
exp = @pkgs.join(Dk::Pkg::MANIFEST_SEPARATOR)
|
19
|
+
serialized_pkgs = subject.serialize(@pkgs)
|
20
|
+
assert_equal exp, serialized_pkgs
|
21
|
+
assert_equal @pkgs, subject.deserialize(serialized_pkgs)
|
22
|
+
end
|
23
|
+
|
24
|
+
should "clean pkg names using serialize/deserialize" do
|
25
|
+
valid_pkgs = Factory.manifest_pkgs.shuffle # randomize their order
|
26
|
+
non_string_pkgs = [Factory.integer, Factory.boolean, Factory.float]
|
27
|
+
duplicate_pkg = Factory.string
|
28
|
+
pkgs = valid_pkgs +
|
29
|
+
non_string_pkgs + # add non strings
|
30
|
+
([duplicate_pkg] * Factory.integer(3)) + # add duplicates
|
31
|
+
([nil] * Factory.integer(3)) + # add `nil` packages
|
32
|
+
([""] * Factory.integer(3)) # add empty string packages
|
33
|
+
serialized_pkgs = pkgs.shuffle.join(Dk::Pkg::MANIFEST_SEPARATOR)
|
34
|
+
|
35
|
+
exp_pkgs = (valid_pkgs + non_string_pkgs + [duplicate_pkg]).map(&:to_s).sort
|
36
|
+
exp_serialized_pkgs = exp_pkgs.join(Dk::Pkg::MANIFEST_SEPARATOR)
|
37
|
+
|
38
|
+
assert_equal exp_serialized_pkgs, subject.serialize(pkgs)
|
39
|
+
assert_equal exp_pkgs, subject.deserialize(serialized_pkgs)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "handle special cases using serialize/deserialize" do
|
43
|
+
# a single item
|
44
|
+
pkg = Factory.string
|
45
|
+
assert_equal pkg, subject.serialize([pkg])
|
46
|
+
assert_equal [pkg], subject.deserialize(pkg)
|
47
|
+
|
48
|
+
assert_equal "", subject.serialize([])
|
49
|
+
assert_equal [], subject.deserialize("")
|
50
|
+
end
|
51
|
+
|
52
|
+
should "complain if serialize/deserialize is passed invalid args" do
|
53
|
+
assert_raises(ArgumentError){ subject.serialize(nil) }
|
54
|
+
assert_raises(ArgumentError){ subject.serialize(Factory.string) }
|
55
|
+
|
56
|
+
assert_raises(ArgumentError){ subject.deserialize(nil) }
|
57
|
+
array = Factory.integer(3).times.map{ Factory.string }
|
58
|
+
assert_raises(ArgumentError){ subject.deserialize(array) }
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'dk-pkg/validate'
|
3
|
+
|
4
|
+
require 'dk/task'
|
5
|
+
require 'dk-pkg/constants'
|
6
|
+
require 'dk-pkg/manifest'
|
7
|
+
|
8
|
+
class Dk::Pkg::Validate
|
9
|
+
|
10
|
+
class UnitTests < Assert::Context
|
11
|
+
desc "Dk::Pkg::Validate"
|
12
|
+
setup do
|
13
|
+
@task_class = Dk::Pkg::Validate
|
14
|
+
end
|
15
|
+
subject{ @task_class }
|
16
|
+
|
17
|
+
should "be a Dk task" do
|
18
|
+
assert_includes Dk::Task, subject
|
19
|
+
end
|
20
|
+
|
21
|
+
should "know its description" do
|
22
|
+
exp = "(dk-pkg) validate the required dk-pkg params"
|
23
|
+
assert_equal exp, subject.description
|
24
|
+
end
|
25
|
+
|
26
|
+
should "only run once" do
|
27
|
+
assert_true subject.run_only_once
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
class RunSetupTests < UnitTests
|
33
|
+
include Dk::Task::TestHelpers
|
34
|
+
|
35
|
+
desc "when run"
|
36
|
+
setup do
|
37
|
+
@manifest_path = Factory.file_path
|
38
|
+
@manifest_mode = Factory.string
|
39
|
+
@manifest_owner = Factory.string
|
40
|
+
@installed_pkgs = Factory.manifest_pkgs
|
41
|
+
|
42
|
+
@exp_test_cmd = "test -e #{@manifest_path}"
|
43
|
+
@exp_cat_cmd = "cat #{@manifest_path}"
|
44
|
+
|
45
|
+
@params = {
|
46
|
+
Dk::Pkg::MANIFEST_PATH_PARAM_NAME => @manifest_path,
|
47
|
+
Dk::Pkg::MANIFEST_MODE_PARAM_NAME => @manifest_mode,
|
48
|
+
Dk::Pkg::MANIFEST_OWNER_PARAM_NAME => @manifest_owner
|
49
|
+
}
|
50
|
+
end
|
51
|
+
subject{ @runner }
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def stub_test_manifest_file_exists_cmd(runner, success)
|
56
|
+
@runner.stub_cmd(@exp_test_cmd){ |s| s.exitstatus = success ? 0 : 1 }
|
57
|
+
end
|
58
|
+
|
59
|
+
def stub_cat_manifest_file_cmd(runner, manifest = nil)
|
60
|
+
manifest ||= Dk::Pkg::Manifest.serialize(@installed_pkgs)
|
61
|
+
runner.stub_cmd(@exp_cat_cmd){ |s| s.stdout = manifest }
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
class RunTests < RunSetupTests
|
67
|
+
setup do
|
68
|
+
@runner = test_runner(@task_class, :params => @params)
|
69
|
+
stub_test_manifest_file_exists_cmd(@runner, false)
|
70
|
+
stub_cat_manifest_file_cmd(@runner)
|
71
|
+
@runner.run
|
72
|
+
end
|
73
|
+
|
74
|
+
should "parse the manifest file and set the installed pkgs param" do
|
75
|
+
assert_equal 5, subject.runs.size
|
76
|
+
|
77
|
+
test_cmd, touch_cmd, chmod_cmd, chown_cmd, cat_cmd = subject.runs
|
78
|
+
assert_equal @exp_test_cmd, test_cmd.cmd_str
|
79
|
+
assert_equal "touch #{@manifest_path}", touch_cmd.cmd_str
|
80
|
+
assert_equal "chmod #{@manifest_mode} #{@manifest_path}", chmod_cmd.cmd_str
|
81
|
+
assert_equal "chown #{@manifest_owner} #{@manifest_path}", chown_cmd.cmd_str
|
82
|
+
assert_equal @exp_cat_cmd, cat_cmd.cmd_str
|
83
|
+
|
84
|
+
exp = @installed_pkgs
|
85
|
+
assert_equal exp, subject.params[Dk::Pkg::INSTALLED_PKGS_PARAM_NAME]
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
class RunWithEmptyManifestTests < RunSetupTests
|
91
|
+
desc "and the manifest is empty"
|
92
|
+
setup do
|
93
|
+
@runner = test_runner(@task_class, :params => @params)
|
94
|
+
stub_test_manifest_file_exists_cmd(@runner, Factory.boolean)
|
95
|
+
stub_cat_manifest_file_cmd(@runner, "")
|
96
|
+
@runner.run
|
97
|
+
end
|
98
|
+
|
99
|
+
should "parse the manifest file and set the installed pkgs param" do
|
100
|
+
assert_equal [], subject.params[Dk::Pkg::INSTALLED_PKGS_PARAM_NAME]
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
class RunWithExistingManifestTests < RunSetupTests
|
106
|
+
desc "and the manifest already exists"
|
107
|
+
setup do
|
108
|
+
@runner = test_runner(@task_class, :params => @params)
|
109
|
+
stub_test_manifest_file_exists_cmd(@runner, true)
|
110
|
+
stub_cat_manifest_file_cmd(@runner)
|
111
|
+
@runner.run
|
112
|
+
end
|
113
|
+
|
114
|
+
should "not create the manifest file but still parse it" do
|
115
|
+
assert_equal 2, subject.runs.size
|
116
|
+
|
117
|
+
test_cmd, cat_cmd = subject.runs
|
118
|
+
assert_equal @exp_test_cmd, test_cmd.cmd_str
|
119
|
+
assert_equal @exp_cat_cmd, cat_cmd.cmd_str
|
120
|
+
|
121
|
+
exp = @installed_pkgs
|
122
|
+
assert_equal exp, subject.params[Dk::Pkg::INSTALLED_PKGS_PARAM_NAME]
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
class RunOnNewWithoutModeOrOwnerParamsTests < RunSetupTests
|
128
|
+
desc "with a new manifest but no mode/owner params set"
|
129
|
+
setup do
|
130
|
+
@params.delete(Dk::Pkg::MANIFEST_MODE_PARAM_NAME)
|
131
|
+
@params.delete(Dk::Pkg::MANIFEST_OWNER_PARAM_NAME)
|
132
|
+
|
133
|
+
@runner = test_runner(@task_class, :params => @params)
|
134
|
+
stub_test_manifest_file_exists_cmd(@runner, false)
|
135
|
+
stub_cat_manifest_file_cmd(@runner)
|
136
|
+
@runner.run
|
137
|
+
end
|
138
|
+
|
139
|
+
should "create the manifest file but not change its mode/owner" do
|
140
|
+
assert_equal 3, subject.runs.size
|
141
|
+
|
142
|
+
test_cmd, touch_cmd, cat_cmd = subject.runs
|
143
|
+
assert_equal @exp_test_cmd, test_cmd.cmd_str
|
144
|
+
assert_equal "touch #{@manifest_path}", touch_cmd.cmd_str
|
145
|
+
assert_equal @exp_cat_cmd, cat_cmd.cmd_str
|
146
|
+
|
147
|
+
exp = @installed_pkgs
|
148
|
+
assert_equal exp, subject.params[Dk::Pkg::INSTALLED_PKGS_PARAM_NAME]
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
class RunWithoutManifestPathTests < RunSetupTests
|
154
|
+
desc "and the manifest path param isn't set"
|
155
|
+
setup do
|
156
|
+
@params[Dk::Pkg::MANIFEST_PATH_PARAM_NAME] = [nil, ''].sample
|
157
|
+
end
|
158
|
+
|
159
|
+
should "complain about the param not being set" do
|
160
|
+
runner = test_runner(@task_class, :params => @params)
|
161
|
+
assert_raises(ArgumentError){ runner.run }
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
class TestHelpersTests < UnitTests
|
167
|
+
desc "TestHelpers"
|
168
|
+
setup do
|
169
|
+
@context_class = Class.new do
|
170
|
+
def self.setup_blocks; @setup_blocks ||= []; end
|
171
|
+
def self.setup(&block)
|
172
|
+
self.setup_blocks << block
|
173
|
+
end
|
174
|
+
include Dk::Pkg::Validate::TestHelpers
|
175
|
+
attr_reader :dk_pkg_installed_pkgs, :params
|
176
|
+
def initialize
|
177
|
+
self.class.setup_blocks.each{ |b| self.instance_eval(&b) }
|
178
|
+
end
|
179
|
+
end
|
180
|
+
@context = @context_class.new
|
181
|
+
end
|
182
|
+
subject{ @context }
|
183
|
+
|
184
|
+
should "use much-plugin" do
|
185
|
+
assert_includes MuchPlugin, Dk::Pkg::Validate::TestHelpers
|
186
|
+
end
|
187
|
+
|
188
|
+
should "setup the ivars and params the validate task needs" do
|
189
|
+
assert_not_nil subject.params[Dk::Pkg::MANIFEST_PATH_PARAM_NAME]
|
190
|
+
|
191
|
+
exp = subject.dk_pkg_installed_pkgs
|
192
|
+
assert_equal exp, subject.params[Dk::Pkg::INSTALLED_PKGS_PARAM_NAME]
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dk-pkg
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
3
|
+
version: &id002 !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2016-08-
|
13
|
+
date: 2016-08-17 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assert
|
@@ -19,9 +19,28 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 2.16.
|
22
|
+
version: 2.16.3
|
23
23
|
type: :development
|
24
24
|
version_requirements: *id001
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: dk
|
27
|
+
prerelease: false
|
28
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- *id002
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id003
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: much-plugin
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.2.0
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id004
|
25
44
|
description: Dk logic for installing pkgs
|
26
45
|
email:
|
27
46
|
- kelly@kellyredding.com
|
@@ -39,10 +58,18 @@ files:
|
|
39
58
|
- README.md
|
40
59
|
- dk-pkg.gemspec
|
41
60
|
- lib/dk-pkg.rb
|
61
|
+
- lib/dk-pkg/constants.rb
|
62
|
+
- lib/dk-pkg/install_pkg.rb
|
63
|
+
- lib/dk-pkg/manifest.rb
|
64
|
+
- lib/dk-pkg/validate.rb
|
42
65
|
- lib/dk-pkg/version.rb
|
43
66
|
- log/.gitkeep
|
44
67
|
- test/helper.rb
|
45
68
|
- test/support/factory.rb
|
69
|
+
- test/unit/dk-pkg_tests.rb
|
70
|
+
- test/unit/install_pkg_tests.rb
|
71
|
+
- test/unit/manifest_tests.rb
|
72
|
+
- test/unit/validate_tests.rb
|
46
73
|
- tmp/.gitkeep
|
47
74
|
homepage: https://github.com/redding/dk-pkg
|
48
75
|
licenses:
|
@@ -56,13 +83,13 @@ require_paths:
|
|
56
83
|
- lib
|
57
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
58
85
|
requirements:
|
59
|
-
- &
|
86
|
+
- &id005
|
60
87
|
- ">="
|
61
88
|
- !ruby/object:Gem::Version
|
62
89
|
version: "0"
|
63
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
91
|
requirements:
|
65
|
-
- *
|
92
|
+
- *id005
|
66
93
|
requirements: []
|
67
94
|
|
68
95
|
rubyforge_project:
|
@@ -73,3 +100,7 @@ summary: Dk logic for installing pkgs
|
|
73
100
|
test_files:
|
74
101
|
- test/helper.rb
|
75
102
|
- test/support/factory.rb
|
103
|
+
- test/unit/dk-pkg_tests.rb
|
104
|
+
- test/unit/install_pkg_tests.rb
|
105
|
+
- test/unit/manifest_tests.rb
|
106
|
+
- test/unit/validate_tests.rb
|