kuroko 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/kuroko.gemspec +21 -0
- data/lib/core_ext/cucumber/rb_language.rb +12 -0
- data/lib/kuroko.rb +11 -0
- data/lib/kuroko/configuration.rb +10 -0
- data/lib/kuroko/errors.rb +5 -0
- data/lib/kuroko/vagrant_support.rb +64 -0
- data/spec/cucumber_core_ext_spec.rb +12 -0
- data/spec/kuroko_spec.rb +28 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/vagrant_support_spec.rb +101 -0
- metadata +134 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Matt House
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Kuroko
|
2
|
+
|
3
|
+
A cucumber plugin to facilitate integration testing of Puppet manifests using Vagrant.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'kuroko'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install kuroko
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Require the library in your `features/support/env.rb`
|
22
|
+
|
23
|
+
require 'kuroko'
|
24
|
+
|
25
|
+
Configure the library to point to a vagrant environment (ie. a directory containing a Vagrantfile) to test your puppet repositories against
|
26
|
+
|
27
|
+
Kuroko.configure do |config|
|
28
|
+
config.vagrant_root = File.expand_path(File.join(__FILE__, 'vagrant_root'))
|
29
|
+
end
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/kuroko.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.authors = ["Matt House"]
|
4
|
+
gem.email = ["matt@eightbitraptor.com"]
|
5
|
+
gem.description = %q{Cucumber Plugin for testing Puppet manifests using Vagrant}
|
6
|
+
gem.summary = %q{Cucumber Plugin for testing Puppet manifests using Vagrant}
|
7
|
+
gem.homepage = ""
|
8
|
+
|
9
|
+
gem.files = `git ls-files`.split($\)
|
10
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
11
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
|
+
gem.name = "kuroko"
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
gem.version = "0.0.1"
|
15
|
+
|
16
|
+
gem.add_dependency('vagrant')
|
17
|
+
gem.add_dependency('cucumber')
|
18
|
+
|
19
|
+
gem.add_development_dependency('rspec')
|
20
|
+
gem.add_development_dependency('rake')
|
21
|
+
end
|
data/lib/kuroko.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module Kuroko
|
2
|
+
module VagrantSupport
|
3
|
+
|
4
|
+
at_exit {
|
5
|
+
if ENV['KEEP_RUNNING'] != "true"
|
6
|
+
new_env = Object.new.extend(self).send(:vagrant_env)
|
7
|
+
new_env.cli('destroy', '-f')
|
8
|
+
end
|
9
|
+
}
|
10
|
+
|
11
|
+
def vagrant_cli_command(command)
|
12
|
+
vagrant_env.cli(command)
|
13
|
+
end
|
14
|
+
|
15
|
+
def vagrant_sandbox_command(command, path=vagrant_root)
|
16
|
+
invoke_sandbox_command(command, path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def run_vagrant_command(command, options={})
|
20
|
+
run_command(:execute, command, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_sudo_command(command, options={})
|
24
|
+
run_command(:sudo, command, options)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def vagrant_env
|
30
|
+
@vagrant ||= Vagrant::Environment.new(:cwd => vagrant_root)
|
31
|
+
end
|
32
|
+
|
33
|
+
def run_command(method, command, options)
|
34
|
+
if vagrant_env.primary_vm.state != :running
|
35
|
+
raise VagrantNotRunningException
|
36
|
+
end
|
37
|
+
|
38
|
+
code = vagrant_env.primary_vm.channel.send(method, command) do |type, data|
|
39
|
+
if !(options[:silent]) && ([:stdout, :stdout].include? type)
|
40
|
+
puts data
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if !options[:no_verify] && code != 0
|
45
|
+
raise VagrantSshCommandError
|
46
|
+
end
|
47
|
+
code
|
48
|
+
end
|
49
|
+
|
50
|
+
def invoke_sandbox_command(command, path)
|
51
|
+
pwd = Dir.pwd
|
52
|
+
begin
|
53
|
+
Dir.chdir(path)
|
54
|
+
vagrant_env.cli('sandbox', command)
|
55
|
+
ensure
|
56
|
+
Dir.chdir(pwd)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def vagrant_root
|
61
|
+
@vagrant_root ||= Configuration.instance.vagrant_root
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kuroko'
|
3
|
+
|
4
|
+
describe "Monkeypatching Cucumber" do
|
5
|
+
subject{ Cucumber::RbSupport::RbLanguage.new }
|
6
|
+
|
7
|
+
it "extends the world with the VagrantSupport module" do
|
8
|
+
subject.extend_world
|
9
|
+
|
10
|
+
subject.current_world.class.ancestors.should include(Kuroko::VagrantSupport)
|
11
|
+
end
|
12
|
+
end
|
data/spec/kuroko_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kuroko'
|
3
|
+
|
4
|
+
describe "configuring Cucumber Puppet" do
|
5
|
+
it "has a configuration api" do
|
6
|
+
Kuroko.should respond_to(:configure)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'yields the configuration instance to the block' do
|
10
|
+
Kuroko.configure do |c|
|
11
|
+
c.should == Kuroko::Configuration.instance
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Kuroko::Configuration do
|
16
|
+
subject{ Kuroko::Configuration.instance }
|
17
|
+
|
18
|
+
it "is a singleton" do
|
19
|
+
subject.should == Kuroko::Configuration.instance
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'stores the vagrant_root path' do
|
23
|
+
subject.vagrant_root = 'foobar'
|
24
|
+
subject.vagrant_root.should == 'foobar'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
# Stub out the Vagrant Environment so that we don't try and load VM's when
|
4
|
+
# running the tests
|
5
|
+
|
6
|
+
module Vagrant
|
7
|
+
class Environment
|
8
|
+
def initialize(args)
|
9
|
+
#NOOP
|
10
|
+
end
|
11
|
+
|
12
|
+
def cli(command, options=nil)
|
13
|
+
# NOOP
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Cucumber
|
19
|
+
module RbSupport
|
20
|
+
class RbLanguage
|
21
|
+
attr_reader :current_world
|
22
|
+
|
23
|
+
def extend_world
|
24
|
+
# NOOP
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kuroko'
|
3
|
+
|
4
|
+
describe "VagrantSupport Module" do
|
5
|
+
subject{ Object.new.extend(Kuroko::VagrantSupport) }
|
6
|
+
let(:mock_env){ double('Environment', cli: nil) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
subject.stub(:vagrant_env).and_return(mock_env)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#vagrant_cli_command" do
|
13
|
+
it "passes the cli command on to the vagrant environment" do
|
14
|
+
mock_env.should_receive(:cli).with('foobar')
|
15
|
+
|
16
|
+
subject.vagrant_cli_command('foobar')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#run_vagrant_sandbox_command" do
|
21
|
+
before do
|
22
|
+
Dir.stub(:chdir)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "changes into the specified working directory" do
|
26
|
+
Dir.should_receive(:chdir).with('/tmp/path')
|
27
|
+
|
28
|
+
subject.vagrant_sandbox_command('dontcare', '/tmp/path')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "runs the specified command against the vagrant env" do
|
32
|
+
mock_env.should_receive(:cli).with('sandbox', 'dontcare')
|
33
|
+
|
34
|
+
subject.vagrant_sandbox_command('dontcare', '/tmp/path')
|
35
|
+
end
|
36
|
+
|
37
|
+
it "changes back into the old working directory" do
|
38
|
+
Dir.should_receive(:chdir).with(Dir.pwd)
|
39
|
+
|
40
|
+
subject.vagrant_sandbox_command('dontcare', '/tmp/path')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'changes back to the old working dir even on a failure' do
|
44
|
+
Dir.should_receive(:chdir).with(Dir.pwd)
|
45
|
+
mock_env.stub(:cli){ raise "Boom!" }
|
46
|
+
|
47
|
+
expect{
|
48
|
+
subject.vagrant_sandbox_command('dontcare', '/tmp/path')
|
49
|
+
}.to raise_error
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#run_vagrant_command" do
|
54
|
+
before do
|
55
|
+
mock_env.stub_chain(:primary_vm, :state){ :running }
|
56
|
+
end
|
57
|
+
|
58
|
+
it "raises an error if the VM has crashed" do
|
59
|
+
mock_env.stub_chain(:primary_vm, :state){ :fucked }
|
60
|
+
|
61
|
+
expect{
|
62
|
+
subject.run_vagrant_command('hostname')
|
63
|
+
}.to raise_error(Kuroko::VagrantNotRunningException)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "sets the vagrant command to execute" do
|
67
|
+
subject.should_receive(:run_command).with(:execute, 'hostname', {})
|
68
|
+
subject.run_vagrant_command('hostname')
|
69
|
+
end
|
70
|
+
|
71
|
+
it "passes through the options hash" do
|
72
|
+
subject.should_receive(:run_command).with(:execute,
|
73
|
+
'hostname',
|
74
|
+
{no_verify: true})
|
75
|
+
subject.run_vagrant_command('hostname', no_verify: true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "raises and exception if the ssh exit code is nonzero" do
|
79
|
+
mock_env.stub_chain(:primary_vm, :channel, :send){ 1 }
|
80
|
+
|
81
|
+
expect{
|
82
|
+
subject.run_vagrant_command('hostname')
|
83
|
+
}.to raise_error(Kuroko::VagrantSshCommandError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "doesn't check the exit status with no_verify" do
|
87
|
+
mock_env.stub_chain(:primary_vm, :channel, :send){ 1 }
|
88
|
+
|
89
|
+
expect{
|
90
|
+
subject.run_vagrant_command('hostname', no_verify: true)
|
91
|
+
}.to_not raise_error(Kuroko::VagrantSshCommandError)
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "running commands with sudo" do
|
95
|
+
it "sets the vagrant command to sudo" do
|
96
|
+
subject.should_receive(:run_command).with(:sudo, 'hostname', {})
|
97
|
+
subject.run_sudo_command('hostname')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kuroko
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt House
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: vagrant
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: cucumber
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
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
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Cucumber Plugin for testing Puppet manifests using Vagrant
|
79
|
+
email:
|
80
|
+
- matt@eightbitraptor.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- kuroko.gemspec
|
91
|
+
- lib/core_ext/cucumber/rb_language.rb
|
92
|
+
- lib/kuroko.rb
|
93
|
+
- lib/kuroko/configuration.rb
|
94
|
+
- lib/kuroko/errors.rb
|
95
|
+
- lib/kuroko/vagrant_support.rb
|
96
|
+
- spec/cucumber_core_ext_spec.rb
|
97
|
+
- spec/kuroko_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/vagrant_support_spec.rb
|
100
|
+
homepage: ''
|
101
|
+
licenses: []
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
hash: -1966606780301347984
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
hash: -1966606780301347984
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 1.8.24
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: Cucumber Plugin for testing Puppet manifests using Vagrant
|
130
|
+
test_files:
|
131
|
+
- spec/cucumber_core_ext_spec.rb
|
132
|
+
- spec/kuroko_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
- spec/vagrant_support_spec.rb
|