require File.dirname(__FILE__) + '/test_helper.rb' class TestDragongoserver < Test::Unit::TestCase BIN_PREFIX = 'bin/' MY_USERID=10737 # FIXME: def setup dgs_username = ENV['DGS_USERNAME'] dgs_password = ENV['DGS_PASSWORD'] @dgs = Dgs.new(dgs_username, dgs_password) @thomas_rank = GoRank.new(26, :kyu) end def test_username assert_equal 'thopre', @dgs.username, "username 'thopre' expected" # there should be NO method to get the password assert_raises(NoMethodError) { assert_equal 'not the real password', @dgs.password } end def test_get_rank assert_equal @thomas_rank.to_s, @dgs.get_rank.to_s, "does not match thopre's rank - or his rank has been changed" end def test_waiting_games zlist = @dgs.waiting_games assert zlist.kind_of?(Array) # assert_equal [1,2,3], zlist assert zlist == [] or games_in_300_000(zlist) end def games_in_300_000(a) result = true a.each { |item| if item < 300_000 or item > 399_999 result = false break end } result end def test_bug_duplicate_numbers_waiting_games zlist = @dgs.waiting_games assert_equal zlist.uniq, zlist end def test_bug_duplicate_numbers_running_games zlist = @dgs.running_games assert_equal zlist.uniq, zlist end def test_running_games zlist = @dgs.running_games assert zlist.kind_of?(Array) end # programm 'dgs' should be found def test_bin_dgs_version assert_equal "dgs " + Dragongoserver::VERSION::STRING + "\n", `#{BIN_PREFIX}dgs -v` assert_equal "dgs " + Dragongoserver::VERSION::STRING + "\n", `#{BIN_PREFIX}dgs --version` end # test waiting moves for me def test_bin_dgs_waiting assert_equal "lalala", `#{BIN_PREFIX}dgs -w` assert_equal "lalala", `#{BIN_PREFIX}dgs -waiting` end def test_dgs_userid assert_equal MY_USERID, @dgs.userid, "userid should be #{MY_USERID}" end # test my running games def test_bin_dgs_running expected = "you have a total of 29 running games 366511 372651 366534 340021 244839 366494 369415 369412 369306 369303 366535" assert_equal expected, `#{BIN_PREFIX}dgs -r` assert_equal expected, `#{BIN_PREFIX}dgs -running` end def test_bin_dgs_add_game assert_equal "Games was added to the waitingroom", `#{BIN_PREFIX}dgs --add-game` end end