From ac9634d8f8c6bbaa8348929f42d53d2b375f6dfb Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 15 Jan 2020 14:41:14 -0700 Subject: Add a json schema for dependency --- spec/fixtures/schema/v2.0.json | 16 ++++++++++++++++ spec/fixtures/schema/v2.0_dependency.json | 27 +++++++++++++++++++++++++++ spec/fixtures/v2.0_schema.json | 16 ---------------- spec/integration/python/pipenv_spec.rb | 1 + spec/integration/ruby/bundler_spec.rb | 2 ++ spec/support/matchers.rb | 9 +++++---- 6 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 spec/fixtures/schema/v2.0.json create mode 100644 spec/fixtures/schema/v2.0_dependency.json delete mode 100644 spec/fixtures/v2.0_schema.json (limited to 'spec') diff --git a/spec/fixtures/schema/v2.0.json b/spec/fixtures/schema/v2.0.json new file mode 100644 index 0000000..3377a9d --- /dev/null +++ b/spec/fixtures/schema/v2.0.json @@ -0,0 +1,16 @@ +{ + "$id": "https://gitlab.com/gitlab-org/security-products/license-management/blob/master/spec/fixtures/schema/v2.0.json", + "type": "object", + "required": [ + "version", + "licenses", + "dependencies" + ], + "properties": { + "version": { "type": "string" }, + "licenses": { "type": "array" }, + "dependencies": { "$ref": "v2.0_dependency.json" } + }, + "additionalProperties": false +} + diff --git a/spec/fixtures/schema/v2.0_dependency.json b/spec/fixtures/schema/v2.0_dependency.json new file mode 100644 index 0000000..fcd96d7 --- /dev/null +++ b/spec/fixtures/schema/v2.0_dependency.json @@ -0,0 +1,27 @@ +{ + "type": "array", + "required": [ + "name", + "url", + "description", + "paths", + "licenses" + ], + "properties": { + "name": { "type": "string" }, + "url": { "type": "uri" }, + "description": { "type": "string" }, + "paths": { + "type": "array", + "items": { + "type": "string" + } + }, + "licenses": { + "type": "array", + "items": { + "type": "string" + } + } + } +} diff --git a/spec/fixtures/v2.0_schema.json b/spec/fixtures/v2.0_schema.json deleted file mode 100644 index bd304ce..0000000 --- a/spec/fixtures/v2.0_schema.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "$id": "https://gitlab.com/gitlab-org/security-products/license-management/blob/master/spec/fixtures/v2.0_schema.json", - "type": "object", - "required": [ - "version", - "licenses", - "dependencies" - ], - "properties": { - "version": { "type": "string" }, - "licenses": { "type": "array" }, - "dependencies": { "type": "array" } - }, - "additionalProperties": false -} - diff --git a/spec/integration/python/pipenv_spec.rb b/spec/integration/python/pipenv_spec.rb index 6039b25..2756f6b 100644 --- a/spec/integration/python/pipenv_spec.rb +++ b/spec/integration/python/pipenv_spec.rb @@ -23,6 +23,7 @@ RSpec.describe "pipenv" do report = runner.scan expect(report).not_to be_empty + expect(report).to match_schema(version: '2.0') expect(report[:version]).not_to be_empty expect(report[:licenses]).not_to be_empty expect(report[:dependencies].map { |x| x[:name] }).to include("six") diff --git a/spec/integration/ruby/bundler_spec.rb b/spec/integration/ruby/bundler_spec.rb index 179da2a..2cb8f7d 100644 --- a/spec/integration/ruby/bundler_spec.rb +++ b/spec/integration/ruby/bundler_spec.rb @@ -14,6 +14,7 @@ gem 'saml-kit' report = runner.scan expect(report).not_to be_empty + expect(report).to match_schema(version: '2.0') expect(report[:licenses]).not_to be_empty expect(report[:dependencies].map { |x| x[:name] }).to include("saml-kit") end @@ -81,6 +82,7 @@ BUNDLED WITH report = runner.scan expect(report).not_to be_empty + expect(report).to match_schema(version: '2.0') expect(report[:licenses]).not_to be_empty expect(report[:dependencies].map { |x| x[:name] }).to include("saml-kit") end diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index bb54d19..1d1c263 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -1,8 +1,9 @@ -RSpec::Matchers.define :match_schema do |version: nil, **options| +RSpec::Matchers.define :match_schema do |version: '2.0'| match do |actual| - path = License::Management.root.join("spec/fixtures/v#{version}_schema.json") - schema = JSON.parse(IO.read(path)) - @errors = JSON::Validator.fully_validate(schema, actual, options) + schema = License::Management.root + .join("spec/fixtures/schema/v#{version}.json") + .to_s + @errors = JSON::Validator.fully_validate(schema, actual) @errors.empty? end -- cgit v1.2.3