kitchen-scribe 0.1.0
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/.gitignore +1 -0
- data/.rvmrc +34 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +73 -0
- data/LICENSE +201 -0
- data/README.md +63 -0
- data/kitchen-scribe.gemspec +23 -0
- data/lib/chef/knife/scribe_copy.rb +165 -0
- data/lib/chef/knife/scribe_hire.rb +92 -0
- data/lib/kitchen-scribe/version.rb +4 -0
- data/spec/chef/knife/scribe_copy_spec.rb +492 -0
- data/spec/chef/knife/scribe_hire_spec.rb +253 -0
- data/spec/spec_helper.rb +23 -0
- metadata +127 -0
@@ -0,0 +1,253 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Pawel Kozlowski (<pawel.kozlowski@u2i.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Pawel Kozlowski
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
20
|
+
|
21
|
+
describe Chef::Knife::ScribeHire do
|
22
|
+
before(:each) do
|
23
|
+
Dir.stub!(:mkdir)
|
24
|
+
Dir.stub!(:pwd) { "some_path" }
|
25
|
+
@scribe = Chef::Knife::ScribeHire.new
|
26
|
+
Chef::Config[:knife][:scribe] = {}
|
27
|
+
@scribe.configure
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#run" do
|
31
|
+
before(:each) do
|
32
|
+
@scribe.stub(:setup_remote)
|
33
|
+
@scribe.stub(:init_chronicle)
|
34
|
+
File.stub!(:directory?) { false }
|
35
|
+
end
|
36
|
+
|
37
|
+
it "calls #configure" do
|
38
|
+
@scribe.should_receive(:configure)
|
39
|
+
@scribe.run
|
40
|
+
end
|
41
|
+
|
42
|
+
it "creates the main chronicle directory in the chronicle path" do
|
43
|
+
Dir.should_receive(:mkdir).with(@scribe.config[:chronicle_path])
|
44
|
+
@scribe.run
|
45
|
+
end
|
46
|
+
|
47
|
+
it "creates the environments subdirectory in the chronicle path" do
|
48
|
+
Dir.should_receive(:mkdir).with(File.join(@scribe.config[:chronicle_path], "environments"))
|
49
|
+
@scribe.run
|
50
|
+
end
|
51
|
+
|
52
|
+
it "creates the nodes subdirectory in the chronicle path" do
|
53
|
+
Dir.should_receive(:mkdir).with(File.join(@scribe.config[:chronicle_path], "nodes"))
|
54
|
+
@scribe.run
|
55
|
+
end
|
56
|
+
|
57
|
+
it "creates the roles subdirectory in the chronicle path" do
|
58
|
+
Dir.should_receive(:mkdir).with(File.join(@scribe.config[:chronicle_path], "roles"))
|
59
|
+
@scribe.run
|
60
|
+
end
|
61
|
+
|
62
|
+
it "calls #init_chronicle" do
|
63
|
+
@scribe.should_receive(:init_chronicle)
|
64
|
+
@scribe.run
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "when remote url was not specified" do
|
68
|
+
it "doesn't call #setup_remote" do
|
69
|
+
@scribe.should_not_receive(:setup_remote)
|
70
|
+
@scribe.run
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "when remote url was specified" do
|
75
|
+
before(:each) do
|
76
|
+
@scribe.config[:remote_url] = "some_url"
|
77
|
+
end
|
78
|
+
it "calls #setup_remote" do
|
79
|
+
@scribe.should_receive(:setup_remote)
|
80
|
+
@scribe.run
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#configure" do
|
86
|
+
describe "when no configuration is given" do
|
87
|
+
before(:each) do
|
88
|
+
@scribe.config = {}
|
89
|
+
Chef::Config[:knife][:scribe] = nil
|
90
|
+
end
|
91
|
+
|
92
|
+
it "uses the default values for all parameters" do
|
93
|
+
@scribe.configure
|
94
|
+
@scribe.config[:chronicle_path].should == Chef::Knife::ScribeHire::DEFAULT_CHRONICLE_PATH
|
95
|
+
@scribe.config[:remote_name].should == Chef::Knife::ScribeHire::DEFAULT_REMOTE_NAME
|
96
|
+
@scribe.config[:remote_url].should be_nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "when configuration is given through knife config" do
|
101
|
+
before(:each) do
|
102
|
+
Chef::Config[:knife][:scribe] = {}
|
103
|
+
Chef::Config[:knife][:scribe][:chronicle_path] = Chef::Knife::ScribeHire::DEFAULT_CHRONICLE_PATH + "_knife"
|
104
|
+
Chef::Config[:knife][:scribe][:remote_name] = Chef::Knife::ScribeHire::DEFAULT_REMOTE_NAME + "_knife"
|
105
|
+
Chef::Config[:knife][:scribe][:remote_url] = "remote_url_knife"
|
106
|
+
@scribe.config = {}
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "when no other configuration is given" do
|
110
|
+
before(:each) do
|
111
|
+
@scribe.config = {}
|
112
|
+
end
|
113
|
+
|
114
|
+
it "uses the configuration from knife config" do
|
115
|
+
@scribe.configure
|
116
|
+
@scribe.config[:chronicle_path].should == Chef::Config[:knife][:scribe][:chronicle_path]
|
117
|
+
@scribe.config[:remote_name].should == Chef::Config[:knife][:scribe][:remote_name]
|
118
|
+
@scribe.config[:remote_url].should == Chef::Config[:knife][:scribe][:remote_url]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "when command line configuration is given" do
|
123
|
+
before(:each) do
|
124
|
+
@scribe.config[:chronicle_path] = Chef::Knife::ScribeHire::DEFAULT_CHRONICLE_PATH + "_cmd"
|
125
|
+
@scribe.config[:remote_name] = Chef::Knife::ScribeHire::DEFAULT_REMOTE_NAME + "_cmd"
|
126
|
+
@scribe.config[:remote_url] = "remote_url_cmd"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "uses the configuration from command line" do
|
130
|
+
@scribe.configure
|
131
|
+
@scribe.config[:chronicle_path].should == Chef::Knife::ScribeHire::DEFAULT_CHRONICLE_PATH + "_cmd"
|
132
|
+
@scribe.config[:remote_name].should == Chef::Knife::ScribeHire::DEFAULT_REMOTE_NAME + "_cmd"
|
133
|
+
@scribe.config[:remote_url].should == "remote_url_cmd"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
describe "#init_chronicle" do
|
141
|
+
it "invokes the git init shell command" do
|
142
|
+
@scribe.should_receive(:shell_out!).with("git init", { :cwd => @scribe.config[:chronicle_path] })
|
143
|
+
@scribe.init_chronicle
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "#setup_remote" do
|
148
|
+
describe "when both remote name and url are set" do
|
149
|
+
before(:each) do
|
150
|
+
@remote_url = "a_repo_url"
|
151
|
+
@remote_name = "a_repo_name"
|
152
|
+
@scribe.config[:remote_url] = @remote_url
|
153
|
+
@scribe.config[:remote_name] = @remote_name
|
154
|
+
end
|
155
|
+
|
156
|
+
it "checks if a remote with this name already exists" do
|
157
|
+
command_response = double('shell_out')
|
158
|
+
command_response.stub(:exitstatus) { 1 }
|
159
|
+
@scribe.stub(:shell_out!) { command_response }
|
160
|
+
expected_command = "git config --get remote.#{@remote_name}.url"
|
161
|
+
@scribe.should_receive(:shell_out!).with(expected_command,
|
162
|
+
:cwd => @scribe.config[:chronicle_path],
|
163
|
+
:returns => [0,1,2])
|
164
|
+
@scribe.setup_remote
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "when the remote of that name does not exist" do
|
168
|
+
it "adds a new remote" do
|
169
|
+
command_response = double('shell_out')
|
170
|
+
command_response.stub(:exitstatus) { 1 }
|
171
|
+
expected_command = "git config --get remote.#{@remote_name}.url"
|
172
|
+
@scribe.should_receive(:shell_out!).with(expected_command,
|
173
|
+
:cwd => @scribe.config[:chronicle_path],
|
174
|
+
:returns => [0,1,2]).and_return(command_response)
|
175
|
+
add_remote_command = "git remote add #{@remote_name} #{@remote_url}"
|
176
|
+
@scribe.should_receive(:shell_out!).with(add_remote_command,
|
177
|
+
:cwd => @scribe.config[:chronicle_path])
|
178
|
+
@scribe.setup_remote
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "when a remote with a given name has already been configured" do
|
183
|
+
describe "when it has a different url" do
|
184
|
+
it "updates the remote url" do
|
185
|
+
command_response = double('shell_out')
|
186
|
+
command_response.stub(:exitstatus) { 0 }
|
187
|
+
command_response.stub(:stdout) { "previous" + @remote_url }
|
188
|
+
expected_command = "git config --get remote.#{@remote_name}.url"
|
189
|
+
@scribe.should_receive(:shell_out!).with(expected_command,
|
190
|
+
:cwd => @scribe.config[:chronicle_path],
|
191
|
+
:returns => [0,1,2]).and_return(command_response)
|
192
|
+
update_remote_url_command = "git config --replace-all remote.#{@remote_name}.url #{@remote_url}"
|
193
|
+
@scribe.should_receive(:shell_out!).with(update_remote_url_command,
|
194
|
+
:cwd => @scribe.config[:chronicle_path])
|
195
|
+
@scribe.setup_remote
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
describe "when it has multiple values" do
|
201
|
+
it "resets the url" do
|
202
|
+
command_response = double('shell_out')
|
203
|
+
command_response.stub(:exitstatus) { 2 }
|
204
|
+
command_response.stub(:stdout) { "previous" + @remote_url }
|
205
|
+
expected_command = "git config --get remote.#{@remote_name}.url"
|
206
|
+
@scribe.should_receive(:shell_out!).with(expected_command,
|
207
|
+
:cwd => @scribe.config[:chronicle_path],
|
208
|
+
:returns => [0,1,2]).and_return(command_response)
|
209
|
+
update_remote_url_command = "git config --replace-all remote.#{@remote_name}.url #{@remote_url}"
|
210
|
+
@scribe.should_receive(:shell_out!).with(update_remote_url_command,
|
211
|
+
:cwd => @scribe.config[:chronicle_path])
|
212
|
+
@scribe.setup_remote
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe "when it has the same url" do
|
217
|
+
it "does nothing" do
|
218
|
+
command_response = double('shell_out')
|
219
|
+
command_response.stub(:exitstatus) { 0 }
|
220
|
+
command_response.stub(:stdout) { @remote_url }
|
221
|
+
expected_command = "git config --get remote.#{@remote_name}.url"
|
222
|
+
@scribe.should_receive(:shell_out!).with(expected_command,
|
223
|
+
:cwd => @scribe.config[:chronicle_path],
|
224
|
+
:returns => [0,1,2]).and_return(command_response)
|
225
|
+
@scribe.should_receive(:shell_out!).exactly(0).times
|
226
|
+
@scribe.setup_remote
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe "when only the remote url is set" do
|
233
|
+
before(:each) do
|
234
|
+
@remote_url = "a_repo_url"
|
235
|
+
@default_remote_name = "origin"
|
236
|
+
@scribe.config[:remote_url] = @remote_url
|
237
|
+
end
|
238
|
+
|
239
|
+
it "uses a default remote name" do
|
240
|
+
command_response = double('shell_out')
|
241
|
+
command_response.stub(:exitstatus) { 1 }
|
242
|
+
expected_command = "git config --get remote.#{@default_remote_name}.url"
|
243
|
+
@scribe.should_receive(:shell_out!).with(expected_command,
|
244
|
+
:cwd => @scribe.config[:chronicle_path],
|
245
|
+
:returns => [0,1,2]).and_return(command_response)
|
246
|
+
add_remote_command = "git remote add #{@default_remote_name} #{@remote_url}"
|
247
|
+
@scribe.should_receive(:shell_out!).with(add_remote_command,
|
248
|
+
:cwd => @scribe.config[:chronicle_path])
|
249
|
+
@scribe.setup_remote
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Pawel Kozlowski (<pawel.kozlowski@u2i.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Pawel Kozlowski
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
20
|
+
|
21
|
+
require 'chef/knife'
|
22
|
+
require 'chef/knife/scribe_hire'
|
23
|
+
require 'chef/knife/scribe_copy'
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitchen-scribe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pawel Kozlowski
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.10
|
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.10.10
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec-core
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
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-expectations
|
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: rspec-mocks
|
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: Knife plugin for tracking your chef configuration changes
|
79
|
+
email:
|
80
|
+
- pawel.kozlowski@u2i.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files:
|
84
|
+
- README.md
|
85
|
+
- LICENSE
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .rvmrc
|
89
|
+
- Gemfile
|
90
|
+
- Gemfile.lock
|
91
|
+
- LICENSE
|
92
|
+
- README.md
|
93
|
+
- kitchen-scribe.gemspec
|
94
|
+
- lib/chef/knife/scribe_copy.rb
|
95
|
+
- lib/chef/knife/scribe_hire.rb
|
96
|
+
- lib/kitchen-scribe/version.rb
|
97
|
+
- spec/chef/knife/scribe_copy_spec.rb
|
98
|
+
- spec/chef/knife/scribe_hire_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
homepage: https://github.com/khozlov/kitchen-scribe
|
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
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.8.24
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Knife plugin for tracking your chef configuration changes
|
124
|
+
test_files:
|
125
|
+
- spec/chef/knife/scribe_copy_spec.rb
|
126
|
+
- spec/chef/knife/scribe_hire_spec.rb
|
127
|
+
- spec/spec_helper.rb
|