aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-07-05 13:48:57 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-07-05 13:48:57 +0100
commitf1ddcb07a58413a87d3643c8a23e9374e6197a1a (patch)
treee6c0c856e5596ff9fbd3c5880845ccd2ff7ed25b /test
parenteeddc7a436fad01a569553465984ef97b3efbc84 (diff)
Tidied tests to work with the last change.
Diffstat (limited to 'test')
-rw-r--r--test/tc_mauve_calendar_interface.rb77
-rw-r--r--test/tc_mauve_source_list.rb40
2 files changed, 33 insertions, 84 deletions
diff --git a/test/tc_mauve_calendar_interface.rb b/test/tc_mauve_calendar_interface.rb
index ddf4039..f805b57 100644
--- a/test/tc_mauve_calendar_interface.rb
+++ b/test/tc_mauve_calendar_interface.rb
@@ -70,83 +70,6 @@ EOF
assert(!CalendarInterface.is_user_off_sick?("test3"))
end
- def test_do_get
- url = "http://localhost/"
-
- #
- # This sets up two redirects, followed by the answer (below)
- #
- 2.times do |x|
- next_url = url + "#{x}/"
- stub_request(:get, url).
- to_return(:status => 301, :body => nil, :headers => {:location => next_url})
- url = next_url
- end
-
- #
- # And finally the answer.
- #
- stub_request(:get, url).
- to_return(:status => 200, :body => "OK!", :headers => {})
-
- #
- # Now do_get should return "OK!" when the maximum number of redirects is set to two.
- #
- result = nil
- assert_nothing_raised{ result = CalendarInterface.__send__(:do_get, "http://localhost/", 2) }
- assert_equal("OK!",result)
-
- #
- # do_get should return nil when the maximum number of redirects is set to two.
- #
- assert_nothing_raised{ result = CalendarInterface.__send__(:do_get, "http://localhost/", 1) }
- assert_nil(result)
-
- #
- # Pop the warning about the redirect off the end of the log.
- #
- logger_pop
- end
-
- def test_do_get_with_cache
- url = "http://localhost/"
-
- #
- # This stubs the request to give out the time
- #
- stub_request(:get, url).
- to_return( lambda{ {:status => 200, :body => YAML.dump(Time.now), :headers => {}} } )
-
- #
- # This reponse should not be cached, the cache-until paramter is "now"
- #
- assert_equal(Time.now, CalendarInterface.__send__(:do_get_with_cache, url, Time.now))
-
- #
- # Since the last request wasn't cached, the next one should give back
- # "now", and should be cached for the next 10 seconds.
- #
- Timecop.freeze(Time.now + 5)
- assert_equal(Time.now, CalendarInterface.__send__(:do_get_with_cache, url, Time.now + 10))
-
- #
- # This should have been cached from the last query.
- #
- Timecop.freeze(Time.now + 5)
- assert_equal(Time.now - 5, CalendarInterface.__send__(:do_get_with_cache, url, Time.now + 10))
-
- #
- # Finally, this should now have expired from the cache.
- #
- Timecop.freeze(Time.now + 5)
- assert_equal(Time.now, CalendarInterface.__send__(:do_get_with_cache, url, Time.now + 10))
-
- Timecop.freeze(Time.now + 50)
- cache = CalendarInterface.__send__(:clean_cache)
- assert(cache.empty?)
- end
-
-
end
diff --git a/test/tc_mauve_source_list.rb b/test/tc_mauve_source_list.rb
index bc68094..5b1aa70 100644
--- a/test/tc_mauve_source_list.rb
+++ b/test/tc_mauve_source_list.rb
@@ -3,12 +3,29 @@ $:.unshift "../lib/"
require 'th_mauve'
require 'mauve/source_list'
require 'th_mauve_resolv'
+require 'webmock'
require 'pp'
class TcMauveSourceList < Mauve::UnitTest
+ include Mauve
+ include WebMock::API
+
+ def setup
+ super
+ setup_database
+ WebMock.disable_net_connect!
+ end
+
+ def teardown
+ WebMock.reset!
+ WebMock.allow_net_connect!
+ teardown_database
+ super
+ end
+
def test_hostname_match
- sl = Mauve::SourceList.new("test")
+ sl = SourceList.new("test")
assert_equal("test", sl.label)
list = %w(a.example.com b.example.com c.example.com)
@@ -21,7 +38,7 @@ class TcMauveSourceList < Mauve::UnitTest
end
def test_regex_match
- sl = Mauve::SourceList.new("test")
+ sl = SourceList.new("test")
assert_nothing_raised{ sl += %w([a-c].example.com *.[d-f].example.com g.example.com) }
@@ -35,7 +52,7 @@ class TcMauveSourceList < Mauve::UnitTest
end
def test_ip_match
- sl = Mauve::SourceList.new("test")
+ sl = SourceList.new("test")
assert_nothing_raised{ sl += %w(test-1.example.com 1.2.3.5 2001:1:2:3::5 1.2.4.0/24 2001:1:2:4::/64) }
@@ -50,7 +67,7 @@ class TcMauveSourceList < Mauve::UnitTest
end
def test_uri_match
- sl = Mauve::SourceList.new("test")
+ sl = SourceList.new("test")
assert_nothing_raised { sl += "test-1.example.com" }
@@ -64,15 +81,24 @@ class TcMauveSourceList < Mauve::UnitTest
end
def test_ip_crossmatch
- sl = Mauve::SourceList.new("test")
+ sl = SourceList.new("test")
assert_nothing_raised { sl += "test-1.example.com" }
assert( sl.includes?("www.example.com"), "www.example.com not found in #{sl.list}" )
- sl = Mauve::SourceList.new("test")
+ sl = SourceList.new("test")
assert_nothing_raised { sl += "2001::/3" }
assert( sl.includes?("www2.example.com"), "www2.example.com not found in #{sl.list}" )
end
-end
+ def test_remote_source_list
+ stub_request(:get, "http://localhost/network/monitor_ip/by_tag/Managed").
+ to_return(:status => 200, :body => %w(1.2.3.4 1.2.3.5).join("\n"))
+
+ sl = SourceList.new("test","http://localhost/network/monitor_ip/by_tag/Managed")
+ assert( sl.includes?("1.2.3.4"), "1.2.3.4 not found in #{sl.list}" )
+ assert( sl.includes?("test-1.example.com"), "test-1.example.com not found in #{sl.list}" )
+ end
+
+end