Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup Whois::Server::Adapters::Verisign test

  • Loading branch information...
commit 545621db392c5d8925b150e9fa9ae0b4ecfea058 1 parent add26ee
@weppos authored
Showing with 37 additions and 30 deletions.
  1. +7 −1 test/test_helper.rb
  2. +30 −29 test/whois/server/adapters/verisign_test.rb
View
8 test/test_helper.rb
@@ -3,9 +3,10 @@
require 'rubygems'
require 'mocha'
-
class Test::Unit::TestCase
+ TEST_ROOT = File.expand_path("../", __FILE__)
+
def self.need_connectivity(&block)
if connectivity_available?
yield
@@ -25,6 +26,11 @@ def with_definitions(&block)
Whois::Server.send :class_variable_set, :@@definitions, @_definitions
end
+
+ def fixture(*name)
+ File.join(TEST_ROOT, "testcases", name)
+ end
+
end
View
59 test/whois/server/adapters/verisign_test.rb
@@ -10,53 +10,54 @@ def setup
end
def test_query
- response = "No match for DOMAIN.FOO."
- expected = response
- @server.expects(:ask_the_socket).with("=domain.foo", "whois.foo", 43).returns(response)
- answer = @server.query("domain.foo")
-
- assert_equal expected,
- answer.to_s
- assert_equal [Whois::Answer::Part.new(response, "whois.foo")],
- answer.parts
+ response1 = "No match for DOMAIN.FOO."
+ @server.expects(:ask_the_socket).with("=domain.foo", "whois.foo", 43).returns(response1)
+
+ record = @server.query("domain.foo")
+ assert_equal response1, record.to_s
+ assert_equal 1, record.parts.size
+ assert_equal [Whois::Answer::Part.new(response1, "whois.foo")],
+ record.parts
end
def test_query_with_referral
- referral = File.read(File.dirname(__FILE__) + "/../../../testcases/referrals/crsnic.com.txt")
- response = "Match for DOMAIN.FOO."
- expected = referral + "\n" + response
- @server.expects(:ask_the_socket).with("=domain.foo", "whois.foo", 43).returns(referral)
- @server.expects(:ask_the_socket).with("domain.foo", "whois.markmonitor.com", 43).returns(response)
- answer = @server.query("domain.foo")
-
- assert_equal expected,
- answer.to_s
- assert_equal [Whois::Answer::Part.new(referral, "whois.foo"), Whois::Answer::Part.new(response, "whois.markmonitor.com")],
- answer.parts
+ response1 = File.read(fixture("referrals/crsnic.com.txt"))
+ response2 = "Match for DOMAIN.FOO."
+ @server.expects(:ask_the_socket).with("=domain.foo", "whois.foo", 43).returns(response1)
+ @server.expects(:ask_the_socket).with("domain.foo", "whois.markmonitor.com", 43).returns(response2)
+
+ record = @server.query("domain.foo")
+ assert_equal response1 + "\n" + response2, record.to_s
+ assert_equal 2, record.parts.size
+ assert_equal [Whois::Answer::Part.new(response1, "whois.foo"), Whois::Answer::Part.new(response2, "whois.markmonitor.com")],
+ record.parts
end
def test_query_with_referral_not_defined_should_ignore_referral
- response1 = File.read(File.dirname(__FILE__) + "/../../../testcases/referrals/crsnic.com_server_not_defined.txt")
+ response1 = File.read(fixture("referrals/crsnic.com_server_not_defined.txt"))
@server.expects(:ask_the_socket).with("=domain.foo", "whois.foo", 43).returns(response1)
@server.expects(:ask_the_socket).never
record = @server.query("domain.foo")
assert_equal 1, record.parts.size
- assert_equal "whois.foo", record.parts.first.host
end
def test_query_with_referral_should_extract_the_closest_referral_server_with_more_servers
- referral = File.read(File.dirname(__FILE__) + "/../../../testcases/referrals/crsnic.com_many_servers.txt")
- @server.expects(:ask_the_socket).with("=domain.foo", "whois.foo", 43).returns(referral)
+ response1 = File.read(fixture("referrals/crsnic.com_many_servers.txt"))
+ @server.expects(:ask_the_socket).with("=domain.foo", "whois.foo", 43).returns(response1)
@server.expects(:ask_the_socket).with("domain.foo", "whois.markmonitor.com", 43).returns("")
- assert @server.query("domain.foo")
+
+ record = @server.query("domain.foo")
+ assert_equal 2, record.parts.size
end
def test_query_with_referral_should_extract_the_closest_referral_server_with_more_servers
- referral = File.read(File.dirname(__FILE__) + "/../../../testcases/referrals/crsnic.com_one_server.txt")
- @server.expects(:ask_the_socket).with("=domain.foo", "whois.foo", 43).returns(referral)
+ response1 = File.read(fixture("referrals/crsnic.com_one_server.txt"))
+ @server.expects(:ask_the_socket).with("=domain.foo", "whois.foo", 43).returns(response1)
@server.expects(:ask_the_socket).with("domain.foo", "whois.godaddy.com", 43).returns("")
- assert @server.query("domain.foo")
+
+ record = @server.query("domain.foo")
+ assert_equal 2, record.parts.size
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.