harrison 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+
3
+ describe Harrison::Package do
4
+ let(:instance) do
5
+ Harrison::Package.new.tap do |p|
6
+ p.project = 'test_project'
7
+ p.host = 'hf_host'
8
+ p.commit = 'HEAD'
9
+ end
10
+ end
11
+
12
+ describe '.initialize' do
13
+ it 'should add --commit to arg_opts' do
14
+ instance.instance_variable_get('@arg_opts').to_s.should include(':commit')
15
+ end
16
+
17
+ it 'should add --purge to arg_opts' do
18
+ instance.instance_variable_get('@arg_opts').to_s.should include(':purge')
19
+ end
20
+
21
+ it 'should add --pkg-dir to arg_opts' do
22
+ instance.instance_variable_get('@arg_opts').to_s.should include(':pkg_dir')
23
+ end
24
+
25
+ it 'should add --remote-dir to arg_opts' do
26
+ instance.instance_variable_get('@arg_opts').to_s.should include(':remote_dir')
27
+ end
28
+
29
+ it 'should persist options' do
30
+ instance = Harrison::Package.new(testopt: 'foo')
31
+
32
+ instance.instance_variable_get('@options').should include(testopt: 'foo')
33
+ end
34
+ end
35
+
36
+ describe 'instance methods' do
37
+ describe '#remote_exec' do
38
+ before(:each) do
39
+ @mock_ssh = double(:ssh)
40
+ allow(instance).to receive(:ssh).and_return(@mock_ssh)
41
+ allow(instance).to receive(:ensure_remote_dir).and_return(true)
42
+ end
43
+
44
+ it 'should prepend remote build dir onto passed command' do
45
+ instance.remote_dir = '~/.harrison'
46
+ instance.project = 'test_project'
47
+
48
+ expect(@mock_ssh).to receive(:exec).with("cd ~/.harrison/test_project/package && test_command").and_return('')
49
+
50
+ instance.remote_exec("test_command")
51
+ end
52
+ end
53
+
54
+ describe '#run' do
55
+ context 'when passed a block' do
56
+ it 'should store the block' do
57
+ test_block = Proc.new { |test| "block_output" }
58
+ instance.run(&test_block)
59
+
60
+ instance.instance_variable_get("@run_block").should == test_block
61
+ end
62
+ end
63
+
64
+ context 'when not passed a block' do
65
+ before(:each) do
66
+ @mock_ssh = double(:ssh, exec: '', upload: true, download: true)
67
+ allow(instance).to receive(:ssh).at_least(:once).and_return(@mock_ssh)
68
+
69
+ allow(instance).to receive(:ensure_local_dir).and_return(true)
70
+ allow(instance).to receive(:resolve_commit!).and_return('test')
71
+ allow(instance).to receive(:excludes_for_tar).and_return('')
72
+ end
73
+
74
+ it 'should invoke the previously stored block once with host' do
75
+ test_block = Proc.new { |test| puts "block for #{test.host}" }
76
+ instance.run(&test_block)
77
+
78
+ output = capture(:stdout) do
79
+ instance.run
80
+ end
81
+
82
+ output.should include('block for hf_host')
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ describe 'protected methods' do
89
+ describe '#remote_project_dir' do
90
+ it 'should combine remote dir and project name' do
91
+ instance.remote_dir = '~/.harrison'
92
+ instance.project = 'test_project'
93
+
94
+ instance.send(:remote_project_dir).should include('~/.harrison', 'test_project')
95
+ end
96
+ end
97
+
98
+ describe '#resolve_commit!' do
99
+ it 'should resolve commit reference to a short sha using git rev-parse' do
100
+ instance.commit = 'giant'
101
+ expect(instance).to receive(:exec).with(/git rev-parse.*giant/).and_return('fef1f0')
102
+
103
+ instance.send(:resolve_commit!).should == 'fef1f0'
104
+ end
105
+ end
106
+
107
+ describe '#excludes_for_tar' do
108
+ it 'should return an empty string if exclude is nil' do
109
+ instance.exclude = nil
110
+
111
+ instance.send(:excludes_for_tar).should == ''
112
+ end
113
+
114
+ it 'should return an empty string if exclude is empty' do
115
+ instance.exclude = []
116
+
117
+ instance.send(:excludes_for_tar).should == ''
118
+ end
119
+
120
+ it 'should return an --exclude option for each member of exclude' do
121
+ instance.exclude = [ 'fee', 'fi', 'fo', 'fum' ]
122
+
123
+ instance.send(:excludes_for_tar).scan(/--exclude/).size.should == instance.exclude.size
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Harrison::SSH do
4
+ pending
5
+ end
@@ -0,0 +1,157 @@
1
+ require 'spec_helper'
2
+
3
+ describe Harrison do
4
+ before(:all) do
5
+ [ :@@args, :@@packager, :@@deployer, :@@config, :@@runner ].each do |class_var|
6
+ Harrison.class_variable_set(class_var, nil)
7
+ end
8
+ end
9
+
10
+ after(:each) do
11
+ [ :@@args, :@@packager, :@@deployer, :@@config, :@@runner ].each do |class_var|
12
+ Harrison.class_variable_set(class_var, nil)
13
+ end
14
+ end
15
+
16
+ describe '.invoke' do
17
+ it 'should exit when no args are passed' do
18
+ output = capture(:stderr) do
19
+ lambda { Harrison.invoke([]) }.should exit_with_code(1)
20
+ end
21
+
22
+ output.should include('no', 'command', 'given')
23
+ end
24
+
25
+ it 'should output base help when first arg is --help' do
26
+ output = capture(:stdout) do
27
+ lambda { Harrison.invoke(['--help']) }.should exit_with_code(0)
28
+ end
29
+
30
+ output.should include('options', 'debug', 'help')
31
+ end
32
+
33
+ it 'should look for a Harrisonfile' do
34
+ expect(Harrison).to receive(:find_harrisonfile).and_return(harrisonfile_fixture_path)
35
+
36
+ output = capture(:stderr) do
37
+ lambda { Harrison.invoke(['test']) }.should exit_with_code(1)
38
+ end
39
+
40
+ output.should include('unrecognized', 'command', 'test')
41
+ end
42
+
43
+ it 'should complain if unable to find a Harrisonfile' do
44
+ expect(Harrison).to receive(:find_harrisonfile).and_return(nil)
45
+
46
+ output = capture(:stderr) do
47
+ lambda { Harrison.invoke(['test']) }.should exit_with_code(1)
48
+ end
49
+
50
+ output.should include('could', 'not', 'find', 'harrisonfile')
51
+ end
52
+ end
53
+
54
+ describe '.config' do
55
+ it 'should return a new Harrison::Config' do
56
+ mock_config = double(:config)
57
+ expect(Harrison::Config).to receive(:new).and_return(mock_config)
58
+
59
+ Harrison.config.should == mock_config
60
+ end
61
+
62
+ it 'should return existing Harrison::Config if defined' do
63
+ mock_config = double(:config)
64
+ Harrison.class_variable_set(:@@config, mock_config)
65
+ expect(Harrison::Config).to_not receive(:new)
66
+
67
+ Harrison.config.should == mock_config
68
+ end
69
+
70
+ it 'should yield config if given a block' do
71
+ mock_config = double(:config)
72
+ Harrison.class_variable_set(:@@config, mock_config)
73
+
74
+ expect { |b| Harrison.config(&b) }.to yield_with_args(mock_config)
75
+ end
76
+ end
77
+
78
+ describe '.package' do
79
+ before(:each) do
80
+ Harrison.class_variable_set(:@@args, ['package'])
81
+ Harrison.class_variable_set(:@@runner, lambda { Harrison.class_variable_get(:@@packager) if Harrison.class_variable_defined?(:@@packager) })
82
+ end
83
+
84
+ it 'should yield a new Harrison::Package' do
85
+ mock_package = double(:package, parse: true)
86
+ expect(Harrison::Package).to receive(:new).and_return(mock_package)
87
+
88
+ expect { |b| Harrison.package(&b) }.to yield_with_args(mock_package)
89
+ end
90
+
91
+ it 'should yield existing Harrison::Package if defined' do
92
+ mock_package = double(:package, parse: true)
93
+ Harrison.class_variable_set(:@@packager, mock_package)
94
+ expect(Harrison::Package).to_not receive(:new)
95
+
96
+ expect { |b| Harrison.package(&b) }.to yield_with_args(mock_package)
97
+ end
98
+ end
99
+
100
+ describe '.deploy' do
101
+ before(:each) do
102
+ Harrison.class_variable_set(:@@args, ['deploy'])
103
+ Harrison.class_variable_set(:@@runner, lambda { Harrison.class_variable_get(:@@deployer) if Harrison.class_variable_defined?(:@@deployer) })
104
+ end
105
+
106
+ it 'should yield a new Harrison::Deploy' do
107
+ mock_deploy = double(:deploy, parse: true)
108
+ expect(Harrison::Deploy).to receive(:new).and_return(mock_deploy)
109
+
110
+ expect { |b| Harrison.deploy(&b) }.to yield_with_args(mock_deploy)
111
+ end
112
+
113
+ it 'should yield existing Harrison::Package if defined' do
114
+ mock_deploy = double(:deploy, parse: true)
115
+ Harrison.class_variable_set(:@@deployer, mock_deploy)
116
+ expect(Harrison::Deploy).to_not receive(:new)
117
+
118
+ expect { |b| Harrison.deploy(&b) }.to yield_with_args(mock_deploy)
119
+ end
120
+ end
121
+
122
+ context 'private methods' do
123
+ describe '.find_harrisonfile' do
124
+ it 'should find a Harrisonfile if it exists in pwd' do
125
+ expect(Dir).to receive(:pwd).and_return(fixture_path)
126
+
127
+ Harrison.send(:find_harrisonfile).should == harrisonfile_fixture_path
128
+ end
129
+
130
+ it 'should find a Harrisonfile if it exists in parent of pwd' do
131
+ expect(Dir).to receive(:pwd).and_return(fixture_path + '/nested')
132
+
133
+ Harrison.send(:find_harrisonfile).should == harrisonfile_fixture_path
134
+ end
135
+
136
+ it 'should return nil if there is no Harrisonfile in tree' do
137
+ expect(Dir).to receive(:pwd).and_return(File.dirname(__FILE__))
138
+
139
+ # Short circuit upward directory traversal.
140
+ allow(File).to receive(:expand_path).and_call_original
141
+ allow(File).to receive(:expand_path).with("..", File.dirname(__FILE__)).and_return(File.dirname(__FILE__))
142
+
143
+ Harrison.send(:find_harrisonfile).should be_nil
144
+ end
145
+ end
146
+
147
+ describe '.eval_script' do
148
+ it 'should eval given script' do
149
+ output = capture(:stdout) do
150
+ Harrison.send(:eval_script, fixture_path + '/eval_script.rb')
151
+ end
152
+
153
+ output.should == "this file was eval-led\n"
154
+ end
155
+ end
156
+ end
157
+ end
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harrison
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jesse Scott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: trollop
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: net-ssh
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: net-scp
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
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.6'
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: '1.6'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: debugger
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: sourcify
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description:
143
+ email:
144
+ - jesse@puppetlabs.com
145
+ executables:
146
+ - harrison
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - .gitignore
151
+ - .rspec
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - TODO
157
+ - bin/harrison
158
+ - harrison.gemspec
159
+ - lib/harrison.rb
160
+ - lib/harrison/base.rb
161
+ - lib/harrison/config.rb
162
+ - lib/harrison/deploy.rb
163
+ - lib/harrison/package.rb
164
+ - lib/harrison/ssh.rb
165
+ - lib/harrison/version.rb
166
+ - spec/fixtures/Harrisonfile
167
+ - spec/fixtures/eval_script.rb
168
+ - spec/fixtures/nested/.gitkeep
169
+ - spec/spec_helper.rb
170
+ - spec/unit/harrison/base_spec.rb
171
+ - spec/unit/harrison/deploy_spec.rb
172
+ - spec/unit/harrison/package_spec.rb
173
+ - spec/unit/harrison/ssh_spec.rb
174
+ - spec/unit/harrison_spec.rb
175
+ homepage: https://github.com/scotje/harrison
176
+ licenses:
177
+ - Apache 2.0
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: 1.9.3
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ segments:
195
+ - 0
196
+ hash: 1981909616735500300
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 1.8.29
200
+ signing_key:
201
+ specification_version: 3
202
+ summary: Simple artifact-based deployment for web applications.
203
+ test_files:
204
+ - spec/fixtures/Harrisonfile
205
+ - spec/fixtures/eval_script.rb
206
+ - spec/fixtures/nested/.gitkeep
207
+ - spec/spec_helper.rb
208
+ - spec/unit/harrison/base_spec.rb
209
+ - spec/unit/harrison/deploy_spec.rb
210
+ - spec/unit/harrison/package_spec.rb
211
+ - spec/unit/harrison/ssh_spec.rb
212
+ - spec/unit/harrison_spec.rb