test/test_sauce.rb in sauce-0.1.0 vs test/test_sauce.rb in sauce-0.2.0

- old
+ new

@@ -3,55 +3,72 @@ class TestSauce < Test::Unit::TestCase context "A Client instance" do setup do # Create this file and put in your details to run the tests account = YAML.load_file "live_account.yml" - @client = Sauce::Client.new(:username => account["username"], - :access_key => account["access_key"]) - @client.destroy_all_tunnels + @username = account["username"] + @access_key = account["access_key"] + @ip = account["ip"] + @client = Sauce::Client.new(:username => @username, + :access_key => @access_key) + @client.tunnels.destroy end should "initialize with passed variables" do client = Sauce::Client.new(:username => "test_user", :access_key => "abc123") assert_equal client.api_url, "https://test_user:abc123@saucelabs.com/rest/test_user/" end should "create a tunnel with the current user" do - tunnel = @client.create_tunnel('DomainNames' => ["123.456.789.123"]) + tunnel = @client.tunnels.create('DomainNames' => ["192.168.0.110"]) tunnel.refresh! assert_not_nil tunnel - assert_equal "sgrove", tunnel.owner + assert_equal @username, tunnel.owner end should "list current tunnels" do - @client.create_tunnel('DomainNames' => ["111.111.111.111"]) - @client.create_tunnel('DomainNames' => ["111.111.111.112"]) - @client.create_tunnel('DomainNames' => ["111.111.111.113"]) + @client.tunnels.create('DomainNames' => ["192.168.0.111"]) + @client.tunnels.create('DomainNames' => ["192.168.0.112"]) + @client.tunnels.create('DomainNames' => ["192.168.0.113"]) - tunnels = @client.tunnels + tunnels = @client.tunnels.all assert_equal 3, tunnels.select{|t| t.status != "halting"}.count end should "destroy a tunnel" do - tunnel = @client.create_tunnel('DomainNames' => ["111.111.111.114"]) + tunnel = @client.tunnels.create('DomainNames' => ["192.168.0.114"]) tunnel.destroy assert_equal "halting", tunnel.status end should "destroy all tunnels" do - @client.create_tunnel('DomainNames' => ["111.111.111.115"]) - @client.create_tunnel('DomainNames' => ["111.111.111.116"]) - @client.create_tunnel('DomainNames' => ["111.111.111.117"]) + tunnel = @client.tunnels.create('DomainNames' => ["192.168.0.115"]) + tunnel = @client.tunnels.create('DomainNames' => ["192.168.0.116"]) + tunnel = @client.tunnels.create('DomainNames' => ["192.168.0.117"]) - @client.destroy_all_tunnels + @client.tunnels.destroy - @client.tunnels.each do |tunnel| + @client.tunnels.all.each do |tunnel| assert_equal "halting", tunnel.status end end + should "say hello on port 1025 if healthy" do + tunnel = @client.tunnels.create('DomainNames' => [@ip]) + + max_retries = 30 + retries = 0 + until tunnel.status == "running" or retries >= max_retries + sleep 5 + retries += 1 + tunnel.refresh! + end + + assert_equal true, tunnel.says_hello? + end + def teardown - @client.destroy_all_tunnels + @client.tunnels.destroy end end end