diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /spec/validators | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'spec/validators')
-rw-r--r-- | spec/validators/ip_cidr_array_validator_spec.rb | 2 | ||||
-rw-r--r-- | spec/validators/json_schema_validator_spec.rb | 25 | ||||
-rw-r--r-- | spec/validators/kubernetes_container_resources_validator_spec.rb | 42 |
3 files changed, 68 insertions, 1 deletions
diff --git a/spec/validators/ip_cidr_array_validator_spec.rb b/spec/validators/ip_cidr_array_validator_spec.rb index 4ea46d714c2..6adb0bc70db 100644 --- a/spec/validators/ip_cidr_array_validator_spec.rb +++ b/spec/validators/ip_cidr_array_validator_spec.rb @@ -17,7 +17,7 @@ RSpec.describe IpCidrArrayValidator, feature_category: :shared do using RSpec::Parameterized::TableSyntax - # noinspection RubyMismatchedArgumentType - RubyMine is resolving `#|` from Array, instead of Rspec::Parameterized + # noinspection RubyMismatchedArgumentType - https://handbook.gitlab.com/handbook/tools-and-tips/editors-and-ides/jetbrains-ides/tracked-jetbrains-issues/#ruby-32041 where(:cidr_array, :validity, :errors) do # rubocop:disable Layout/LineLength -- The RSpec table syntax often requires long lines for errors nil | false | { cidr_array: ["must be an array of CIDR values"] } diff --git a/spec/validators/json_schema_validator_spec.rb b/spec/validators/json_schema_validator_spec.rb index 01caf4ab0bd..f3a22892407 100644 --- a/spec/validators/json_schema_validator_spec.rb +++ b/spec/validators/json_schema_validator_spec.rb @@ -58,5 +58,30 @@ RSpec.describe JsonSchemaValidator do end end end + + context 'when detail_errors is true' do + let(:validator) { described_class.new(attributes: [:data], detail_errors: true, filename: "build_report_result_data") } + + context 'when data is valid' do + it 'returns no errors' do + subject + + expect(build_report_result.errors).to be_empty + end + end + + context 'when data is invalid' do + it 'returns json schema is invalid' do + build_report_result.data = { invalid: 'data' } + + subject + + expect(build_report_result.errors.size).to eq(1) + expect(build_report_result.errors.full_messages).to match_array( + ["Data '/invalid' must be a valid 'schema'"] + ) + end + end + end end end diff --git a/spec/validators/kubernetes_container_resources_validator_spec.rb b/spec/validators/kubernetes_container_resources_validator_spec.rb new file mode 100644 index 00000000000..aea561bafb9 --- /dev/null +++ b/spec/validators/kubernetes_container_resources_validator_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe KubernetesContainerResourcesValidator, feature_category: :shared do + let(:model) do + Class.new do + include ActiveModel::Model + include ActiveModel::Validations + + attr_accessor :resources + alias_method :resources_before_type_cast, :resources + + validates :resources, kubernetes_container_resources: true + end.new + end + + using RSpec::Parameterized::TableSyntax + + # noinspection RubyMismatchedArgumentType - https://handbook.gitlab.com/handbook/tools-and-tips/editors-and-ides/jetbrains-ides/tracked-jetbrains-issues/#ruby-32041 + where(:resources, :validity, :errors) do + # rubocop:disable Layout/LineLength -- The RSpec table syntax often requires long lines for errors + nil | false | { resources: ["must be a hash"] } + '' | false | { resources: ["must be a hash"] } + {} | false | { resources: ["must be a hash containing 'cpu' and 'memory' attribute of type string"] } + { cpu: nil, memory: nil } | false | { resources: ["'cpu: ' must be a string", "'memory: ' must be a string"] } + { cpu: "123di", memory: "123oi" } | false | { resources: ["'cpu: 123di' must match the regex '^(\\d+m|\\d+(\\.\\d*)?)$'", "'memory: 123oi' must match the regex '^\\d+(\\.\\d*)?([EPTGMK]|[EPTGMK]i)?$'"] } + { cpu: "123di", memory: "123oi" } | false | { resources: ["'cpu: 123di' must match the regex '^(\\d+m|\\d+(\\.\\d*)?)$'", "'memory: 123oi' must match the regex '^\\d+(\\.\\d*)?([EPTGMK]|[EPTGMK]i)?$'"] } + { cpu: "100m", memory: "123Mi" } | true | {} + # rubocop:enable Layout/LineLength + end + + with_them do + before do + model.resources = resources + model.validate + end + + it { expect(model.valid?).to eq(validity) } + it { expect(model.errors.messages).to eq(errors) } + end +end |