Skip to content

Commit

Permalink
Allow newer versions of json-schema then 2.2.5
Browse files Browse the repository at this point in the history
While the performance issue is still not completely fixed
voxpupuli/json-schema#261
newer Ruby versions show warnings with the old json-schema versions so
we need to support the newer ones.

Newer json-schema versions have a littel different error messages that's
why the tests needed to be adapted accordingly.
  • Loading branch information
thardeck committed Jun 25, 2019
1 parent 5793952 commit 538fd43
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Machinery Release Notes

* Allow newer json-schema releases then 2.2.5. Newer versions slow down parsing
of manifests but newer Ruby versions have issues with old json schema releases.
The performance issue is known upstream: (gh#ruby-json-schema/json-schema#261)
* Fix machinery helper go version parsing (bsc#1125785)
* Allow inspection of old 32-bit systems even when their architecture is
reported as i586 or i386
Expand Down
2 changes: 1 addition & 1 deletion machinery.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Gem::Specification.new do |s|
s.add_dependency "abstract_method", "~>1.2"
s.add_dependency "builder", "~>3.2"
s.add_dependency "gli", "~>2.11"
s.add_dependency "json-schema", "~> 2.2.4"
s.add_dependency "json-schema", "~> 2.2"
s.add_dependency "haml", ">= 4.0"
s.add_dependency "kramdown", "~> 1.3"
s.add_dependency "tilt", "~> 2.0"
Expand Down
20 changes: 10 additions & 10 deletions spec/unit/json_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

it "raises an error when encountering invalid enum values" do
expected = <<EOF
In scope changed_config_files: The property #0 (files/changes) of type Hash did not match any of the required schemas.
In scope changed_config_files: The property #0 \\(files.*\\) of type .* did not match any of the required schemas
EOF

errors = Machinery::JsonValidator.new(JSON.parse(<<-EOT)).validate
Expand Down Expand Up @@ -110,7 +110,7 @@
}
EOT

expect(errors.first).to eq(expected.chomp)
expect(errors.first).to match(/#{expected.chomp}/)
end

it "does not raise an error when a changed-managed-file is 'replaced'" do
Expand Down Expand Up @@ -158,35 +158,35 @@

it "raises in case of an unknown status" do
expected = <<EOF
In scope changed_config_files: The property #0 (_elements/status) of type Hash did not match any of the required schemas.
In scope changed_config_files: The property #0 \\(_elements.*\\) of type .* did not match any of the required schemas
EOF
expected.chomp!
errors = Machinery::JsonValidator.new(
JSON.parse(File.read("#{path}unknown_status.json"))
).validate
expect(errors.first).to eq(expected)
expect(errors.first).to match(/#{expected}/)
end

it "raises in case of a pattern mismatch" do
expected = <<EOF
In scope changed_config_files: The property #0 (_elements/mode/changes) of type Hash did not match any of the required schemas.
In scope changed_config_files: The property #0 \\(_elements.*\\) of type .* did not match any of the required schemas
EOF
expected.chomp!
errors = Machinery::JsonValidator.new(
JSON.parse(File.read("#{path}pattern_mismatch.json"))
).validate
expect(errors.first).to eq(expected)
expect(errors.first).to match(/#{expected}/)
end

it "raises for a deleted file in case of an empty changes array" do
expected = <<EOF
In scope changed_config_files: The property #0 (_elements/changes) of type Hash did not match any of the required schemas.
In scope changed_config_files: The property #0 \\(_elements.*\\) of type .* did not match any of the required schemas
EOF
expected.chomp!
errors = Machinery::JsonValidator.new(
JSON.parse(File.read("#{path}deleted_without_changes.json"))
).validate
expect(errors.first).to eq(expected)
expect(errors.first).to match(/#{expected}/)
end
end

Expand All @@ -195,13 +195,13 @@

it "raises for extracted in case of unknown type" do
expected = <<EOF
In scope unmanaged_files: The property #0 (_elements) of type Hash did not match one or more of the required schemas.
In scope unmanaged_files: The property #0 \\(_elements\\) of type .* did not match one or more of the required schemas
EOF
expected.chomp!
errors = Machinery::JsonValidator.new(
JSON.parse(File.read("#{path}extracted_unknown_type.json"))
).validate
expect(errors.first).to include(expected)
expect(errors.first).to match(/#{expected}/)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@
manifest.validate
expected_output = <<-EOF.chomp
Warning: System Description validation errors:
The property '#/meta/os' of type String did not match the following type:
The property '#/meta/os' of type [Ss]tring did not match the following type:
EOF
expect(captured_machinery_output).to include(expected_output)
expect(captured_machinery_output).to match(/#{expected_output}/)
end

it "doesn't validate incompatible descriptions" do
Expand Down
5 changes: 2 additions & 3 deletions spec/unit/validate_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@

it "raises an error when encountering faulty description" do
expected = <<EOF
In scope packages: The property #0 (_elements/checksum/_attributes/package_system) of type Hash did not match any of the required schemas.
In scope packages: The property.* of type .* did not match any of the required schemas
EOF
expected.chomp!
expect {
validate_task.validate(store, "faulty_description")
}.to raise_error(Machinery::Errors::SystemDescriptionValidationFailed, expected)
}.to raise_error(Machinery::Errors::SystemDescriptionValidationFailed, /#{expected}/)
end

it "prints a message in case of successful validation" do
Expand Down

0 comments on commit 538fd43

Please sign in to comment.