Commit 56a3a36
Changed files (5)
lib/scim/kit/cli/app.rb
@@ -93,7 +93,7 @@ module Scim
entry = resource_type_entry(resource_type)
errors = validation.errors_for(entry, result.body, &transform)
- return reporter.report(result) unless errors
+ return reporter.report_unvalidated(result) unless errors
reporter.report_validation(result, errors)
end
lib/scim/kit/cli/reporter.rb
@@ -22,6 +22,13 @@ module Scim
failure(validation_errors: errors)
end
+ # --validate was asked for and could not be carried out, so the
+ # response is reported but the command still fails.
+ def report_unvalidated(result)
+ shell.say(pretty(result.body))
+ FAILURE
+ end
+
def success(body)
shell.say(pretty(body))
SUCCESS
spec/scim/kit/cli/app_spec.rb
@@ -440,7 +440,7 @@ RSpec.describe Scim::Kit::Cli::App do
.to_return(status: 200, body: { totalResults: 0 }.to_json)
end
- it 'warns and exits 0' do
+ it 'warns that it could not validate' do
allow($stdout).to receive(:print)
instance = app('validate' => true)
@@ -448,12 +448,12 @@ RSpec.describe Scim::Kit::Cli::App do
.to output(/no schema found/).to_stderr
end
- it 'exits 0' do
+ it 'exits 1 rather than reporting an unvalidated success' do
allow($stdout).to receive(:print)
allow($stderr).to receive(:print)
instance = app('validate' => true)
- expect(exit_status { instance.list('User') }).to eq(0)
+ expect(exit_status { instance.list('User') }).to eq(1)
end
end
end
spec/scim/kit/cli/reporter_spec.rb
@@ -103,6 +103,21 @@ RSpec.describe Scim::Kit::Cli::Reporter do
end
end
+ describe '#report_unvalidated' do
+ let(:result) { Scim::Kit::Http::Result.new(200, body) }
+
+ it 'prints the body to stdout' do
+ expect { subject.report_unvalidated(result) }
+ .to output("#{pretty}\n").to_stdout
+ end
+
+ it 'returns a failure status' do
+ allow($stdout).to receive(:print)
+
+ expect(subject.report_unvalidated(result)).to eq(1)
+ end
+ end
+
describe '#warn' do
it 'prefixes the message and writes it to stderr' do
expect { subject.warn('watch out') }
README.md
@@ -103,8 +103,10 @@ scim-kit list User --header "Authorization: Bearer $TOKEN"
### Validating a server
`--validate` checks responses against JSON Schema and exits non-zero when a
-response does not conform. The body is always printed to stdout; validation
-errors go to stderr.
+response does not conform, or when the validation could not be carried out at
+all -- for example when the server's `/Schemas` document is unreachable, so a
+CI job gating on the exit code never passes on an unvalidated response. The
+body is always printed to stdout; validation errors go to stderr.
```bash
scim-kit discover --validate