[前][次][番号順一覧][スレッド一覧]

ruby-changes:13108

From: akr <ko1@a...>
Date: Sat, 12 Sep 2009 12:12:00 +0900 (JST)
Subject: [ruby-changes:13108] Ruby:r24857 (trunk): more tests.

akr	2009-09-12 12:11:49 +0900 (Sat, 12 Sep 2009)

  New Revision: 24857

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24857

  Log:
    more tests.

  Modified files:
    trunk/test/test_open-uri.rb

Index: test/test_open-uri.rb
===================================================================
--- test/test_open-uri.rb	(revision 24856)
+++ test/test_open-uri.rb	(revision 24857)
@@ -25,6 +25,16 @@
     }
   end
 
+  def setup
+    @proxies = %w[http_proxy ftp_proxy no_proxy]
+    @old_proxies = @proxies.map {|k| ENV[k] }
+    @proxies.each {|k| ENV[k] = nil }
+  end
+
+  def teardown
+    @proxies.each_with_index {|k, i| ENV[k] = @old_proxies[i] }
+  end
+
   def test_200
     with_http {|srv, dr, url|
       open("#{dr}/foo200", "w") {|f| f << "foo200" }
@@ -312,5 +322,49 @@
     }
   end
 
+  def with_env(h)
+    begin
+      old = {}
+      h.each_key {|k| old[k] = ENV[k] }
+      h.each {|k, v| ENV[k] = v }
+      yield
+    ensure
+      h.each_key {|k| ENV[k] = old[k] }
+    end
+  end
+
+  def test_find_proxy
+    # 192.0.2.0/24 is TEST-NET.  RFC3330
+    assert_nil(URI("http://192.0.2.1/").find_proxy)
+    assert_nil(URI("ftp://192.0.2.1/").find_proxy)
+    with_env('http_proxy'=>'http://127.0.0.1:8080') {
+      assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy)
+      assert_nil(URI("ftp://192.0.2.1/").find_proxy)
+    }
+    with_env('ftp_proxy'=>'http://127.0.0.1:8080') {
+      assert_nil(URI("http://192.0.2.1/").find_proxy)
+      assert_equal(URI('http://127.0.0.1:8080'), URI("ftp://192.0.2.1/").find_proxy)
+    }
+    with_env('REQUEST_METHOD'=>'GET') {
+      assert_nil(URI("http://192.0.2.1/").find_proxy)
+    }
+    with_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'192.0.2.2') {
+      assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy)
+      assert_nil(URI("http://192.0.2.2/").find_proxy)
+    }
+  end
+
+  def test_find_proxy_case_sensitive_env
+    with_env('http_proxy'=>'http://127.0.0.1:8080', 'REQUEST_METHOD'=>'GET') {
+      assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy)
+    }
+    with_env('HTTP_PROXY'=>'http://127.0.0.1:8081', 'REQUEST_METHOD'=>'GET') {
+      assert_nil(nil, URI("http://192.0.2.1/").find_proxy)
+    }
+    with_env('http_proxy'=>'http://127.0.0.1:8080', 'HTTP_PROXY'=>'http://127.0.0.1:8081', 'REQUEST_METHOD'=>'GET') {
+      assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy)
+    }
+  end
+
 end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]