/usr/lib/ruby/vendor_ruby/fog/test_helpers/formats_helper.rb is in ruby-fog-core 1.45.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | require "fog/schema/data_validator"
module Shindo
class Tests
# Generates a Shindo test that compares a hash schema to the result
# of the passed in block returning true if they match.
#
# The schema that is passed in is a Hash or Array of hashes that
# have Classes in place of values. When checking the schema the
# value should match the Class.
#
# Strict mode will fail if the data has additional keys. Setting
# +strict+ to +false+ will allow additional keys to appear.
#
# @param [Hash] schema A Hash schema
# @param [Hash] options Options to change validation rules
# @option options [Boolean] :allow_extra_keys
# If +true+ does not fail when keys are in the data that are
# not specified in the schema. This allows new values to
# appear in API output without breaking the check.
# @option options [Boolean] :allow_optional_rules
# If +true+ does not fail if extra keys are in the schema
# that do not match the data. Not recommended!
# @yield Data to check with schema
#
# @example Using in a test
# Shindo.tests("comparing welcome data against schema") do
# data = {:welcome => "Hello" }
# data_matches_schema(:welcome => String) { data }
# end
#
# comparing welcome data against schema
# + data matches schema
#
# @example Example schema
# {
# "id" => String,
# "ram" => Integer,
# "disks" => [
# {
# "size" => Float
# }
# ],
# "dns_name" => Fog::Nullable::String,
# "active" => Fog::Boolean,
# "created" => DateTime
# }
#
# @return [Boolean]
def data_matches_schema(schema, options = {})
test("data matches schema") do
validator = Fog::Schema::DataValidator.new
valid = validator.validate(yield, schema, options)
@message = validator.message unless valid
valid
end
end
# @deprecated #formats is deprecated. Use #data_matches_schema instead
def formats(format, strict = true)
test("has proper format") do
if strict
options = { :allow_extra_keys => false, :allow_optional_rules => true }
else
options = { :allow_extra_keys => true, :allow_optional_rules => true }
end
validator = Fog::Schema::DataValidator.new
valid = validator.validate(yield, format, options)
@message = validator.message unless valid
valid
end
end
end
end
|