Sha256: 5e54780179c0cdafbc0501e95565e0a706c39a3bdfe21dca653bc82a567ec59d

Contents?: true

Size: 1.82 KB

Versions: 86

Compression:

Stored size: 1.82 KB

Contents

require_relative 'helper'
require 'fluent/test'
require 'fluent/oj_options'

class OjOptionsTest < ::Test::Unit::TestCase
  begin
    require 'oj'
    @@oj_is_avaibale = true
  rescue LoadError
    @@oj_is_avaibale = false
  end

  setup do
    @orig_env = {}
    ENV.each do |key, value|
      @orig_env[key] = value if key.start_with?("FLUENT_OJ_OPTION_")
    end
  end

  teardown do
    ENV.delete_if { |key| key.start_with?("FLUENT_OJ_OPTION_") }
    @orig_env.each { |key, value| ENV[key] = value }
  end

  test "available?" do
    assert_equal(@@oj_is_avaibale, Fluent::OjOptions.available?)
  end

  sub_test_case "set by environment variable" do
    test "when no env vars set, returns default options" do
      ENV.delete_if { |key| key.start_with?("FLUENT_OJ_OPTION_") }
      defaults = Fluent::OjOptions::DEFAULTS
      assert_equal(defaults, Fluent::OjOptions.load_env)
      assert_equal(defaults, Oj.default_options.slice(*defaults.keys)) if @@oj_is_avaibale
    end

    test "valid env var passed with valid value, default is overridden" do
      ENV["FLUENT_OJ_OPTION_BIGDECIMAL_LOAD"] = ":bigdecimal"
      assert_equal(:bigdecimal, Fluent::OjOptions.load_env[:bigdecimal_load])
      assert_equal(:bigdecimal, Oj.default_options[:bigdecimal_load]) if @@oj_is_avaibale
    end

    test "valid env var passed with invalid value, default is not overriden" do
      ENV["FLUENT_OJ_OPTION_BIGDECIMAL_LOAD"] = ":conor"
      assert_equal(:float, Fluent::OjOptions.load_env[:bigdecimal_load])
      assert_equal(:float, Oj.default_options[:bigdecimal_load]) if @@oj_is_avaibale
    end

    test "invalid env var passed, nothing done with it" do
      ENV["FLUENT_OJ_OPTION_CONOR"] = ":conor"
      assert_equal(nil, Fluent::OjOptions.load_env[:conor])
      assert_equal(nil, Oj.default_options[:conor]) if @@oj_is_avaibale
    end
  end
end

Version data entries

86 entries across 86 versions & 7 rubygems

Version Path
fluentd-1.14.5-x86-mingw32 test/test_oj_options.rb
fluentd-1.14.5-x64-mingw32 test/test_oj_options.rb
fluentd-1.14.5 test/test_oj_options.rb
fluentd-1.14.4-x64-mingw-ucrt test/test_oj_options.rb
fluentd-1.14.4-x64-mingw32 test/test_oj_options.rb
fluentd-1.14.4-x86-mingw32 test/test_oj_options.rb
fluentd-1.14.4 test/test_oj_options.rb
fluentd-1.14.3-x86-mingw32 test/test_oj_options.rb
fluentd-1.14.3-x64-mingw32 test/test_oj_options.rb
fluentd-1.14.3 test/test_oj_options.rb
fluentd-1.14.2-x86-mingw32 test/test_oj_options.rb
fluentd-1.14.2-x64-mingw32 test/test_oj_options.rb
fluentd-1.14.2 test/test_oj_options.rb
fluentd-1.14.1-x86-mingw32 test/test_oj_options.rb
fluentd-1.14.1-x64-mingw32 test/test_oj_options.rb
fluentd-1.14.1 test/test_oj_options.rb
fluentd-1.14.0-x86-mingw32 test/test_oj_options.rb
fluentd-1.14.0-x64-mingw32 test/test_oj_options.rb
fluentd-1.14.0 test/test_oj_options.rb
fluentd-1.14.0.rc test/test_oj_options.rb