Sha256: eb645abc3ed00df815c2257d3746236f9f62a0a08ef654db1301b98c123e5a82

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require 'test_helper'

class TestContextShape < Minitest::Test
  class Email; end

  def test_field_type_number
    [
      [1, 1],
      [99999999999999999999999999999999999999999999, 1],
      [-99999999999999999999999999999999999999999999, 1],

      ['a', 2],
      ['99999999999999999999999999999999999999999999', 2],

      [1.0, 4],
      [99999999999999999999999999999999999999999999.0, 4],
      [-99999999999999999999999999999999999999999999.0, 4],

      [true, 5],
      [false, 5],

      [[], 10],
      [[1, 2, 3], 10],
      [['a', 'b', 'c'], 10],

      [Email.new, 2],
    ].each do |value, expected|
      actual = Prefab::ContextShape.field_type_number(value)

      refute_nil actual, "Expected a value for input: #{value}"
      assert_equal expected, actual, "Expected #{expected} for #{value}"
    end
  end

  # If this test fails, it means that we've added a new type to the ConfigValue
  def test_mapping_is_exhaustive
    #this removes provided for now
    unsupported = [:bytes, :limit_definition, :log_level, :weighted_values, :int_range, :provided]
    type_fields = PrefabProto::ConfigValue.descriptor.lookup_oneof("type").entries
    supported = type_fields.entries.reject do |entry|
      unsupported.include?(entry.name.to_sym)
    end.map(&:number)
    mapped = Prefab::ContextShape::MAPPING.values.uniq

    unless mapped == supported
      raise "ContextShape MAPPING needs update: #{mapped} != #{supported}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prefab-cloud-ruby-1.2.1 test/test_context_shape.rb