From 4c57c9605a316fc84af180891b3d6b797cbfea3a Mon Sep 17 00:00:00 2001
From: Steve Kemp <steve@steve.org.uk>
Date: Wed, 14 Nov 2012 20:09:00 +0000
Subject:   Added test of inside vs. outside of Bytemark network

---
 t/test-alerter.rb | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100755 t/test-alerter.rb

(limited to 't')

diff --git a/t/test-alerter.rb b/t/test-alerter.rb
new file mode 100755
index 0000000..80ce44e
--- /dev/null
+++ b/t/test-alerter.rb
@@ -0,0 +1,97 @@
+#!/usr/bin/ruby1.8 -I./lib/ -I../lib/
+
+
+
+require 'test/unit'
+require 'custodian/alerter'
+
+
+
+#
+# Unit test for our alerting class
+#
+# This doesn't actually test the alerts, but it will
+# test that we can successfully determine whether a
+# destination is inside or outside the Bytemark network.
+#
+#
+class TestAlerter < Test::Unit::TestCase
+
+  #
+  # Create the test suite environment: NOP.
+  #
+  def setup
+  end
+
+  #
+  # Destroy the test suite environment: NOP.
+  #
+  def teardown
+  end
+
+
+  #
+  # Ensure we can instantiate the object
+  #
+  def test_init
+
+    assert_nothing_raised do
+      obj = Alerter.new( {} )
+      assert( obj )
+    end
+
+  end
+
+
+  #
+  #  Test location-detection.
+  #
+  def test_families
+
+    #
+    #  Hash of hostnames and version of address.
+    #
+    to_test = {
+
+      #
+      # Hosts inside the Bytemark network
+      #
+      "www.steve.org.uk"               => true,
+      "ipv6.steve.org.uk"              => true,
+      "http://www.steve.org.uk/"       => true,
+      "http://ipv6.steve.org.uk"       => true,
+      "canalrivertrust.org.uk"         => true,
+      "http://canalrivertrust.org.uk/" => true,
+      "http://canalrivertrust.org.uk"  => true,
+
+      #
+      # Hosts outside the Bytemark network
+      #
+      "https://google.com/"     => false,
+      "http://google.com/"      => false,
+      "http://ipv6.google.com/" => false,
+      "http://192.168.0.333/"   => false,
+    }
+
+
+
+    to_test.each do |name,inside|
+
+      obj = Alerter.new( nil )
+
+      text = obj.expand_inside_bytemark( name )
+
+      if ( text =~ /is inside/ )
+        assert( inside == true )
+      end
+      if ( text =~ /is not/ )
+        assert( inside == false )
+      end
+    end
+  end
+
+
+
+
+
+end
-- 
cgit v1.2.3