chekku 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --backtrace
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - rbx-19mode
5
+ - jruby-19mode
6
+ branches:
7
+ only:
8
+ - master
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- # Chekku
2
-
1
+ # Chekku [![Build Status](https://secure.travis-ci.org/ys/chekku.png)](http://travis-ci.org/ys/chekku)
3
2
  The gem that checks your software dependencies
4
3
 
5
4
  ## WARNING
@@ -23,24 +22,44 @@ Or install it yourself as:
23
22
  ## Usage
24
23
 
25
24
  ```
26
- $ chekku checks # Check your software dependencies
25
+ $ chekku checks # Check your software dependencies (default task)
27
26
  $ chekku help [TASK] # Describe available tasks or one specific task
28
27
  ```
29
28
 
30
29
  ## Chekkufile
31
30
 
32
31
  This is the file that contains the dependencies we need to check
33
- For the moment only the name is executable is validated
34
32
 
35
33
  Chekkufile :
36
34
 
37
35
  ```ruby
38
36
  check 'mysql', '>= 5.0', env: :production
39
- check 'redis-server'
37
+ check 'redis'
40
38
  check 'mongod', '~> 1.0', env: :development, must_run: true
41
39
  ```
42
40
 
43
- **As you can see, you have to set the executable name for the moment, I'm trying to find an easy way to check for software which executables aren't name as the project (see imagemagick)**
41
+ ## def.yml
42
+
43
+ This file is in an hidden folder of your home and should contain information about how to check the existance, versions,... of a dependency
44
+
45
+ ~/.chekku/def.yml :
46
+
47
+ ```
48
+ mysql:
49
+ executable: 'mysqld'
50
+ redis:
51
+ executable: 'redis-server'
52
+ imagemagick:
53
+ executable: 'convert'
54
+ ```
55
+
56
+ ** I'm currently working on a webapp to define online all the values for this file. So it will be community based. **
57
+
58
+ ## Future
59
+
60
+ I'll try to have a version that works for checking the version of the dependecy in the near future.
61
+ And will add tests to check if the service is running or not.
62
+
44
63
  ## Contributing
45
64
 
46
65
  1. Fork it
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new do |t|
4
+ t.rspec_opts = ['--color', '--format doc', '--order rand']
5
+ end
6
+
7
+ task :default => :spec
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ #encoding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'chekku/version'
@@ -8,17 +8,14 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Chekku::VERSION
9
9
  gem.authors = ['Yannick Schutz']
10
10
  gem.email = ['yannick.schutz@gmail.com']
11
- gem.description = %q{Chekku checks all your software dependencies in every environment. It will helps you installing them too.}
11
+ gem.description = %q{Chekku checks all your software dependencies from development to production.}
12
12
  gem.summary = %q{Chekku: software dependencies checker}
13
13
  gem.homepage = 'http://ys.github.com/chekku'
14
-
15
14
  gem.required_ruby_version = '>= 1.9'
16
15
  gem.required_rubygems_version = '>= 1.3.6'
17
-
18
16
  gem.add_development_dependency 'rspec', '>= 2.0'
19
-
20
17
  gem.add_dependency 'thor'
21
-
18
+ gem.add_dependency 'rake'
22
19
  gem.files = `git ls-files`.split($/)
23
20
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
24
21
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
@@ -0,0 +1,3 @@
1
+ check 'mysql'
2
+ check 'redis'
3
+ check 'imagemagick'
@@ -0,0 +1,8 @@
1
+ mysql:
2
+ executable: 'mysqld'
3
+ postgres:
4
+ executable: 'postgres'
5
+ redis:
6
+ executable: 'redis-server'
7
+ imagemagick:
8
+ executable: 'convert'
@@ -1,6 +1,7 @@
1
- require "chekku/version"
1
+ require 'chekku/version'
2
2
  require 'thor'
3
3
  require 'thor/group'
4
+ require 'chekku/errors'
4
5
 
5
6
  module Chekku
6
7
  class Command
@@ -1,5 +1,6 @@
1
1
  require 'pathname'
2
2
  require_relative 'dsl'
3
+ require_relative 'definitions_service'
3
4
 
4
5
  class Chekku::Checker < Thor
5
6
  include Thor::Actions
@@ -23,9 +24,9 @@ class Chekku::Checker < Thor
23
24
  end
24
25
 
25
26
  def verify_chekku_file_existence
26
- chekkufile = Pathname.new(@chekkufile).expand_path
27
+ chekkufile = Pathname.new(@chekkufile).expand_path
27
28
 
28
- unless chekkufile.file?
29
+ unless chekkufile.file?
29
30
  say "#{chekkufile} not found"
30
31
  exit -1
31
32
  end
