aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-05-01 13:41:01 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-05-01 13:41:01 +0100
commit0c95e0543f8e0ffc7e7b3d33799b78e03c1049d2 (patch)
tree439adb0f9126a094eec6e9d521b35b6c55513082 /test
parent69ddc82f0aef0fb31ff6b3f12ba11dcfa8d35758 (diff)
Updated sender to try and get things into UTF8 where poss.
Diffstat (limited to 'test')
-rw-r--r--test/tc_mauve_sender.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/tc_mauve_sender.rb b/test/tc_mauve_sender.rb
new file mode 100644
index 0000000..7db06c1
--- /dev/null
+++ b/test/tc_mauve_sender.rb
@@ -0,0 +1,79 @@
+$:.unshift "../lib"
+
+require 'th_mauve_resolv'
+require 'test/unit'
+require 'pp'
+require 'timecop'
+require 'mauve/sender'
+require 'locale'
+require 'iconv'
+
+
+class TcMauveSender < Test::Unit::TestCase
+ include Mauve
+
+ def setup
+ Timecop.freeze(Time.local(2011,8,1,0,0,0,0))
+ end
+
+ def teardown
+ Timecop.return
+ end
+
+ def test_sanitise
+ Locale.clear
+ Locale.current = "en_GB.ISO-8859-1"
+
+ #
+ # Set up a couple of crazy sources.
+ #
+ utf8_source = "Å ðîßtáñt plàñët"
+ iso88591_source = Iconv.conv(Locale.current.charset, "UTF-8", utf8_source)
+
+ #
+ # Make sure our two sources are distinct
+ #
+ assert(iso88591_source != utf8_source)
+
+ sender = Sender.new("test-1.example.com")
+ update = Mauve::Proto::AlertUpdate.new
+ update.source = iso88591_source
+ update.replace = false
+
+ alert = Mauve::Proto::Alert.new
+ update.alert << alert
+
+ alert_cleared = Mauve::Proto::Alert.new
+ update.alert << alert_cleared
+ alert_cleared.clear_time = Time.now.to_i
+
+ #
+ # Make sure the update has the correct source
+ #
+ assert_equal(iso88591_source, update.source)
+
+ #
+ # Sanitize
+ #
+ update = sender.sanitize(update)
+
+ #
+ # Now make sure the sanitization has changed it back to UTF-8
+ #
+ assert_equal(utf8_source, update.source)
+
+ #
+ # Now make sure the transmission time + id have been set
+ #
+ assert_equal(Time.now.to_i, update.transmission_time)
+ assert_kind_of(Integer, update.transmission_id)
+
+ #
+ # Make sure that the alert has its raise time set by default
+ #
+ assert_equal(Time.now.to_i, alert.raise_time)
+ assert_equal(0, alert_cleared.raise_time)
+ end
+
+
+end