lib/cloudflare/rspec/connection.rb in cloudflare-4.1.2 vs lib/cloudflare/rspec/connection.rb in cloudflare-4.1.3
- old
+ new
@@ -19,10 +19,12 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
require 'async/rspec'
+require 'async/http/proxy'
+
require_relative '../../cloudflare'
module Cloudflare
module RSpec
module Connection
@@ -33,13 +35,23 @@
# You must specify these in order for the tests to run.
let(:email) {ENV['CLOUDFLARE_EMAIL']}
let(:key) {ENV['CLOUDFLARE_KEY']}
- let(:connection) {@connection = Cloudflare.connect(key: key, email: email)}
+ let(:connection) do
+ if proxy_url = ENV['CLOUDFLARE_PROXY']
+ proxy_endpoint = Async::HTTP::Endpoint.parse(proxy_url)
+ @client = Async::HTTP::Client.new(proxy_endpoint)
+ @connection = Cloudflare.connect(@client.proxied_endpoint(DEFAULT_ENDPOINT), key: key, email: email)
+ else
+ @client = nil
+ @connection = Cloudflare.connect(key: key, email: email)
+ end
+ end
after do
@connection&.close
+ @client&.close
end
end
end
end