Repository: puma/puma
File: test/test_config.rb (Ruby)

Code before:

    env = { "MAX_THREADS" => "7" }
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal 7, conf.options.default_options[:max_threads]

    env = { "PUMA_MAX_THREADS" => "8" }
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal 8, conf.options.default_options[:max_threads]

    env = { "PUMA_MAX_THREADS" => "" }
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal default_max_threads, conf.options.default_options[:max_threads]
  end

  def test_config_loads_workers_from_env
    env = { "WEB_CONCURRENCY" => "9" }
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal 9, conf.options.default_options[:workers]
  end

  def test_config_ignores_blank_workers_from_env
    env = { "WEB_CONCURRENCY" => "" }
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal 0, conf.options.default_options[:workers]
  end

  def test_config_does_not_preload_app_if_not_using_workers
    env = { "WEB_CONCURRENCY" => "0" }
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal false, conf.options.default_options[:preload_app]
  end

  def test_config_preloads_app_if_using_workers
    env = { "WEB_CONCURRENCY" => "2" }
    preload = Puma.forkable?
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal preload, conf.options.default_options[:preload_app]
  end
end

class TestConfigFileWithFakeEnv < PumaTest
  def setup
    FileUtils.mkpath("config/puma")
    File.write("config/puma/fake-env.rb", "")

Review comment (suggestion):
I don't think `nil` needs to be tested, `ENV` values are always strings

```suggestion
    ['', ' ', " \n ", " \t "].each do |wc|
```

Code after:

    env = { "MAX_THREADS" => "7" }
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal 7, conf.options.default_options[:max_threads]

    env = { "PUMA_MAX_THREADS" => "8" }
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal 8, conf.options.default_options[:max_threads]

    env = { "PUMA_MAX_THREADS" => "" }
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal default_max_threads, conf.options.default_options[:max_threads]
  end

  def test_config_loads_workers_from_env
    env = { "WEB_CONCURRENCY" => "9" }
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal 9, conf.options.default_options[:workers]
  end

  def test_config_ignores_blank_workers_from_env
    [nil, '', ' ', " \n ", " \t "].each do |wc|
      env = { "WEB_CONCURRENCY" => wc }
      conf = Puma::Configuration.new({}, {}, env)
      conf.clamp
      assert_equal 0, conf.options.default_options[:workers]
    end
  end

  def test_config_does_not_preload_app_if_not_using_workers
    env = { "WEB_CONCURRENCY" => "0" }
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal false, conf.options.default_options[:preload_app]
  end

  def test_config_preloads_app_if_using_workers
    env = { "WEB_CONCURRENCY" => "2" }
    preload = Puma.forkable?
    conf = Puma::Configuration.new({}, {}, env)
    conf.clamp
    assert_equal preload, conf.options.default_options[:preload_app]
  end
end

class TestConfigFileWithFakeEnv < PumaTest
  def setup