Commit c5b67bc4 authored by Michał Zając's avatar Michał Zając

Improve specs

parent 6ecfb5db
......@@ -7,6 +7,7 @@ module Gitlab
module Validators
class SchemaValidator
SUPPORTED_VERSIONS = {
cluster_image_scanning: %w[14.0.4 14.0.5 14.0.6 14.1.0],
container_scanning: %w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0],
coverage_fuzzing: %w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0],
dast: %w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0],
......@@ -16,6 +17,7 @@ module Gitlab
}.freeze
DEPRECATED_VERSIONS = {
cluster_image_scanning: %w[],
container_scanning: %w[],
coverage_fuzzing: %w[],
dast: %w[],
......
......@@ -4,24 +4,56 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
describe 'SUPPORTED_VERSIONS' do
let(:schema_path) { Rails.root.join("lib", "gitlab", "ci", "parsers", "security", "validators", "schemas") }
# This is not a stub, let is not accessible within context blocks
# rubocop:disable RSpec/LeakyConstantDeclaration
SCHEMA_PATH = Rails.root.join("lib", "gitlab", "ci", "parsers", "security", "validators", "schemas")
# rubocop:enable RSpec/LeakyConstantDeclaration
described_class::SUPPORTED_VERSIONS.each_key do |report_type|
context "#{report_type}" do
it 'matches DEPRECATED_VERSIONS keys' do
expect(described_class::SUPPORTED_VERSIONS.keys).to eq(described_class::DEPRECATED_VERSIONS.keys)
end
context 'files under SCHEMA_PATH are explicitly listed' do
# We only care about the part that comes before report-format.json
# https://rubular.com/r/N8Juz7r8hYDYgD
filename_regex = /(?<report_type>[-\w]*)\-report-format.json/
versions = Dir.glob(File.join(SCHEMA_PATH, "*", File::SEPARATOR)).map { |path| path.split("/").last }
versions.each do |version|
files = Dir[SCHEMA_PATH.join(version, "*.json")]
files.each do |file|
matches = filename_regex.match(file)
report_type = matches[:report_type].tr("-", "_").to_sym
it "#{report_type} #{version}" do
expect(described_class::SUPPORTED_VERSIONS[report_type]).to include(version)
end
end
end
end
context 'every SUPPORTED_VERSION has a corresponding JSON file' do
described_class::SUPPORTED_VERSIONS.each_key do |report_type|
let(:filename) { "#{report_type.to_s.tr("_", "-")}-report-format.json" }
described_class::SUPPORTED_VERSIONS[report_type].each do |version|
context "#{version}" do
it "has a corresponding schema file present" do
full_path = schema_path.join(version, filename)
expect(File.file?(full_path)).to be true
end
it "#{report_type} #{version} schema file is present" do
full_path = SCHEMA_PATH.join(version, filename)
expect(File.file?(full_path)).to be true
end
end
end
end
end
describe 'DEPRECATED_VERSIONS' do
it 'matches SUPPORTED_VERSIONS keys' do
expect(described_class::DEPRECATED_VERSIONS.keys).to eq(described_class::SUPPORTED_VERSIONS.keys)
end
end
using RSpec::Parameterized::TableSyntax
where(:report_type, :expected_errors, :valid_data) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment