From 5d26b821d3b6842ab458146dab6df3d64392969c Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Fri, 7 Dec 2012 11:30:19 +0000 Subject: When reporting on failure-types the HTTP/HTTPS test is often reported incorrectly. Fixed this now, based on the URL and added a test case. --- lib/custodian/protocoltest/http.rb | 14 +++++++- t/test-http-vs-https.rb | 68 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100755 t/test-http-vs-https.rb diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb index 81113c0..6de74d3 100644 --- a/lib/custodian/protocoltest/http.rb +++ b/lib/custodian/protocoltest/http.rb @@ -91,7 +91,19 @@ module Custodian end - + # + # Get the right type of this object, based on the + # URL + # + def get_type + if ( @url =~ /^https:/ ) + "https" + elsif ( @url =~ /^http:/ ) + "http" + else + raise ArgumentError, "URL isn't http/https: #{@url}" + end + end # # Allow this test to be serialized. diff --git a/t/test-http-vs-https.rb b/t/test-http-vs-https.rb new file mode 100755 index 0000000..ada49d6 --- /dev/null +++ b/t/test-http-vs-https.rb @@ -0,0 +1,68 @@ +#!/usr/bin/ruby -Ilib/ -I../lib/ + + +require 'test/unit' + +require 'custodian/protocoltests' + + + +# +# Each of our test-objects implements a single test-type, except for http which implements two. +# +# It can be confusing if a test reports the wrong type though: +# +# http://example.com/ the https test failed against .. +# +# Or in reverse: +# +# https://example.com/ the http test failed ... +# +# Test we can get the sanest result here. +# +class TestTestName < Test::Unit::TestCase + + # + # Create the test suite environment: NOP. + # + def setup + end + + # + # Destroy the test suite environment: NOP. + # + def teardown + end + + + # + # Get the type of a test, and ensure it is http. + # + def test_http_type + test = nil + + assert_nothing_raised do + test = Custodian::TestFactory.create( "http://example.com/ must run http." ) + end + + assert( test ) + assert_equal( test.get_type, "http" ) + end + + + # + # Get the type of a test, and ensure it is https. + # + def test_https_type + test = nil + + assert_nothing_raised do + test = Custodian::TestFactory.create( "https://example.com/ must run https." ) + end + + assert( test ) + assert_equal( test.get_type, "https" ) + end + +end + -- cgit v1.2.1