@@ -0,0 +1,15 @@
1
+ require_relative 'fetcher'
2
+
3
+ class Chekku::DefinitionsService
4
+
5
+ attr_accessor :definitions, :chekkufile
6
+
7
+ def load_definitions_for(file)
8
+ @chekkufile = file
9
+ @definitions = Chekku::Fetcher.fetch_for_chekkufile file
10
+ end
11
+
12
+ def definition_for(dependency)
13
+ @definitions[dependency] if @definitions
14
+ end
15
+ end
@@ -0,0 +1,51 @@
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
@@ -1,16 +1,28 @@
1
- require_relative 'generic_checker.rb'
2
- class Chekku::Dsl < Thor::Group
1
+ require_relative 'dependency_checker'
2
+
3
+ class Chekku::Dsl
4
+
5
+ attr_accessor :definitions_service
6
+
3
7
  def self.evaluate(file)
4
- builder = new
5
- builder.eval_chekkufile(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
6
14
  end
7
15
 
8
16
  def eval_chekkufile(file)
9
17
  instance_eval(read_file(file))
18
+ rescue NoMethodError => e
19
+ puts "\033[31mERROR: Please verify the syntax of your Chekkufile"
10
20
  end
11
21
 
12
22
  def check(name, version = nil, args ={})
13
- say Chekku::GenericChecker.new(name, version, args).chekku!
23
+ puts Chekku::DependencyChecker.with(@definitions_service).chekku(name, version, args)
24
+ rescue DefinitionsError => e
25
+ puts "\033[31mERROR: #{e.message}\033[0m\n"
14
26
  end
15
27
 
16
28
  def read_file(file)
@@ -0,0 +1,4 @@
1
+ class DefinitionsError < StandardError; end
2
+ class AppNameNotSaneError < DefinitionsError; end
3
+ class AppNameNotStringError < DefinitionsError; end
4
+ class DefinitionNotFoundError < DefinitionsError; end
@@ -0,0 +1,20 @@
1
+ #encoding: utf-8
2
+ require 'yaml'
3
+
4
+ class Chekku::Fetcher
5
+
6
+ CHEKKU_PATH = "#{ENV['HOME']}/.chekku"
7
+
8
+ attr_accessor :dependencies
9
+
10
+ def self.fetch_for_chekkufile(file)
11
+ # TODO: Implements server side of the file checker
12
+ # STUB: Load local file
13
+ fetcher = new
14
+ fetcher.dependencies_from_file
15
+ end
16
+
17
+ def dependencies_from_file
18
+ @dependencies = YAML.load_file("#{CHEKKU_PATH}/def.yml")
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Chekku
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -0,0 +1,49 @@
1
+ require 'chekku/definitions_service'
2
+ require 'chekku/errors'
3
+
4
+ describe Chekku::DefinitionsService do
5
+
6
+ describe '#load_definitions_for' do
7
+ let(:definitions_service) { Chekku::DefinitionsService.new }
8
+ let(:definitions) { { 'mysql' => { 'existance' => 'which mysqld' }} }
9
+
10
+ it 'should set definitions' do
11
+ Chekku::Fetcher.stub(:fetch_for_chekkufile).with('blabla').and_return(definitions)
12
+ expect { definitions_service.load_definitions_for('blabla') }
13
+ .to change(definitions_service, :definitions).from(nil).to(definitions)
14
+ end
15
+ end
16
+
17
+ describe '#definition_for' do
18
+ let(:definitions) { { 'mysql' => { 'existance' => 'which mysqld' }} }
19
+
20
+ context 'definitions are set' do
21
+ let(:definitions_service) { Chekku::DefinitionsService.new }
22
+ before(:each) do
23
+ definitions_service.definitions = definitions
24
+ end
25
+
26
+ context 'existing definition' do
27
+ it 'should return the definition of the asked element' do
28
+ definitions_service.definition_for('mysql').should == definitions['mysql']
29
+ end
30
+ end
31
+
32
+ context 'missing definition' do
33
+ it 'should return nil' do
34
+ definitions_service.definition_for('not-existing').should == nil
35
+ end
36
+ end
37
+ end
38
+
39
+ context 'definitions are not set' do
40
+ let(:definitions_service) { Chekku::DefinitionsService.new }
41
+ it 'should return nil' do
42
+ definitions_service.definition_for('not-existing').should == nil
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
@@ -0,0 +1,129 @@
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
@@ -0,0 +1,6 @@
1
+ require 'chekku/dsl'
2
+
3
+ describe Chekku::Dsl do
4
+ it 'should works' do
5
+ end
6
+ end
@@ -0,0 +1,26 @@
1
+ require 'chekku/fetcher'
2
+
3
+ describe Chekku::Fetcher do
4
+
5
+ describe ".dependencies_for_file" do
6
+ let(:fetcher) { Chekku::Fetcher.new() }
7
+ it 'should call YAML.load_file' do
8
+ YAML.should_receive(:load_file).with("#{ENV['HOME']}/.chekku/def.yml")
9
+ fetcher.dependencies_from_file
10
+ end
11
+
12
+ it 'should return an object with methods corresponding to dependencies' do
13
+ dependencies_hash = { 'mysql' => { 'existance' => 'which mysqld' }}
14
+ YAML.stub(:load_file).and_return(dependencies_hash)
15
+ fetcher.dependencies_from_file['mysql'].should == { 'existance' =>'which mysqld'}
16
+ end
17
+ end
18
+
19
+ describe '#fetch_for_chekkufile(file)' do
20
+ it 'should return an object with' do
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+
@@ -2,7 +2,15 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
4
  require 'chekku'
5
+ # Load support files
6
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
7
+
8
+ # Load fixtures from the engine
9
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
10
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
11
+ end
5
12
 
6
13
  RSpec.configure do |config|
7
- # some (optional) config here
14
+ config.before :each do
15
+ end
8
16
  end
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.3
4
+ version: 0.0.4
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-08-16 00:00:00.000000000 Z
12
+ date: 2012-09-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -43,8 +43,23 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: Chekku checks all your software dependencies in every environment. It
47
- will helps you installing them too.
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Chekku checks all your software dependencies from development to production.
48
63
  email:
49
64
  - yannick.schutz@gmail.com
50
65
  executables:
@@ -53,18 +68,28 @@ extensions: []
53
68
  extra_rdoc_files: []
54
69
  files:
55
70
  - .gitignore
71
+ - .rspec
72
+ - .travis.yml
56
73
  - Gemfile
57
74
  - LICENSE.txt
58
75
  - README.md
59
76
  - Rakefile
60
77
  - bin/chekku
61
78
  - chekku.gemspec
79
+ - examples/Chekkufile
80
+ - examples/def.yml
62
81
  - lib/chekku.rb
63
82
  - lib/chekku/checker.rb
83
+ - lib/chekku/definitions_service.rb
84
+ - lib/chekku/dependency_checker.rb
64
85
  - lib/chekku/dsl.rb
65
- - lib/chekku/generic_checker.rb
86
+ - lib/chekku/errors.rb
87
+ - lib/chekku/fetcher.rb
66
88
  - lib/chekku/version.rb
67
- - spec/generic_checker_spec.rb
89
+ - spec/lib/definitions_service_spec.rb
90
+ - spec/lib/dependency_checker_spec.rb
91
+ - spec/lib/dsl_spec.rb
92
+ - spec/lib/fetcher_spec.rb
68
93
  - spec/spec_helper.rb
69
94
  homepage: http://ys.github.com/chekku
70
95
  licenses: []
@@ -91,5 +116,8 @@ signing_key:
91
116
  specification_version: 3
92
117
  summary: ! 'Chekku: software dependencies checker'
93
118
  test_files:
94
- - spec/generic_checker_spec.rb
119
+ - spec/lib/definitions_service_spec.rb
120
+ - spec/lib/dependency_checker_spec.rb
121
+ - spec/lib/dsl_spec.rb
122
+ - spec/lib/fetcher_spec.rb
95
123
  - spec/spec_helper.rb
@@ -1,24 +0,0 @@
1
- class Chekku::GenericChecker < Thor::Shell::Basic
2
-
3
- def initialize(name, version = nil, args = {})
4
- @name = sanitize name.to_s
5
- @version = version
6
- @args = args
7
- end
8
-
9
- def chekku!
10
- if which_exists?
11
- "\e[32m#{@name} exists!\e[0m"
12
- else
13
- "\e[31mI think you must install #{@name}\e[0m"
14
- end
15
- end
16
-
17
- def which_exists?
18
- system("which '#{@name}' > /dev/null")
19
- end
20
-
21
- def sanitize(name)
22
- name.gsub(/&|"|'|;|\s/, "")
23
- end
24
- end
@@ -1,21 +0,0 @@
1
- require 'thor'
2
- require 'chekku/generic_checker'
3
-
4
- describe Chekku::GenericChecker do
5
-
6
- context "The command exists" do
7
- let(:valid_checker) { Chekku::GenericChecker.new('ls', nil, nil) }
8
- it "should return a green string" do
9
- valid_checker.chekku!.should == "\e[32mls exists!\e[0m"
10
- end
11
- end
12
-
13
- context "The command does not exist" do
14
- let(:invalid_checker) { Chekku::GenericChecker.new('lsdahpdahiofaiofhaoigfhoaugzza', nil, nil) }
15
- it "should return a green string" do
16
- invalid_checker.chekku!.should == "\e[31mI think you must install lsdahpdahiofaiofhaoigfhoaugzza\e[0m"
17
- end
18
- end
19
-
20
-
21
- end