summaryrefslogtreecommitdiff
path: root/spec/integration
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2014-08-08 15:55:28 -0700
committerdanielsdeleo <dan@getchef.com>2014-08-10 09:40:36 -0700
commit11f7b2c725db4384787f76c4c5229f98c8694e95 (patch)
treeec99bf199d8a9fe14c90aab2e234a219b2bd447c /spec/integration
parent674cc65dc68b9d5f0eaa36f2409c6c12becf2c11 (diff)
downloadchef-11f7b2c725db4384787f76c4c5229f98c8694e95.tar.gz
Fix expected format of JSON errors in integration tests
The format was previously not stable because chef-zero (or other test code) would `require 'json'` and undo ffi-yajl's monkey patches to the JSON gem. We would probably be better off if we can get out of the business of monkeypatching JSON or attempting to provide compatibility at all, in which case this commit could be reverted.
Diffstat (limited to 'spec/integration')
-rw-r--r--spec/integration/knife/diff_spec.rb8
-rw-r--r--spec/integration/knife/download_spec.rb19
-rw-r--r--spec/integration/knife/upload_spec.rb48
3 files changed, 31 insertions, 44 deletions
diff --git a/spec/integration/knife/diff_spec.rb b/spec/integration/knife/diff_spec.rb
index 8d13d86a99..62b491d6ef 100644
--- a/spec/integration/knife/diff_spec.rb
+++ b/spec/integration/knife/diff_spec.rb
@@ -309,7 +309,9 @@ EOM
when_the_repository 'has an environment with bad JSON' do
before { file 'environments/x.json', '{' }
it 'knife diff reports an error and does a textual diff' do
- knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n")
+ error_text = "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF"
+ error_match = Regexp.new(Regexp.escape(error_text))
+ knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => error_match)
end
end
end
@@ -590,7 +592,9 @@ EOM
when_the_repository 'has an environment with bad JSON' do
before { file 'environments/x.json', '{' }
it 'knife diff reports an error and does a textual diff' do
- knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n")
+ error_text = "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF"
+ error_match = Regexp.new(Regexp.escape(error_text))
+ knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => error_match)
end
end
end
diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb
index 4788a564b7..2ef5dc03c1 100644
--- a/spec/integration/knife/download_spec.rb
+++ b/spec/integration/knife/download_spec.rb
@@ -541,7 +541,13 @@ EOM
file 'environments/x.json', '{'
end
it 'knife download succeeds' do
- knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n", :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n"
+ warning = <<-EOH
+WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF
+ {
+ (right here) ------^
+
+EOH
+ knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n", :stderr => warning
knife('diff --name-status /environments/x.json').should_succeed ''
end
end
@@ -1033,17 +1039,6 @@ EOM
environment 'x', {}
end
- when_the_repository 'has an environment with bad JSON' do
- before do
- file 'environments/x.json', '{'
- end
-
- it 'knife download succeeds' do
- knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n", :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n"
- knife('diff --name-status /environments/x.json').should_succeed ''
- end
- end
-
when_the_repository 'has the same environment with the wrong name in the file' do
before do
file 'environments/x.json', { 'name' => 'y' }
diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb
index 90666f4fc9..d8db27f73b 100644
--- a/spec/integration/knife/upload_spec.rb
+++ b/spec/integration/knife/upload_spec.rb
@@ -605,8 +605,24 @@ EOM
end
it 'knife upload tries and fails' do
- knife('upload /environments/x.json').should_fail "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\nERROR: /environments/x.json failed to write: Parse error reading JSON: A JSON text must at least contain two octets!\n"
- knife('diff --name-status /environments/x.json').should_succeed "M\t/environments/x.json\n", :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n"
+ error1 = <<-EOH
+WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF
+ {
+ (right here) ------^
+
+ERROR: /environments/x.json failed to write: Parse error reading JSON: parse error: premature EOF
+ {
+ (right here) ------^
+EOH
+
+ warn = <<-EOH
+WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF
+ {
+ (right here) ------^
+
+EOH
+ knife('upload /environments/x.json').should_fail(error1)
+ knife('diff --name-status /environments/x.json').should_succeed("M\t/environments/x.json\n", :stderr => warn)
end
end
@@ -632,15 +648,6 @@ EOM
end
when_the_chef_server 'is empty' do
- when_the_repository 'has an environment with bad JSON' do
- before do
- file 'environments/x.json', '{'
- end
- it 'knife upload tries and fails' do
- knife('upload /environments/x.json').should_fail "ERROR: /environments failed to create_child: Parse error reading JSON creating child 'x.json': A JSON text must at least contain two octets!\n"
- knife('diff --name-status /environments/x.json').should_succeed "A\t/environments/x.json\n"
- end
- end
when_the_repository 'has an environment with the wrong name in the file' do
before do
@@ -1140,16 +1147,6 @@ EOM
environment 'x', {}
end
- when_the_repository 'has an environment with bad JSON' do
- before do
- file 'environments/x.json', '{'
- end
- it 'knife upload tries and fails' do
- knife('upload /environments/x.json').should_fail "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\nERROR: /environments/x.json failed to write: Parse error reading JSON: A JSON text must at least contain two octets!\n"
- knife('diff --name-status /environments/x.json').should_succeed "M\t/environments/x.json\n", :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n"
- end
- end
-
when_the_repository 'has the same environment with the wrong name in the file' do
before do
file 'environments/x.json', { 'name' => 'y' }
@@ -1172,15 +1169,6 @@ EOM
end
when_the_chef_server 'is empty' do
- when_the_repository 'has an environment with bad JSON' do
- before do
- file 'environments/x.json', '{'
- end
- it 'knife upload tries and fails' do
- knife('upload /environments/x.json').should_fail "ERROR: /environments failed to create_child: Parse error reading JSON creating child 'x.json': A JSON text must at least contain two octets!\n"
- knife('diff --name-status /environments/x.json').should_succeed "A\t/environments/x.json\n"
- end
- end
when_the_repository 'has an environment with the wrong name in the file' do
before do