diff options
author | John Keiser <jkeiser@opscode.com> | 2013-07-03 09:06:25 -0600 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2013-09-12 23:10:55 -0700 |
commit | 2ef76f824e08c54c6cf3bf60f5f01cb609770c6f (patch) | |
tree | 16a909482ad883258ae8d91d2e6f9b785b8bfb0f /spec/integration | |
parent | 2a9f3e7178379fe70303042ded5c3b52dca25f42 (diff) | |
download | chef-2ef76f824e08c54c6cf3bf60f5f01cb609770c6f.tar.gz |
Add tests for raw --pretty and --no-pretty
Diffstat (limited to 'spec/integration')
-rw-r--r-- | spec/integration/knife/raw_spec.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb index 002fd4fdc4..e5983a43cf 100644 --- a/spec/integration/knife/raw_spec.rb +++ b/spec/integration/knife/raw_spec.rb @@ -162,5 +162,68 @@ EOM EOM end end + + context 'When a server returns raw json' do + before :each do + @real_chef_server_url = Chef::Config.chef_server_url + Chef::Config.chef_server_url = "http://127.0.0.1:9018" + app = lambda do |env| + [200, {'Content-Type' => 'application/json' }, ['{ "x": "y", "a": "b" }'] ] + end + @raw_server = Puma::Server.new(app, Puma::Events.new(STDERR, STDOUT)) + @raw_server.add_tcp_listener("127.0.0.1", 9018) + @raw_server.run + end + + after :each do + Chef::Config.chef_server_url = @real_chef_server_url + @raw_server.stop(true) + end + + it 'knife raw /blah returns the prettified json' do + knife('raw /blah').should_succeed <<EOM +{ + "x": "y", + "a": "b" +} +EOM + end + + it 'knife raw --no-pretty /blah returns the raw json' do + knife('raw --no-pretty /blah').should_succeed <<EOM +{ "x": "y", "a": "b" } +EOM + end + end + + context 'When a server returns text'do + before :each do + @real_chef_server_url = Chef::Config.chef_server_url + Chef::Config.chef_server_url = "http://127.0.0.1:9018" + app = lambda do |env| + [200, {'Content-Type' => 'text' }, ['{ "x": "y", "a": "b" }'] ] + end + @raw_server = Puma::Server.new(app, Puma::Events.new(STDERR, STDOUT)) + @raw_server.add_tcp_listener("127.0.0.1", 9018) + @raw_server.run + end + + after :each do + Chef::Config.chef_server_url = @real_chef_server_url + @raw_server.stop(true) + end + + it 'knife raw /blah returns the raw text' do + knife('raw /blah').should_succeed <<EOM +{ "x": "y", "a": "b" } +EOM + end + + it 'knife raw --no-pretty /blah returns the raw text' do + knife('raw --no-pretty /blah').should_succeed <<EOM +{ "x": "y", "a": "b" } +EOM + end + end end end |