From f7299614d6922f8b3eeacf53f6e3013e490e6faf Mon Sep 17 00:00:00 2001 From: David Elner Date: Mon, 30 Apr 2018 16:49:05 -0400 Subject: [PATCH] Removed: Configuration minitests in favor of RSpec. --- test/configurable_test.rb | 88 ---------------- test/configuration/pin_setup_test.rb | 50 --------- test/configuration/proxy_test.rb | 34 ------ test/configuration/resolver_test.rb | 22 ---- test/configuration_test.rb | 150 --------------------------- test/pin_test.rb | 90 ---------------- test/registry_test.rb | 60 ----------- 7 files changed, 494 deletions(-) delete mode 100644 test/configurable_test.rb delete mode 100644 test/configuration/pin_setup_test.rb delete mode 100644 test/configuration/proxy_test.rb delete mode 100644 test/configuration/resolver_test.rb delete mode 100644 test/configuration_test.rb delete mode 100644 test/pin_test.rb delete mode 100644 test/registry_test.rb diff --git a/test/configurable_test.rb b/test/configurable_test.rb deleted file mode 100644 index e7bb0417186..00000000000 --- a/test/configurable_test.rb +++ /dev/null @@ -1,88 +0,0 @@ -require 'ddtrace/configurable' - -module Datadog - class ConfigurableTest < Minitest::Test - def setup - @module = Module.new { include(Configurable) } - end - - def test_option_methods - assert_respond_to(@module, :set_option) - assert_respond_to(@module, :get_option) - end - - def test_option_default - @module.class_eval do - option :foo, default: :bar - end - - assert_equal(:bar, @module.get_option(:foo)) - end - - def test_setting_an_option - @module.class_eval do - option :foo, default: :bar - end - - @module.set_option(:foo, 'baz!') - assert_equal('baz!', @module.get_option(:foo)) - end - - def test_custom_setter - @module.class_eval do - option :shout, setter: ->(v) { v.upcase } - end - - @module.set_option(:shout, 'loud') - assert_equal('LOUD', @module.get_option(:shout)) - end - - def test_custom_setter_block - @module.class_eval do - option(:shout) { |value| "#{value.upcase}!" } - end - - @module.set_option(:shout, 'ouch') - assert_equal('OUCH!', @module.get_option(:shout)) - end - - def test_invalid_option - assert_raises(InvalidOptionError) do - @module.set_option(:bad_option, 'foo') - end - - assert_raises(InvalidOptionError) do - @module.get_option(:bad_option) - end - end - - def test_to_h - @module.class_eval do - option :x, default: 1 - option :y, default: 2 - end - - @module.set_option(:y, 100) - assert_equal({ x: 1, y: 100 }, @module.to_h) - end - - def test_false_options - @module.class_eval do - option :boolean, default: true - end - - @module.set_option(:boolean, false) - refute(@module.get_option(:boolean)) - end - - def test_dependency_solving - @module.class_eval do - option :foo, depends_on: [:bar] - option :bar, depends_on: [:baz] - option :baz - end - - assert_equal([:baz, :bar, :foo], @module.sorted_options) - end - end -end diff --git a/test/configuration/pin_setup_test.rb b/test/configuration/pin_setup_test.rb deleted file mode 100644 index 19a2e449b23..00000000000 --- a/test/configuration/pin_setup_test.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'ddtrace/configuration' - -module Datadog - class Configuration - class PinSetupTest < Minitest::Test - def setup - @target = Object.new - - Pin - .new('original-service', app: 'original-app') - .onto(@target) - end - - def test_setting_options - custom_tracer = get_test_tracer - - custom_options = { - service_name: 'my-service', - app: 'my-app', - app_type: :cache, - tracer: custom_tracer, - tags: { env: :prod }, - distributed_tracing: true - } - - PinSetup.new(@target, custom_options).call - - assert_equal('my-service', @target.datadog_pin.service) - assert_equal('my-app', @target.datadog_pin.app) - assert_equal({ env: :prod }, @target.datadog_pin.tags) - assert_equal({ distributed_tracing: true }, @target.datadog_pin.config) - assert_equal(custom_tracer, @target.datadog_pin.tracer) - end - - def test_missing_options_are_not_set - PinSetup.new(@target, app: 'custom-app').call - - assert_equal('custom-app', @target.datadog_pin.app) - assert_equal('original-service', @target.datadog_pin.service) - end - - def test_configure_api - Datadog.configure(@target, service_name: :foo, extra: :bar) - - assert_equal(:foo, @target.datadog_pin.service) - assert_equal({ extra: :bar }, @target.datadog_pin.config) - end - end - end -end diff --git a/test/configuration/proxy_test.rb b/test/configuration/proxy_test.rb deleted file mode 100644 index ea2903f6213..00000000000 --- a/test/configuration/proxy_test.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'ddtrace/configurable' - -module Datadog - class Configuration - class ProxyTest < Minitest::Test - def setup - @module = Module.new do - include Configurable - option :x, default: :a - option :y, default: :b - end - - @proxy = Proxy.new(@module) - end - - def test_hash_syntax - @proxy[:x] = 1 - @proxy[:y] = 2 - - assert_equal(1, @proxy[:x]) - assert_equal(2, @proxy[:y]) - end - - def test_hash_coercion - assert_equal({ x: :a, y: :b }, @proxy.to_h) - assert_equal({ x: :a, y: :b }, @proxy.to_hash) - end - - def test_merge - assert_equal({ x: :a, y: :b, z: :c }, @proxy.merge(z: :c)) - end - end - end -end diff --git a/test/configuration/resolver_test.rb b/test/configuration/resolver_test.rb deleted file mode 100644 index 2b2900edf8f..00000000000 --- a/test/configuration/resolver_test.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'ddtrace/configuration' - -module Datadog - class Configuration - class ResolverTest < Minitest::Test - def test_dependency_solving - graph = { 1 => [2], 2 => [3, 4], 3 => [], 4 => [3], 5 => [1] } - tsort = Resolver.new(graph).call - - assert_equal([3, 4, 2, 1, 5], tsort) - end - - def test_cyclic_dependecy - graph = { 1 => [2], 2 => [1] } - - assert_raises(TSort::Cyclic) do - Resolver.new(graph).call - end - end - end - end -end diff --git a/test/configuration_test.rb b/test/configuration_test.rb deleted file mode 100644 index 141e60894ea..00000000000 --- a/test/configuration_test.rb +++ /dev/null @@ -1,150 +0,0 @@ -require 'ddtrace/configuration' -require 'ddtrace/configurable' -require 'logger' - -module Datadog - class ConfigurationTest < Minitest::Test - def setup - @registry = Registry.new - @configuration = Configuration.new(registry: @registry) - end - - def test_use_method - contrib = Minitest::Mock.new - contrib.expect(:patch, true) - contrib.expect(:sorted_options, []) - - @registry.add(:example, contrib) - @configuration.use(:example) - - assert_mock(contrib) - end - - def test_module_configuration - integration = Module.new do - include Contrib::Base - option :option1 - option :option2 - end - - @registry.add(:example, integration) - - @configuration.use(:example, option1: :foo!, option2: :bar!) - - assert_equal(:foo!, @configuration[:example][:option1]) - assert_equal(:bar!, @configuration[:example][:option2]) - end - - def test_setting_a_configuration_param - integration = Module.new do - include Contrib::Base - option :option1 - end - - @registry.add(:example, integration) - @configuration[:example][:option1] = :foo - assert_equal(:foo, @configuration[:example][:option1]) - end - - def test_invalid_integration - assert_raises(Configuration::InvalidIntegrationError) do - @configuration[:foobar] - end - end - - def test_lazy_option - integration = Module.new do - include Contrib::Base - option :option1, default: -> { 1 + 1 }, lazy: true - end - - @registry.add(:example, integration) - - assert_equal(2, @configuration[:example][:option1]) - end - - def test_hash_coercion - integration = Module.new do - include Contrib::Base - option :option1, default: :foo - option :option2, default: :bar - end - - @registry.add(:example, integration) - assert_equal({ option1: :foo, option2: :bar }, @configuration[:example].to_h) - end - - def test_dependency_solving - integration = Module.new do - include Contrib::Base - option :multiply_by, depends_on: [:number] do |value| - get_option(:number) * value - end - - option :number - end - - @registry.add(:example, integration) - @configuration.use(:example, multiply_by: 5, number: 5) - assert_equal(5, @configuration[:example][:number]) - assert_equal(25, @configuration[:example][:multiply_by]) - end - - def test_default_also_passes_through_setter - array = [] - - integration = Module.new do - include Contrib::Base - option :option1 - option :option2, default: 10 do |value| - array << value - value - end - end - - @registry.add(:example, integration) - @configuration.use(:example, option1: :foo!) - - assert_equal(:foo!, @configuration[:example][:option1]) - assert_equal(10, @configuration[:example][:option2]) - assert_includes(array, 10) - end - - def test_tracer_configuration - tracer = Datadog::Tracer.new - debug_state = tracer.class.debug_logging - original_log = tracer.class.log - custom_log = Logger.new(STDOUT) - - @configuration.tracer( - enabled: false, - debug: !debug_state, - log: custom_log, - hostname: 'tracer.host.com', - port: 1234, - env: :config_test, - tags: { foo: :bar }, - instance: tracer - ) - - refute(tracer.enabled) - refute(debug_state) - assert_equal(custom_log, Datadog::Tracer.log) - assert_equal('tracer.host.com', tracer.writer.transport.hostname) - assert_equal(1234, tracer.writer.transport.port) - assert_equal(:config_test, tracer.tags[:env]) - assert_equal(:bar, tracer.tags[:foo]) - tracer.class.debug_logging = debug_state - tracer.class.log = original_log - end - - def test_configuration_acts_on_default_tracer - previous_state = Datadog.tracer.enabled - - @configuration.tracer(enabled: !previous_state) - refute_equal(previous_state, Datadog.tracer.enabled) - @configuration.tracer(enabled: previous_state) - assert_equal(previous_state, Datadog.tracer.enabled) - end - end -end diff --git a/test/pin_test.rb b/test/pin_test.rb deleted file mode 100644 index 18c74937a81..00000000000 --- a/test/pin_test.rb +++ /dev/null @@ -1,90 +0,0 @@ -require 'helper' -require 'ddtrace' -require 'ddtrace/pin' -require 'ddtrace/tracer' - -class CustomPinSetGet - def datadog_pin - @custom_attribute - end - - def datadog_pin=(pin) - @custom_attribute = 'The PIN is set!' - end -end - -class PinTest < Minitest::Test - def test_pin_onto - a = '' # using String, but really, any object should fit - - pin = Datadog::Pin.new('abc', app: 'anapp') - assert_equal('abc', pin.service) - assert_equal('anapp', pin.app) - pin.onto(a) - - got = Datadog::Pin.get_from(a) - assert_equal('abc', got.service) - assert_equal('anapp', got.app) - end - - def test_pin_get_from - a = [0, nil, self] # get_from should be callable on anything - - a.each do |x| - assert_nil(Datadog::Pin.get_from(x)) - end - end - - def test_to_s - pin = Datadog::Pin.new('abc', app: 'anapp', app_type: 'db') - assert_equal('abc', pin.service) - assert_equal('anapp', pin.app) - assert_equal('db', pin.app_type) - repr = pin.to_s - assert_equal('Pin(service:abc,app:anapp,app_type:db,name:)', repr) - end - - def test_pin_accessor - a = '' # using String, but really, any object should fit - - pin = Datadog::Pin.new('abc') - pin.onto(a) - - got = a.datadog_pin - assert_equal('abc', got.service) - end - - def test_enabled - pin = Datadog::Pin.new('abc') - assert_equal(true, pin.enabled?) - end - - def test_custom_getter_setter - # ensures that if datadog_pin is available in the class, it will - # be used instead of the default datadog_pin - obj = CustomPinSetGet.new - pin = Datadog::Pin.new('pin', app: 'app', app_type: 'db') - pin.onto(obj) - assert_equal('The PIN is set!', Datadog::Pin.get_from(obj)) - end - - def test_service_info_update - tracer = get_test_tracer - Datadog::Pin.new('test-service', app: 'test-app', app_type: 'test-type', tracer: tracer) - - assert(tracer.services.key?('test-service')) - assert_equal( - { 'app' => 'test-app', 'app_type' => 'test-type' }, - tracer.services['test-service'] - ) - end - - def test_service_info_update_with_missing_params - tracer = get_test_tracer - - # instantiating `Pin` without an `app` param (which is necessary for service info) - Datadog::Pin.new('test-service', app_type: 'test-type', tracer: tracer) - - assert(tracer.services.empty?) - end -end diff --git a/test/registry_test.rb b/test/registry_test.rb deleted file mode 100644 index 97649c9f2cd..00000000000 --- a/test/registry_test.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'minitest/autorun' -require 'ddtrace' -require 'ddtrace/registry' - -module Datadog - class RegistryTest < Minitest::Test - def test_object_retrieval - registry = Registry.new - - object1 = Object.new - object2 = Object.new - - registry.add(:object1, object1) - registry.add(:object2, object2) - - assert_same(object1, registry[:object1]) - assert_same(object2, registry[:object2]) - end - - def test_hash_coercion - registry = Registry.new - - object1 = Object.new - object2 = Object.new - - registry.add(:object1, object1, true) - registry.add(:object2, object2, false) - - assert_equal({ object1: true, object2: false }, registry.to_h) - end - - def test_enumeration - registry = Registry.new - - object1 = Object.new - object2 = Object.new - - registry.add(:object1, object1, true) - registry.add(:object2, object2, false) - - assert(registry.respond_to?(:each)) - assert_kind_of(Enumerable, registry) - - # Enumerable#map - objects = registry.map(&:klass) - assert_kind_of(Array, objects) - assert_equal(2, objects.size) - assert_includes(objects, object1) - assert_includes(objects, object2) - end - - def test_registry_entry - entry = Registry::Entry.new(:array, Array, true) - - assert_equal(:array, entry.name) - assert_equal(Array, entry.klass) - assert_equal(true, entry.auto_patch) - end - end -end