Sha256: fc4215489d8bea9818ded5997499feb4885afac3cea08c408caa8ba5163e19f7

Contents?: true

Size: 1.43 KB

Versions: 17

Compression:

Stored size: 1.43 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
    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

17 entries across 17 versions & 1 rubygems

Version Path
prefab-cloud-ruby-1.6.2 test/test_context_shape.rb
prefab-cloud-ruby-1.6.1 test/test_context_shape.rb
prefab-cloud-ruby-1.6.0 test/test_context_shape.rb
prefab-cloud-ruby-1.5.1 test/test_context_shape.rb
prefab-cloud-ruby-1.6.0.pre2 test/test_context_shape.rb
prefab-cloud-ruby-1.6.0.pre1 test/test_context_shape.rb
prefab-cloud-ruby-0 test/test_context_shape.rb
prefab-cloud-ruby-1.5.0 test/test_context_shape.rb
prefab-cloud-ruby-1.4.5 test/test_context_shape.rb
prefab-cloud-ruby-1.4.4 test/test_context_shape.rb
prefab-cloud-ruby-1.4.3 test/test_context_shape.rb
prefab-cloud-ruby-1.4.2 test/test_context_shape.rb
prefab-cloud-ruby-1.4.1 test/test_context_shape.rb
prefab-cloud-ruby-1.4.0 test/test_context_shape.rb
prefab-cloud-ruby-1.3.2 test/test_context_shape.rb
prefab-cloud-ruby-1.3.1 test/test_context_shape.rb
prefab-cloud-ruby-1.3.0 test/test_context_shape.rb