File: testyaml.rb

package info (click to toggle)
ruby-log4r 1.1.10-4.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 648 kB
  • sloc: ruby: 2,744; xml: 96; makefile: 5
file content (39 lines) | stat: -rw-r--r-- 1,077 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'test_helper'

# Define a custom outputter that allows arrays in configuration hash
module Log4r
  class TestYamlOutputter < Outputter
    # expose array parameter
    attr_reader :array_param

    def initialize(name, hash = {})
      @array_param = hash['array_param']
    end
  end
end


class TestYaml < TestCase
  include Log4r

  def setup
    @cfg = YamlConfigurator # shorthand
    @cfg['CUSTOM_DOMAIN'] = 'bar.com'
  end

  def test_injection
    assert_nothing_raised("Exception injected") do
      @cfg.load_yaml_file(File.join(File.dirname(__FILE__),'testyaml_injection.yaml'))
    end
  end

  def test_arrays
    assert_nothing_raised("Parser couldn't handle arrays in YAML") do
      @cfg.load_yaml_file(File.join(File.dirname(__FILE__),'testyaml_arrays.yaml'))
    end
    log = Logger['mylogger']
    assert_instance_of(Array, log.outputters.first.array_param, 'Array not loaded properly from YAML')
    assert_equal('wilma@bar.com', log.outputters.first.array_param[2], '#{}-style parameter interpolation doesn\'t work properly in arrays')
  end
end