chekku 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +8 -8
- data/lib/chekku/checker.rb +2 -3
- data/lib/chekku/definition.rb +85 -0
- data/lib/chekku/definitions.rb +46 -0
- data/lib/chekku/definitions_service.rb +2 -3
- data/lib/chekku/errors.rb +5 -3
- data/lib/chekku/fetcher.rb +2 -1
- data/lib/chekku/version.rb +1 -1
- data/spec/lib/definition_spec.rb +148 -0
- data/spec/lib/definitions_service_spec.rb +5 -8
- data/spec/lib/definitions_spec.rb +27 -0
- data/spec/lib/fetcher_spec.rb +3 -3
- metadata +8 -8
- data/lib/chekku/dependency_checker.rb +0 -51
- data/lib/chekku/dsl.rb +0 -32
- data/spec/lib/dependency_checker_spec.rb +0 -129
- data/spec/lib/dsl_spec.rb +0 -6
data/README.md
CHANGED
@@ -3,7 +3,7 @@ The gem that checks your software dependencies
|
|
3
3
|
|
4
4
|
## WARNING
|
5
5
|
|
6
|
-
**This gem is in
|
6
|
+
**This gem is in early version! Please use it carefully.**
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -28,14 +28,15 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
## Chekkufile
|
30
30
|
|
31
|
-
This is the file that contains the dependencies we need to
|
31
|
+
This is the file that contains the dependencies we need to checks.
|
32
32
|
|
33
33
|
Chekkufile :
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
check 'mysql', must_run: true
|
37
|
+
check 'redis'
|
38
|
+
check 'postgres', "~> 9.2", must_run: true
|
39
|
+
check 'imagemagick', "<= 4"
|
39
40
|
```
|
40
41
|
|
41
42
|
## def.yml
|
@@ -53,12 +54,11 @@ imagemagick:
|
|
53
54
|
executable: 'convert'
|
54
55
|
```
|
55
56
|
|
56
|
-
** I'm currently working on a webapp to define online all the values for this file. So it will be community based. **
|
57
57
|
|
58
58
|
## Future
|
59
59
|
|
60
|
-
I'
|
61
|
-
|
60
|
+
**I'm currently working on a webapp to define online all the values for this file. So it will be community based.**
|
61
|
+
|
62
62
|
|
63
63
|
## Contributing
|
64
64
|
|
data/lib/chekku/checker.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'pathname'
|
2
|
-
require_relative '
|
3
|
-
require_relative 'definitions_service'
|
2
|
+
require_relative 'definitions'
|
4
3
|
|
5
4
|
class Chekku::Checker < Thor
|
6
5
|
include Thor::Actions
|
@@ -20,7 +19,7 @@ class Chekku::Checker < Thor
|
|
20
19
|
private
|
21
20
|
|
22
21
|
def check_dependencies
|
23
|
-
Chekku::
|
22
|
+
Chekku::Definitions.evaluate(@chekkufile)
|
24
23
|
end
|
25
24
|
|
26
25
|
def verify_chekku_file_existence
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
class Chekku::Definition
|
3
|
+
|
4
|
+
attr_accessor :name, :executable, :version_checker, :errors
|
5
|
+
|
6
|
+
def self.load(definitions_hash = {})
|
7
|
+
[].tap do |definitions|
|
8
|
+
definitions_hash.each_pair do |name, hash_definition|
|
9
|
+
definitions << self.new(hash_definition.merge(name: name))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(attributes = {})
|
15
|
+
attributes.each do |name, value|
|
16
|
+
send("#{name}=", value)
|
17
|
+
end
|
18
|
+
@errors = {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def chekku(version = nil, args = {})
|
22
|
+
raise(DefinitionValidationError, "not installed") unless exists?
|
23
|
+
validates version, args
|
24
|
+
"[\033[32m✓\033[0m] #{name}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def exists?
|
28
|
+
verify_executable! && found?
|
29
|
+
end
|
30
|
+
|
31
|
+
def verify_executable!
|
32
|
+
raise(AppNameNotStringError, 'You need to use strings for app names') unless executable.is_a?(String)
|
33
|
+
raise(AppNameNotSaneError, "Sorry the app name '#{name}' is not sane") unless sane_executable?
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
def found?
|
38
|
+
system "which #{executable} > /dev/null 2>&1"
|
39
|
+
end
|
40
|
+
|
41
|
+
def sane_executable?
|
42
|
+
executable == sanitized_executable
|
43
|
+
end
|
44
|
+
|
45
|
+
def sanitized_executable
|
46
|
+
executable.gsub /&|"|'|;|\s/, ""
|
47
|
+
end
|
48
|
+
|
49
|
+
def validates(version = nil, args = {})
|
50
|
+
raise(DefinitionValidationError, "wrong version: wanted #{version}, got #{installed_version}") unless ( !version || check_version(version))
|
51
|
+
raise(DefinitionValidationError, "installed but not running (must_run: true)") unless (!args[:must_run] || is_running?)
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
def is_running?
|
56
|
+
ps_result = `ps aux | grep #{executable}`
|
57
|
+
ps_result_array = ps_result.split("\n")
|
58
|
+
ps_result_array.any? do |ps_line|
|
59
|
+
ps_line.include?(executable) && (executable == 'grep' || !ps_line.include?('grep'))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def check_version(version)
|
64
|
+
operator, version = version.split(' ')
|
65
|
+
if version.nil?
|
66
|
+
version = operator
|
67
|
+
operator = '=='
|
68
|
+
end
|
69
|
+
if operator == '~>'
|
70
|
+
installed_version >= Gem::Version.new(version) && installed_version <= Gem::Version.new(version).bump
|
71
|
+
else
|
72
|
+
installed_version.send(operator, Gem::Version.new(version))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def installed_version
|
77
|
+
version_matches = `#{executable} --version`.scan(/(\d+[\.\d+]*)/).flatten
|
78
|
+
max_dot_number_version = ''
|
79
|
+
version_matches.each do |version|
|
80
|
+
max_dot_number_version = version if version.count('.') > max_dot_number_version.count('.')
|
81
|
+
end
|
82
|
+
Gem::Version.new(max_dot_number_version)
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require_relative 'definition'
|
3
|
+
require_relative 'definitions_service'
|
4
|
+
|
5
|
+
class Chekku::Definitions
|
6
|
+
|
7
|
+
attr_accessor :definitions_service, :dependency_checker
|
8
|
+
|
9
|
+
def self.evaluate(file)
|
10
|
+
new.eval_chekkufile(file)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@definitions_service = Chekku::DefinitionsService.new
|
15
|
+
@definitions_service.load_definitions_for @chekkufile
|
16
|
+
end
|
17
|
+
|
18
|
+
def eval_chekkufile(file)
|
19
|
+
instance_eval(read_file(file))
|
20
|
+
rescue NoMethodError => e
|
21
|
+
puts "\033[31mERROR: Please verify the syntax of your Chekkufile"
|
22
|
+
end
|
23
|
+
|
24
|
+
def check(name, version = nil, args = {})
|
25
|
+
unless version.is_a?(String)
|
26
|
+
args = version || {}
|
27
|
+
version = nil
|
28
|
+
end
|
29
|
+
definition = get_definition! name
|
30
|
+
puts definition.chekku(version, args)
|
31
|
+
rescue DefinitionsError => e
|
32
|
+
puts "[\033[31m✗\033[0m] #{name}: #{e.message}\n"
|
33
|
+
rescue ChekkuError => e
|
34
|
+
puts "\033[31mERROR: #{e.message}\033[0m\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_definition!(name)
|
38
|
+
@definitions_service.definition_for(name) ||
|
39
|
+
raise(DefinitionNotFoundError, "#{name} definition not found. Check ~/.chekku/def.yml")
|
40
|
+
end
|
41
|
+
|
42
|
+
def read_file(file)
|
43
|
+
File.open(file, "r") { |f| f.read }
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -2,14 +2,13 @@ require_relative 'fetcher'
|
|
2
2
|
|
3
3
|
class Chekku::DefinitionsService
|
4
4
|
|
5
|
-
attr_accessor :definitions
|
5
|
+
attr_accessor :definitions
|
6
6
|
|
7
7
|
def load_definitions_for(file)
|
8
|
-
@chekkufile = file
|
9
8
|
@definitions = Chekku::Fetcher.fetch_for_chekkufile file
|
10
9
|
end
|
11
10
|
|
12
11
|
def definition_for(dependency)
|
13
|
-
@definitions
|
12
|
+
@definitions.select{ |definition| definition.name == dependency }.first if @definitions
|
14
13
|
end
|
15
14
|
end
|
data/lib/chekku/errors.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class DefinitionsError < StandardError; end
|
2
|
-
class
|
3
|
-
class
|
4
|
-
class
|
2
|
+
class ChekkuError < StandardError; end
|
3
|
+
class AppNameNotSaneError < ChekkuError; end
|
4
|
+
class AppNameNotStringError < ChekkuError; end
|
5
|
+
class DefinitionNotFoundError < ChekkuError; end
|
6
|
+
class DefinitionValidationError < DefinitionsError; end
|
data/lib/chekku/fetcher.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
require 'yaml'
|
3
|
+
require_relative 'definition'
|
3
4
|
|
4
5
|
class Chekku::Fetcher
|
5
6
|
|
@@ -15,6 +16,6 @@ class Chekku::Fetcher
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def dependencies_from_file
|
18
|
-
@dependencies = YAML.load_file("#{CHEKKU_PATH}/def.yml")
|
19
|
+
@dependencies = Chekku::Definition.load(YAML.load_file("#{CHEKKU_PATH}/def.yml") || {})
|
19
20
|
end
|
20
21
|
end
|
data/lib/chekku/version.rb
CHANGED
@@ -0,0 +1,148 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'chekku/definition'
|
3
|
+
require 'chekku/errors'
|
4
|
+
|
5
|
+
describe Chekku::Definition do
|
6
|
+
let(:definition) { Chekku::Definition.new(name: 'mysql', executable: 'mysqld') }
|
7
|
+
describe ".sanitized_executable" do
|
8
|
+
it "should not change a sane command" do
|
9
|
+
definition.sanitized_executable.should == "mysqld"
|
10
|
+
end
|
11
|
+
|
12
|
+
context "not sane commands" do
|
13
|
+
"&\"';\s".each_char do |char|
|
14
|
+
it "should remove #{char}" do
|
15
|
+
definition.executable = "my#{char}sql"
|
16
|
+
definition.sanitized_executable.should == "mysql"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
describe '.sane_executable?' do
|
22
|
+
it "should be true with sane command" do
|
23
|
+
definition.sane_executable?.should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be false with not sane command" do
|
27
|
+
definition.executable = "my& sql"
|
28
|
+
definition.sane_executable?.should be_false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
describe '.verify_executable!' do
|
32
|
+
it 'should be ok with a sane string' do
|
33
|
+
definition.verify_executable!.should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should raise an error with symbol' do
|
37
|
+
definition.executable = :mysql
|
38
|
+
expect { definition.verify_executable! }.to raise_error(AppNameNotStringError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should raise an error with not sane command' do
|
42
|
+
definition.executable = 'my&sql'
|
43
|
+
expect { definition.verify_executable! }.to raise_error(AppNameNotSaneError)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.found?' do
|
48
|
+
it 'should be true for existing executable' do
|
49
|
+
definition.stub(:system).with('which mysqld > /dev/null 2>&1').and_return(true)
|
50
|
+
definition.found?.should be_true
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should be false for non existing executable' do
|
54
|
+
definition.stub(:system).with('which mysqld > /dev/null 2>&1').and_return(false)
|
55
|
+
definition.found?.should be_false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '.exists?' do
|
60
|
+
it 'should be true if executable is valid and found' do
|
61
|
+
definition.stub(:verify_executable!).and_return(true)
|
62
|
+
definition.stub(:found?).and_return(true)
|
63
|
+
definition.exists?.should be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should be false if executable is invalid' do
|
67
|
+
definition.stub(:verify_executable!).and_return(false)
|
68
|
+
definition.stub(:found?).and_return(true)
|
69
|
+
definition.exists?.should be_false
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should be false if executable is not found' do
|
73
|
+
definition.stub(:verify_executable!).and_return(true)
|
74
|
+
definition.stub(:found?).and_return(false)
|
75
|
+
definition.exists?.should be_false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '.chekku' do
|
80
|
+
it 'should says ✓ if soft exists' do
|
81
|
+
definition.stub(:exists?).and_return(true)
|
82
|
+
definition.chekku.should == "[\033[32m✓\033[0m] mysql"
|
83
|
+
end
|
84
|
+
it 'should says x if soft does not exist' do
|
85
|
+
definition.stub(:exists?).and_return(false)
|
86
|
+
expect { definition.chekku }.to raise_error(DefinitionValidationError)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
let(:version) { Gem::Version.new('5.5.27') }
|
91
|
+
|
92
|
+
describe '.installed_version' do
|
93
|
+
it 'should match 5.5.27 for mysql' do
|
94
|
+
definition.stub(:`).and_return '5.5.27'
|
95
|
+
definition.installed_version.should == version
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '.check_version' do
|
100
|
+
it 'should be ~> 5.5 for mysql' do
|
101
|
+
definition.stub(:installed_version).and_return version
|
102
|
+
definition.check_version('~> 5.5').should be_true
|
103
|
+
end
|
104
|
+
it 'should be >= 5.3 for mysql' do
|
105
|
+
definition.stub(:installed_version).and_return version
|
106
|
+
definition.check_version('>= 5.3').should be_true
|
107
|
+
end
|
108
|
+
it 'should be <= 5.6 for mysql' do
|
109
|
+
definition.stub(:installed_version).and_return version
|
110
|
+
definition.check_version('<= 5.6').should be_true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '.is_running?' do
|
115
|
+
let(:running_return) do %q{yannick 65754 0.0 0.0 2432768 492 s000 R+ 9:37PM 0:00.00 grep mysql
|
116
|
+
yannick 65717 0.0 1.0 2666308 43300 s000 S 9:37PM 0:00.11 /usr/local/Cellar/mysql/5.5.27/bin/mysqld --basedir=/usr/local/Cellar/mysql/5.5.27 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/5.5.27/lib/plugin --log-error=/usr/local/var/mysql/foobar.local.err --pid-file=/usr/local/var/mysql/foobar.local.pid
|
117
|
+
yannick 65646 0.0 0.0 2433432 1072 s000 S 9:37PM 0:00.02 /bin/sh /usr/local/Cellar/mysql/5.5.27/bin/mysqld_safe --datadir=/usr/local/var/mysql --pid-file=/usr/local/var/mysql/foobar.local.pid}
|
118
|
+
end
|
119
|
+
let(:not_running_return) { %q{yannick 65754 0.0 0.0 2432768 492 s000 R+ 9:37PM 0:00.00 grep mysql} }
|
120
|
+
it 'should be true if running' do
|
121
|
+
definition.stub(:`).and_return running_return
|
122
|
+
definition.is_running?.should be_true
|
123
|
+
end
|
124
|
+
it 'should be false if not running' do
|
125
|
+
definition.stub(:`).and_return not_running_return
|
126
|
+
definition.is_running?.should be_false
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '.validates' do
|
131
|
+
it 'should raise an error if the version is wrong' do
|
132
|
+
definition.stub(:check_version).and_return false
|
133
|
+
definition.stub(:is_running?).and_return true
|
134
|
+
expect{ definition.validates("3.0") }.to raise_error(DefinitionValidationError)
|
135
|
+
end
|
136
|
+
it 'should raise an error if not running but must run arg' do
|
137
|
+
definition.stub(:check_version).and_return true
|
138
|
+
definition.stub(:is_running?).and_return false
|
139
|
+
expect{ definition.validates(nil, must_run: true) }.to raise_error(DefinitionValidationError)
|
140
|
+
end
|
141
|
+
it 'should be tru if everything is ok' do
|
142
|
+
definition.stub(:check_version).and_return true
|
143
|
+
definition.stub(:is_running?).and_return true
|
144
|
+
definition.validates("3.0", must_run: true).should be_true
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
@@ -3,10 +3,11 @@ require 'chekku/errors'
|
|
3
3
|
|
4
4
|
describe Chekku::DefinitionsService do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
let(:definition) { Chekku::Definition.new(name: 'mysql', executable: 'mysqld')}
|
7
|
+
let(:definitions) { [definition] }
|
8
|
+
let(:definitions_service) { Chekku::DefinitionsService.new }
|
9
9
|
|
10
|
+
describe '#load_definitions_for' do
|
10
11
|
it 'should set definitions' do
|
11
12
|
Chekku::Fetcher.stub(:fetch_for_chekkufile).with('blabla').and_return(definitions)
|
12
13
|
expect { definitions_service.load_definitions_for('blabla') }
|
@@ -15,17 +16,14 @@ describe Chekku::DefinitionsService do
|
|
15
16
|
end
|
16
17
|
|
17
18
|
describe '#definition_for' do
|
18
|
-
let(:definitions) { { 'mysql' => { 'existance' => 'which mysqld' }} }
|
19
|
-
|
20
19
|
context 'definitions are set' do
|
21
|
-
let(:definitions_service) { Chekku::DefinitionsService.new }
|
22
20
|
before(:each) do
|
23
21
|
definitions_service.definitions = definitions
|
24
22
|
end
|
25
23
|
|
26
24
|
context 'existing definition' do
|
27
25
|
it 'should return the definition of the asked element' do
|
28
|
-
definitions_service.definition_for('mysql').should == definitions
|
26
|
+
definitions_service.definition_for('mysql').should == definitions.first
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
@@ -37,7 +35,6 @@ describe Chekku::DefinitionsService do
|
|
37
35
|
end
|
38
36
|
|
39
37
|
context 'definitions are not set' do
|
40
|
-
let(:definitions_service) { Chekku::DefinitionsService.new }
|
41
38
|
it 'should return nil' do
|
42
39
|
definitions_service.definition_for('not-existing').should == nil
|
43
40
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'chekku/definitions'
|
3
|
+
require 'chekku/definitions_service'
|
4
|
+
require 'chekku/errors'
|
5
|
+
|
6
|
+
describe Chekku::Definitions do
|
7
|
+
|
8
|
+
let(:definitions_service) { double(Chekku::DefinitionsService) }
|
9
|
+
let(:definitions) { Chekku::Definitions.new }
|
10
|
+
let(:definition) { Chekku::Definition.new(name: 'mysql', executable: 'mysqld') }
|
11
|
+
|
12
|
+
describe 'instance methods' do
|
13
|
+
|
14
|
+
describe '.get_definition' do
|
15
|
+
it 'should return the definition' do
|
16
|
+
definitions.definitions_service.stub(:definition_for).with('mysql').and_return(definition)
|
17
|
+
definitions.get_definition!('mysql').should == definition
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should raise an error if not found' do
|
21
|
+
definitions.definitions_service.stub(:definition_for).with('mysql').and_return(nil)
|
22
|
+
expect{ definitions.get_definition!('mysql') }.to raise_error(DefinitionNotFoundError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/spec/lib/fetcher_spec.rb
CHANGED
@@ -9,10 +9,10 @@ describe Chekku::Fetcher do
|
|
9
9
|
fetcher.dependencies_from_file
|
10
10
|
end
|
11
11
|
|
12
|
-
it 'should return an
|
13
|
-
dependencies_hash = { 'mysql' => { '
|
12
|
+
it 'should return an array of definitions of dependencies' do
|
13
|
+
dependencies_hash = { 'mysql' => { 'executable' => 'mysqld' }}
|
14
14
|
YAML.stub(:load_file).and_return(dependencies_hash)
|
15
|
-
fetcher.dependencies_from_file
|
15
|
+
fetcher.dependencies_from_file.first.name.should == 'mysql'
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chekku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -80,15 +80,15 @@ files:
|
|
80
80
|
- examples/def.yml
|
81
81
|
- lib/chekku.rb
|
82
82
|
- lib/chekku/checker.rb
|
83
|
+
- lib/chekku/definition.rb
|
84
|
+
- lib/chekku/definitions.rb
|
83
85
|
- lib/chekku/definitions_service.rb
|
84
|
-
- lib/chekku/dependency_checker.rb
|
85
|
-
- lib/chekku/dsl.rb
|
86
86
|
- lib/chekku/errors.rb
|
87
87
|
- lib/chekku/fetcher.rb
|
88
88
|
- lib/chekku/version.rb
|
89
|
+
- spec/lib/definition_spec.rb
|
89
90
|
- spec/lib/definitions_service_spec.rb
|
90
|
-
- spec/lib/
|
91
|
-
- spec/lib/dsl_spec.rb
|
91
|
+
- spec/lib/definitions_spec.rb
|
92
92
|
- spec/lib/fetcher_spec.rb
|
93
93
|
- spec/spec_helper.rb
|
94
94
|
homepage: http://ys.github.com/chekku
|
@@ -116,8 +116,8 @@ signing_key:
|
|
116
116
|
specification_version: 3
|
117
117
|
summary: ! 'Chekku: software dependencies checker'
|
118
118
|
test_files:
|
119
|
+
- spec/lib/definition_spec.rb
|
119
120
|
- spec/lib/definitions_service_spec.rb
|
120
|
-
- spec/lib/
|
121
|
-
- spec/lib/dsl_spec.rb
|
121
|
+
- spec/lib/definitions_spec.rb
|
122
122
|
- spec/lib/fetcher_spec.rb
|
123
123
|
- spec/spec_helper.rb
|
@@ -1,51 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
class Chekku::DependencyChecker
|
3
|
-
|
4
|
-
attr_accessor :definitions_service
|
5
|
-
attr_accessor :definition
|
6
|
-
|
7
|
-
def self.with(definitions_service)
|
8
|
-
new definitions_service
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize(definitions_service)
|
12
|
-
@definitions_service = definitions_service
|
13
|
-
end
|
14
|
-
|
15
|
-
def chekku(name, version, args)
|
16
|
-
definition = get_and_check_definition! name
|
17
|
-
if exists? definition
|
18
|
-
"Checked #{name} [\033[32m✓\033[0m]"
|
19
|
-
else
|
20
|
-
"Checked #{name} [\033[31m✗\033[0m] I think you must install it!"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def get_and_check_definition!(name)
|
25
|
-
@definitions_service.definition_for(name) ||
|
26
|
-
raise(DefinitionNotFoundError, "#{name} definition not be found. Check ~/.chekku/def.yml")
|
27
|
-
end
|
28
|
-
|
29
|
-
def exists?(definition)
|
30
|
-
command = definition['executable']
|
31
|
-
verify_command!(command) && found?(command)
|
32
|
-
end
|
33
|
-
|
34
|
-
def verify_command!(command)
|
35
|
-
raise AppNameNotStringError, 'You need to use strings for app names' unless command.is_a?(String)
|
36
|
-
raise AppNameNotSaneError, "Sorry the app name '#{@current_app}' is not sane" unless sane?(command)
|
37
|
-
true
|
38
|
-
end
|
39
|
-
|
40
|
-
def found?(command)
|
41
|
-
system("which #{command} > /dev/null")
|
42
|
-
end
|
43
|
-
|
44
|
-
def sane?(command)
|
45
|
-
command == sanitize(command)
|
46
|
-
end
|
47
|
-
|
48
|
-
def sanitize(command)
|
49
|
-
command.gsub(/&|"|'|;|\s/, "")
|
50
|
-
end
|
51
|
-
end
|
data/lib/chekku/dsl.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require_relative 'dependency_checker'
|
2
|
-
|
3
|
-
class Chekku::Dsl
|
4
|
-
|
5
|
-
attr_accessor :definitions_service
|
6
|
-
|
7
|
-
def self.evaluate(file)
|
8
|
-
new.eval_chekkufile(file)
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
@definitions_service = Chekku::DefinitionsService.new
|
13
|
-
@definitions_service.load_definitions_for @chekkufile
|
14
|
-
end
|
15
|
-
|
16
|
-
def eval_chekkufile(file)
|
17
|
-
instance_eval(read_file(file))
|
18
|
-
rescue NoMethodError => e
|
19
|
-
puts "\033[31mERROR: Please verify the syntax of your Chekkufile"
|
20
|
-
end
|
21
|
-
|
22
|
-
def check(name, version = nil, args ={})
|
23
|
-
puts Chekku::DependencyChecker.with(@definitions_service).chekku(name, version, args)
|
24
|
-
rescue DefinitionsError => e
|
25
|
-
puts "\033[31mERROR: #{e.message}\033[0m\n"
|
26
|
-
end
|
27
|
-
|
28
|
-
def read_file(file)
|
29
|
-
File.open(file, "r") { |f| f.read }
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
require 'chekku/dependency_checker'
|
3
|
-
require 'chekku/definitions_service'
|
4
|
-
require 'chekku/errors'
|
5
|
-
|
6
|
-
describe Chekku::DependencyChecker do
|
7
|
-
|
8
|
-
|
9
|
-
describe "#with" do
|
10
|
-
let(:definitions_service) { double(Chekku::DefinitionsService) }
|
11
|
-
let(:subject) { Chekku::DependencyChecker.with(definitions_service) }
|
12
|
-
it { should be_instance_of(Chekku::DependencyChecker) }
|
13
|
-
its(:definitions_service) { should == definitions_service }
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'instance methods' do
|
17
|
-
let(:checker) { Chekku::DependencyChecker.with(Chekku::DefinitionsService.new) }
|
18
|
-
|
19
|
-
describe ".sanitize" do
|
20
|
-
it "should not change a sane command" do
|
21
|
-
checker.sanitize("hello_you").should == "hello_you"
|
22
|
-
end
|
23
|
-
|
24
|
-
context "not sane commands" do
|
25
|
-
it "should remove &" do
|
26
|
-
checker.sanitize("hello&world").should == "helloworld"
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should remove \"" do
|
30
|
-
checker.sanitize("hello\"world").should == "helloworld"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should remove '" do
|
34
|
-
checker.sanitize("hello'world").should == "helloworld"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should remove ;" do
|
38
|
-
checker.sanitize("hello;world").should == "helloworld"
|
39
|
-
end
|
40
|
-
it "should remove \s" do
|
41
|
-
checker.sanitize("hello world").should == "helloworld"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '.sane?' do
|
47
|
-
it "should be true with sane command" do
|
48
|
-
checker.sane?('ls').should be_true
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should be false with not sane command" do
|
52
|
-
checker.sane?('ls & rm ').should be_false
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '.verify_command!' do
|
57
|
-
it 'should be ok with a sane string' do
|
58
|
-
checker.verify_command!('ls').should be_true
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should raise an error with symbol' do
|
62
|
-
expect { checker.verify_command!(:ls) }.to raise_error(AppNameNotStringError)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should raise an error with not sane command' do
|
66
|
-
expect { checker.verify_command!('rm&') }.to raise_error(AppNameNotSaneError)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe '.found?' do
|
71
|
-
it 'should be true for an existing command' do
|
72
|
-
checker.found?('ls').should be_true
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'should be false for an existing command' do
|
76
|
-
checker.found?('lsrm').should be_false
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe '.exists?' do
|
81
|
-
let(:definition) { { 'executable' => 'mysql' } }
|
82
|
-
it 'should be true if command is valid and found' do
|
83
|
-
checker.stub(:verify_command!).with('mysql').and_return(true)
|
84
|
-
checker.stub(:found?).with('mysql').and_return(true)
|
85
|
-
checker.exists?(definition).should be_true
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'should be false if command is invalid' do
|
89
|
-
checker.stub(:verify_command!).with('mysql').and_return(false)
|
90
|
-
checker.stub(:found?).with('mysql').and_return(true)
|
91
|
-
checker.exists?(definition).should be_false
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should be false if command is not found' do
|
95
|
-
checker.stub(:verify_command!).with('mysql').and_return(true)
|
96
|
-
checker.stub(:found?).with('mysql').and_return(false)
|
97
|
-
checker.exists?(definition).should be_false
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe '.get_and_check_definition' do
|
102
|
-
let(:definition) { { 'executable' => 'mysql' } }
|
103
|
-
it 'should return a hash with the definition' do
|
104
|
-
checker.definitions_service.stub(:definition_for).with('mysql').and_return(definition)
|
105
|
-
checker.get_and_check_definition!('mysql').should == definition
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'should raise an error if not found' do
|
109
|
-
checker.definitions_service.stub(:definition_for).with('mysql').and_return(nil)
|
110
|
-
expect{ checker.get_and_check_definition!('mysql') }.to raise_error(DefinitionNotFoundError)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe '.chekku' do
|
115
|
-
let(:definition) { { 'executable' => 'mysql' } }
|
116
|
-
it 'should if definition exists says ✓' do
|
117
|
-
checker.stub(:get_and_check_definition!).with('mysql').and_return(definition)
|
118
|
-
checker.stub(:exists?).with(definition).and_return(true)
|
119
|
-
checker.chekku('mysql', nil, nil).should == "Checked mysql [\033[32m✓\033[0m]"
|
120
|
-
end
|
121
|
-
it 'should if definition exists says x' do
|
122
|
-
checker.stub(:get_and_check_definition!).with('mysql').and_return(definition)
|
123
|
-
checker.stub(:exists?).with(definition).and_return(false)
|
124
|
-
checker.chekku('mysql', nil, nil).should == "Checked mysql [\033[31m✗\033[0m] I think you must install it!"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
end
|