kknife 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,111 @@
1
+ # Author: Matt Hoyle (<matt@deployable.co>)
2
+ # Copyright: Copyright (c) 2013 Deployable Ltd.
3
+ # License: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'spec_helper'
18
+
19
+ describe Knifecmd do
20
+
21
+ before :each do
22
+ @k = Knifecmd.new
23
+ end
24
+
25
+
26
+ it "resolves commands correctly" do
27
+
28
+ tests = [
29
+ %w( download something ),
30
+ %w( node edit nodename -s http://someserver ),
31
+ %w( environment list ),
32
+ %w( environment edit production ),
33
+ %w( data bag from file /path/to/somefile ),
34
+ %w( cookbook upload ),
35
+ %w( client bulk delete ),
36
+ ]
37
+
38
+ tests.each do |test|
39
+ expect( @k.resolve( test ) ).to eq( test )
40
+ end
41
+ end
42
+
43
+
44
+ it "resolves command with _'s" do
45
+
46
+ tests = [
47
+ [ %w( node run_list add recipe[something] ), %w( node run list add recipe[something] ) ],
48
+ ]
49
+
50
+ tests.each do |test,result|
51
+ expect( @k.resolve( test ) ).to eq( result )
52
+ end
53
+ end
54
+
55
+
56
+
57
+ tests = [
58
+ [ %w( d something ), %w( download something ) ],
59
+ [ %w( n e nodename ), %w( node edit nodename ) ],
60
+ [ %w( e l ), %w( environment list )],
61
+ [ %w( en l ), %w( environment list )],
62
+ [ %w( en e production ), %w( environment edit production )],
63
+ [ %w( da b f f /to/file ), %w( data bag from file /to/file )],
64
+ [ %w( coo u ), %w( cookbook upload )],
65
+ [ %w( cl b d ), %w( client bulk delete )],
66
+ [ %w( re l ), %w( recipe list )],
67
+ [ %w( ro l ), %w( role list )],
68
+ ]
69
+
70
+ tests.each do |test,result|
71
+ it "resolves shortened command [#{test}]" do
72
+ expect( @k.resolve( test ) ).to eq( result )
73
+ end
74
+ end
75
+
76
+
77
+
78
+ tests = [
79
+ [ %w( ne nodename ), %w( node edit nodename) ],
80
+ [ %w( ns nodename ), %w( node show nodename) ],
81
+ [ %w( client bd ), %w( client bulk delete) ],
82
+ [ %w( client bd ), %w( client bulk delete) ],
83
+ [ %w( cs download ), %w( cookbook site download) ],
84
+ [ %w( db ff /path/file ), %w( data bag from file /path/file ) ],
85
+ [ %w( node rl remove role[something] ), %w( node run list remove role[something] ) ],
86
+ ]
87
+
88
+ tests.each do |test,result|
89
+ it "resolve shortcuts" do
90
+ expect( @k.resolve( test ) ).to eq( result )
91
+ end
92
+ end
93
+
94
+
95
+
96
+ tests = [
97
+ [ %w( c u ), %w( cookbook upload ) ],
98
+ [ %w( c b d ), %w( cookbook bulk delete ) ],
99
+ [ %w( e show dev ), %w( environment show dev ) ],
100
+ [ %w( d ), %w( download ) ],
101
+ [ %w( r list ), %w( role list ) ],
102
+ ]
103
+
104
+ tests.each do |test,result|
105
+ it "resolve ambiguous commands" do
106
+ expect( @k.resolve( test ) ).to eq( result )
107
+ end
108
+ end
109
+
110
+ end
111
+
@@ -0,0 +1,144 @@
1
+ # Author: Matt Hoyle (<matt@deployable.co>)
2
+ # Copyright: Copyright (c) 2013 Deployable Ltd.
3
+ # License: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative '../lib/kknife'
18
+
19
+
20
+ require 'stringio'
21
+
22
+
23
+ RSpec::Matchers.define :match_stdout do |check|
24
+
25
+ @capture = nil
26
+
27
+ match do |block|
28
+
29
+ begin
30
+ stdout_saved = $stdout
31
+ $stdout = StringIO.new
32
+ block.call
33
+ ensure
34
+ @capture = $stdout
35
+ $stdout = stdout_saved
36
+ end
37
+
38
+ @capture.string.match check
39
+ end
40
+
41
+ failure_message_for_should do
42
+ "expected to #{description}"
43
+ end
44
+ failure_message_for_should_not do
45
+ "expected not to #{description}"
46
+ end
47
+ description do
48
+ "match [#{check}] \non stdout [#{@capture.string}]"
49
+ end
50
+
51
+ end
52
+
53
+
54
+ RSpec::Matchers.define :stdout do |check|
55
+
56
+ @capture = nil
57
+
58
+ match do |block|
59
+
60
+ begin
61
+ stdout_saved = $stdout
62
+ $stdout = StringIO.new
63
+ block.call
64
+ ensure
65
+ @capture = $stdout
66
+ $stdout = stdout_saved
67
+ end
68
+
69
+ @capture.string == check
70
+ end
71
+
72
+ failure_message_for_should do
73
+ "expected stdout to be #{description}"
74
+ end
75
+ failure_message_for_should_not do
76
+ "expected stdout not to be #{description}"
77
+ end
78
+ description do
79
+ "[#{check}] \nbut got [#{@capture.string}]"
80
+ end
81
+
82
+ end
83
+
84
+
85
+ RSpec::Matchers.define :stderr do |check|
86
+
87
+ @capture = nil
88
+
89
+ match do |block|
90
+
91
+ begin
92
+ stdout_saved = $stderr
93
+ $stderr = StringIO.new
94
+ block.call
95
+ ensure
96
+ @capture = $stderr
97
+ $stderr = stdout_saved
98
+ end
99
+
100
+ @capture.string == check
101
+ end
102
+
103
+ failure_message_for_should do
104
+ "expected stderr to be #{description}"
105
+ end
106
+ failure_message_for_should_not do
107
+ "expected stderr not to be #{description}"
108
+ end
109
+ description do
110
+ "[#{check}] \nbut got [#{@capture.string}]"
111
+ end
112
+
113
+ end
114
+
115
+
116
+ RSpec::Matchers.define :match_stderr do |check|
117
+
118
+ @capture = nil
119
+
120
+ match do |block|
121
+
122
+ begin
123
+ stdout_saved = $stderr
124
+ $stderr = StringIO.new
125
+ block.call
126
+ ensure
127
+ @capture = $stderr
128
+ $stderr = stdout_saved
129
+ end
130
+
131
+ @capture.string.match check
132
+ end
133
+
134
+ failure_message_for_should do
135
+ "expected stderr to be #{description}"
136
+ end
137
+ failure_message_for_should_not do
138
+ "expected stderr not to be #{description}"
139
+ end
140
+ description do
141
+ "[#{check}] \nbut got [#{@capture.string}]"
142
+ end
143
+
144
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kknife
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Hoyle
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-13 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: '11.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: '11.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: trollop
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.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: '2.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-core
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.13.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: 2.13.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-expectations
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.13.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: 2.13.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-mocks
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.13.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: 2.13.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: chef-zero
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '1.7'
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: '1.7'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rest_client
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.6'
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: '1.6'
126
+ description: k shortcut commands for knife
127
+ email: matt@deployable.co
128
+ executables:
129
+ - k
130
+ extensions: []
131
+ extra_rdoc_files:
132
+ - LICENSE
133
+ - README.md
134
+ files:
135
+ - LICENSE
136
+ - README.md
137
+ - lib/kknife/command.rb
138
+ - lib/kknife/dbg.rb
139
+ - lib/kknife/k2.rb
140
+ - lib/kknife/knifecmd.rb
141
+ - lib/kknife/log.rb
142
+ - lib/kknife/lookup.rb
143
+ - lib/kknife/version.rb
144
+ - lib/kknife.rb
145
+ - spec/command_spec.rb
146
+ - spec/helpers.rb
147
+ - spec/knifecmd_spec.rb
148
+ - spec/k_spec.rb
149
+ - spec/spec_helper.rb
150
+ - bin/k
151
+ homepage: http://deployable.co
152
+ licenses:
153
+ - Apache
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 1.8.24
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: Shortcuts for the chef knife command
176
+ test_files: []
177
+ has_rdoc: