Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved test harness and code quality.
- Loading branch information
Showing
15 changed files
with
229 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'test_helper' | ||
|
||
class ServerAdaptersAfiliasTest < Test::Unit::TestCase | ||
include Whois | ||
|
||
def setup | ||
@definition = [".foo", "whois.foo", {}] | ||
@klass = Server::Adapters::Afilias | ||
@server = @klass.new(*@definition) | ||
end | ||
|
||
def test_query | ||
expected = "No match for DOMAIN.FOO." | ||
@server.expects(:ask_the_socket).with("domain.foo", "whois.afilias-grs.info", 43).returns(expected) | ||
assert_equal expected, @server.query("domain.foo") | ||
end | ||
|
||
def test_query_with_referral | ||
response = File.read(File.dirname(__FILE__) + "/../testcases/referrals/afilias.bz.txt") | ||
expected = "Match for DOMAIN.FOO." | ||
@server.expects(:ask_the_socket).with("domain.foo", "whois.afilias-grs.info", 43).returns(response) | ||
@server.expects(:ask_the_socket).with("domain.foo", "whois.belizenic.bz", 43).returns(expected) | ||
assert_equal expected, @server.query("domain.foo") | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'test_helper' | ||
|
||
class ServerAdaptersNoneTest < Test::Unit::TestCase | ||
include Whois | ||
|
||
def setup | ||
@definition = [".foo", nil, {}] | ||
@klass = Server::Adapters::None | ||
@server = @klass.new(*@definition) | ||
end | ||
|
||
def test_query | ||
assert_raise(NoInterfaceError) { @server.query("domain.foo") } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'test_helper' | ||
|
||
class ServerAdaptersPirTest < Test::Unit::TestCase | ||
include Whois | ||
|
||
def setup | ||
@definition = [".foo", "whois.foo", {}] | ||
@klass = Server::Adapters::Pir | ||
@server = @klass.new(*@definition) | ||
end | ||
|
||
def test_query | ||
expected = "No match for DOMAIN.FOO." | ||
@server.expects(:ask_the_socket).with("FULL domain.foo", "whois.publicinterestregistry.net", 43).returns(expected) | ||
assert_equal expected, @server.query("domain.foo") | ||
end | ||
|
||
def test_query_with_referral | ||
response = File.read(File.dirname(__FILE__) + "/../testcases/referrals/pir.org.txt") | ||
expected = "Match for DOMAIN.FOO." | ||
@server.expects(:ask_the_socket).with("FULL domain.foo", "whois.publicinterestregistry.net", 43).returns(response) | ||
@server.expects(:ask_the_socket).with("domain.foo", "whois.iana.org", 43).returns(expected) | ||
assert_equal expected, @server.query("domain.foo") | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'test_helper' | ||
|
||
class ServerAdaptersStandardTest < Test::Unit::TestCase | ||
include Whois | ||
|
||
def setup | ||
@definition = [".foo", "whois.foo", {}] | ||
@klass = Server::Adapters::Standard | ||
@server = @klass.new(*@definition) | ||
end | ||
|
||
def test_query | ||
@server.expects(:ask_the_socket).with("domain.foo", "whois.foo", 43) | ||
@server.query("domain.foo") | ||
end | ||
|
||
def test_query_with_port | ||
@server = @klass.new(".foo", "whois.foo", { :port => 20 }) | ||
@server.expects(:ask_the_socket).with("domain.foo", "whois.foo", 20) | ||
@server.query("domain.foo") | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'test_helper' | ||
|
||
class ServerAdaptersVerisignTest < Test::Unit::TestCase | ||
include Whois | ||
|
||
def setup | ||
@definition = [".foo", "whois.foo", {}] | ||
@klass = Server::Adapters::Verisign | ||
@server = @klass.new(*@definition) | ||
end | ||
|
||
def test_query | ||
expected = "No match for DOMAIN.FOO." | ||
@server.expects(:ask_the_socket).with("=domain.foo", "whois.crsnic.net", 43).returns(expected) | ||
assert_equal expected, @server.query("domain.foo") | ||
end | ||
|
||
def test_query_with_referral | ||
response = File.read(File.dirname(__FILE__) + "/../testcases/referrals/crsnic.com.txt") | ||
expected = "Match for DOMAIN.FOO." | ||
@server.expects(:ask_the_socket).with("=domain.foo", "whois.crsnic.net", 43).returns(response) | ||
@server.expects(:ask_the_socket).with("domain.foo", "whois.tucows.com", 43).returns(expected) | ||
assert_equal expected, @server.query("domain.foo") | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'test_helper' | ||
|
||
class ServerAdaptersWebTest < Test::Unit::TestCase | ||
include Whois | ||
|
||
def setup | ||
@definition = [".foo", nil, { :web => "http://whois.foo" }] | ||
@klass = Server::Adapters::Web | ||
@server = @klass.new(*@definition) | ||
end | ||
|
||
def test_query | ||
error = assert_raise(WebInterfaceError) { @server.query("domain.foo") } | ||
assert_match /whois\.foo/, error.message | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'test_helper' | ||
|
||
class ServerTest < Test::Unit::TestCase | ||
include Whois | ||
|
||
def test_guess_should_recognize_email | ||
Server.expects(:find_for_email).with("email@example.org").returns(true) | ||
assert Server.guess("email@example.org") | ||
end | ||
|
||
def test_guess_should_recognize_tld | ||
Server.expects(:find_for_tld).with("google.com").returns(true) | ||
assert Server.guess("google.com") | ||
end | ||
|
||
|
||
def test_definitions | ||
assert_instance_of Array, Server.definitions | ||
end | ||
|
||
|
||
def test_define | ||
Server.define(".foo", "whois.foo") | ||
assert_equal [".foo", "whois.foo", {}], Server.definitions.last | ||
end | ||
|
||
def test_define_with_options | ||
Server.define(".foo", "whois.foo", :foo => "bar") | ||
assert_equal [".foo", "whois.foo", { :foo => "bar" }], Server.definitions.last | ||
end | ||
|
||
|
||
def test_factory | ||
server = Server.factory(".foo", "whois.foo") | ||
assert_instance_of Server::Adapters::Standard, server | ||
end | ||
|
||
def test_factory_with_adapter | ||
server = Server.factory(".foo", "whois.foo", :adapter => Server::Adapters::None) | ||
assert_instance_of Server::Adapters::None, server | ||
end | ||
|
||
def test_factory_with_adapter_should_delete_adapter_option | ||
server = Server.factory(".foo", "whois.foo", :adapter => Server::Adapters::None, :foo => "bar") | ||
assert_equal server.options, { :foo => "bar" } | ||
end | ||
|
||
|
||
end |