Sha256: efa2aea5ea817d8dd3fb7bf6ccb36f65d6cd36a0cc14011a1ae78c18988d216f

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true
require 'test_helper'

class TestCLogger < Minitest::Test
  def setup
    Prefab::LoggerClient.send(:public, :get_path)
    Prefab::LoggerClient.send(:public, :level_of)
    @logger = Prefab::LoggerClient.new($stdout)
  end

  def test_get_path
    assert_equal "test_l.foo_warn",
                 @logger.get_path("/Users/jdwyah/Documents/workspace/RateLimitInc/prefab-cloud-ruby/lib/test_l.rb",
                                  "foo_warn")

    assert_equal "active_support.log_subscriber.info",
                 @logger.get_path("/Users/jdwyah/.rvm/gems/ruby-2.3.3@forcerank/gems/activesupport-4.1.16/lib/active_support/log_subscriber.rb",
                                  "info")
  end

  def test_level_of
    with_env("PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL", "info") do
      # env var overrides the default level
      assert_equal Logger::INFO,
        @logger.level_of("app.models.user"), "PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL is info"

      @logger.set_config_client(MockConfigClient.new({}))
      assert_equal Logger::WARN,
                  @logger.level_of("app.models.user"), "default is warn"

      @logger.set_config_client(MockConfigClient.new("log_level.app" => "info"))
      assert_equal Logger::INFO,
                  @logger.level_of("app.models.user")

      @logger.set_config_client(MockConfigClient.new("log_level.app" => "debug"))
      assert_equal Logger::DEBUG,
                  @logger.level_of("app.models.user")

      @logger.set_config_client(MockConfigClient.new("log_level.app" => "debug",
                                                    "log_level.app.models" => "warn"))
      assert_equal Logger::WARN,
                  @logger.level_of("app.models.user")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
prefab-cloud-ruby-0.14.0 test/test_logger.rb
prefab-cloud-ruby-0.13.3 test/test_logger.rb
prefab-cloud-ruby-0.13.2 test/test_logger.rb
prefab-cloud-ruby-0.13.0 test/test_logger.rb