summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorjkeiser <jkeiser@opscode.com>2013-01-16 11:01:41 -0800
committerJohn Keiser <jkeiser@opscode.com>2013-06-07 13:12:20 -0700
commitf35c1a48f4098185dc6feefc7c2e80d4311f770e (patch)
tree48d67185d290d0a5a824c363d1187f91bc3ce526 /spec
parent5cf1446795ceaefb7e926726eb27f38bd19a69b2 (diff)
downloadchef-f35c1a48f4098185dc6feefc7c2e80d4311f770e.tar.gz
Make knife show exit with error code on error
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/knife/delete_spec.rb18
-rw-r--r--spec/integration/knife/show_spec.rb124
2 files changed, 133 insertions, 9 deletions
diff --git a/spec/integration/knife/delete_spec.rb b/spec/integration/knife/delete_spec.rb
index c233b6eb05..6f2a4f5afc 100644
--- a/spec/integration/knife/delete_spec.rb
+++ b/spec/integration/knife/delete_spec.rb
@@ -6,8 +6,8 @@ describe 'knife delete' do
extend IntegrationSupport
include KnifeSupport
- let :everything do
- <<EOM
+ let :everything do
+ <<EOM
/cookbooks
/cookbooks/x
/cookbooks/x/metadata.rb
@@ -20,26 +20,26 @@ describe 'knife delete' do
/roles
/roles/x.json
EOM
- end
+ end
- let :server_nothing do
- <<EOM
+ let :server_nothing do
+ <<EOM
/cookbooks
/data_bags
/environments
/environments/_default.json
/roles
EOM
- end
+ end
- let :nothing do
- <<EOM
+ let :nothing do
+ <<EOM
/cookbooks
/data_bags
/environments
/roles
EOM
- end
+ end
when_the_chef_server "has one of each thing" do
client 'x', '{}'
diff --git a/spec/integration/knife/show_spec.rb b/spec/integration/knife/show_spec.rb
new file mode 100644
index 0000000000..97a14bfe85
--- /dev/null
+++ b/spec/integration/knife/show_spec.rb
@@ -0,0 +1,124 @@
+require 'support/shared/integration/integration_helper'
+require 'chef/knife/show'
+
+describe 'knife show' do
+ extend IntegrationSupport
+ include KnifeSupport
+
+ when_the_chef_server "has one of each thing" do
+ client 'x', '{}'
+ cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
+ data_bag 'x', { 'y' => '{}' }
+ environment 'x', '{}'
+ node 'x', '{}'
+ role 'x', '{}'
+ user 'x', '{}'
+
+ when_the_repository 'also has one of each thing' do
+ file 'clients/x.json', { 'foo' => 'bar' }
+ file 'cookbooks/x/metadata.rb', 'version "1.0.1"'
+ file 'data_bags/x/y.json', { 'foo' => 'bar' }
+ file 'environments/_default.json', { 'foo' => 'bar' }
+ file 'environments/x.json', { 'foo' => 'bar' }
+ file 'nodes/x.json', { 'foo' => 'bar' }
+ file 'roles/x.json', { 'foo' => 'bar' }
+ file 'users/x.json', { 'foo' => 'bar' }
+
+ it 'knife show /cookbooks/x/metadata.rb shows the remote version' do
+ knife('show /cookbooks/x/metadata.rb').should_succeed <<EOM
+/cookbooks/x/metadata.rb:
+version "1.0.0"
+EOM
+ end
+ it 'knife show --local /cookbooks/x/metadata.rb shows the local version' do
+ knife('show --local /cookbooks/x/metadata.rb').should_succeed <<EOM
+/cookbooks/x/metadata.rb:
+version "1.0.1"
+EOM
+ end
+ it 'knife show /data_bags/x/y.json shows the remote version' do
+ knife('show /data_bags/x/y.json').should_succeed <<EOM
+/data_bags/x/y.json:
+{
+ "id": "y"
+}
+EOM
+ end
+ it 'knife show --local /data_bags/x/y.json shows the local version' do
+ knife('show --local /data_bags/x/y.json').should_succeed <<EOM
+/data_bags/x/y.json:
+{
+ "foo": "bar"
+}
+EOM
+ end
+ it 'knife show /environments/x.json shows the remote version' do
+ knife('show /environments/x.json').should_succeed <<EOM
+/environments/x.json:
+{
+ "name": "x",
+ "description": "",
+ "cookbook_versions": {
+ },
+ "json_class": "Chef::Environment",
+ "chef_type": "environment",
+ "default_attributes": {
+ },
+ "override_attributes": {
+ }
+}
+EOM
+ end
+ it 'knife show --local /environments/x.json shows the local version' do
+ knife('show --local /environments/x.json').should_succeed <<EOM
+/environments/x.json:
+{
+ "foo": "bar"
+}
+EOM
+ end
+ it 'knife show /roles/x.json shows the remote version' do
+ knife('show /roles/x.json').should_succeed <<EOM
+/roles/x.json:
+{
+ "name": "x",
+ "description": "",
+ "json_class": "Chef::Role",
+ "default_attributes": {
+ },
+ "override_attributes": {
+ },
+ "chef_type": "role",
+ "run_list": [
+
+ ],
+ "env_run_lists": {
+ }
+}
+EOM
+ end
+ it 'knife show --local /roles/x.json shows the local version' do
+ knife('show --local /roles/x.json').should_succeed <<EOM
+/roles/x.json:
+{
+ "foo": "bar"
+}
+EOM
+ end
+ # show directory
+ it 'knife show /data_bags/x fails' do
+ knife('show /data_bags/x').should_fail "ERROR: /data_bags/x: is a directory\n"
+ end
+ it 'knife show --local /data_bags/x fails' do
+ knife('show --local /data_bags/x').should_fail "ERROR: /data_bags/x: is a directory\n"
+ end
+ # show nonexistent file
+ it 'knife show /environments/nonexistent.json fails' do
+ knife('show /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n"
+ end
+ it 'knife show --local /environments/nonexistent.json fails' do
+ knife('show --local /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n"
+ end
+ end
+ end
+end