aboutsummaryrefslogtreecommitdiff
path: root/test/tc_mauve_configuration_builders_server.rb
blob: fc245e44c604176c0633512eb88a1ca63de236b6 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
$:.unshift "../lib/"

require 'th_mauve'
require 'mauve/configuration_builders/server'

class TcMauveConfigurationBuildersServer < Mauve::UnitTest

  def test_server_params
    hostname = "test.example.com"
    database =  "sqlite://./test.db"
    initial_sleep = 314

    config=<<EOF
server {
  hostname "#{hostname}"
  database "#{database}"
  initial_sleep #{initial_sleep}
}
EOF

    assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
    
    #
    # Check that we've got the correct things set
    #
    s = Mauve::Server.instance
    assert_equal(hostname, s.hostname)
    assert_equal(database, s.database)
    assert_equal(initial_sleep, s.initial_sleep)
  end

  def test_heartbeat_params
    destination = "test-backup.example.com"
    summary     = "Mauve blurgh!"
    detail      = "<p>A very interesting test.</p>"
    raise_after = 1000
    send_every  = 60

    config=<<EOF
server {
  heartbeat {
    destination "#{destination}"
    summary     "#{summary}"
    detail      "#{detail}"
    raise_after #{raise_after}
    send_every  #{send_every}
  }
}
EOF
    assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }

    h = Mauve::Heartbeat.instance
    assert_equal(detail, h.detail)
    assert_equal(summary, h.summary)
    assert_equal(destination, h.destination)
    assert_equal(raise_after, h.raise_after)
    assert_equal(send_every, h.send_every) 
  end

  def test_web_interface_params
    ip = "::"
    port = 12341
    document_root = "./"
    base_url = "http://www.example.com"
    session_secret = "asd2342"
    sleep_interval = 32

    config=<<EOF
server {
  web_interface {
    ip "#{ip}"
    port #{port}
    document_root "#{document_root}"
    base_url "#{base_url}"
    session_secret "#{session_secret}"
  }
}
EOF
    assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
 
    assert_equal(ip, Mauve::HTTPServer.instance.ip)
    assert_equal(port, Mauve::HTTPServer.instance.port)
    assert_equal(document_root, Mauve::HTTPServer.instance.document_root)
    assert_equal(base_url, Mauve::HTTPServer.instance.base_url)
    assert_equal(session_secret, Mauve::HTTPServer.instance.session_secret)
  end

  def test_listener_params
    ip = "::"
    port = 12341
    config=<<EOF

server {
  listener {
    ip "#{ip}"
    port #{port}
  }
}
EOF

    assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
    u = Mauve::UDPServer.instance
    assert_equal(IPAddr.new(ip), u.ip)
    assert_equal(port, u.port)
  end

  def test_notifier_params
    config=<<EOF
server {
  notifier {
  }
}
EOF

    assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
    n = Mauve::Notifier.instance
  end

  def test_processor_params
    transmission_cache_expire_time = 3120
    sleep_interval = 1235

    config=<<EOF
server {
  processor {
    transmission_cache_expire_time #{transmission_cache_expire_time}
  }
}
EOF

    assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
    pr = Mauve::Processor.instance    
    assert_equal(transmission_cache_expire_time, pr.transmission_cache_expire_time)
  end

end