summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2018-01-11 15:29:37 +0100
committerBrett Walker <bwalker@gitlab.com>2018-01-22 17:25:11 +0100
commit0dc71abdd4f39916a1deba2657d81f54f465edb2 (patch)
treed998a3add0ae0d4dcdd5529c6f73eb1071ce0bd2
parent1a075899007da589a788b6b95c4b1f2a6396499d (diff)
downloadgitlab-ce-0dc71abdd4f39916a1deba2657d81f54f465edb2.tar.gz
replace use of faraday gem with airborne gem for QA API testing
-rw-r--r--qa/Gemfile2
-rw-r--r--qa/Gemfile.lock40
-rw-r--r--qa/qa.rb4
-rw-r--r--qa/qa/runtime/api.rb36
-rw-r--r--qa/qa/specs/features/api/users_spec.rb21
-rw-r--r--qa/qa/support/api_helpers.rb4
-rw-r--r--qa/qa/support/matchers/have_gitlab_api_status.rb17
7 files changed, 51 insertions, 73 deletions
diff --git a/qa/Gemfile b/qa/Gemfile
index efb4f87d83b..d69c71003ae 100644
--- a/qa/Gemfile
+++ b/qa/Gemfile
@@ -6,4 +6,4 @@ gem 'capybara-screenshot', '~> 1.0.18'
gem 'rake', '~> 12.3.0'
gem 'rspec', '~> 3.7'
gem 'selenium-webdriver', '~> 3.8.0'
-gem 'faraday', '~> 0.12'
+gem 'airborne', '~> 0.2.13'
diff --git a/qa/Gemfile.lock b/qa/Gemfile.lock
index 85dd648f835..565adac7499 100644
--- a/qa/Gemfile.lock
+++ b/qa/Gemfile.lock
@@ -1,8 +1,19 @@
GEM
remote: https://rubygems.org/
specs:
+ activesupport (5.1.4)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
+ i18n (~> 0.7)
+ minitest (~> 5.1)
+ tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
+ airborne (0.2.13)
+ activesupport
+ rack
+ rack-test (~> 0.6, >= 0.6.2)
+ rest-client (>= 1.7.3, < 3.0)
+ rspec (~> 3.1)
byebug (9.1.0)
capybara (2.16.1)
addressable
@@ -17,16 +28,25 @@ GEM
childprocess (0.8.0)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.2)
+ concurrent-ruby (1.0.5)
diff-lcs (1.3)
- faraday (0.13.1)
- multipart-post (>= 1.2, < 3)
+ domain_name (0.5.20170404)
+ unf (>= 0.0.5, < 1.0.0)
ffi (1.9.18)
+ http-cookie (1.0.3)
+ domain_name (~> 0.5)
+ i18n (0.9.1)
+ concurrent-ruby (~> 1.0)
launchy (2.4.3)
addressable (~> 2.3)
method_source (0.9.0)
+ mime-types (3.1)
+ mime-types-data (~> 3.2015)
+ mime-types-data (3.2016.0521)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
- multipart-post (2.0.0)
+ minitest (5.11.1)
+ netrc (0.11.0)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
pry (0.11.3)
@@ -40,11 +60,15 @@ GEM
rack-test (0.8.2)
rack (>= 1.0, < 3)
rake (12.3.0)
+ rest-client (2.0.2)
+ http-cookie (>= 1.0.2, < 2.0)
+ mime-types (>= 1.16, < 4.0)
+ netrc (~> 0.8)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
- rspec-core (3.7.0)
+ rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
@@ -57,6 +81,12 @@ GEM
selenium-webdriver (3.8.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
+ thread_safe (0.3.6)
+ tzinfo (1.2.4)
+ thread_safe (~> 0.1)
+ unf (0.1.4)
+ unf_ext
+ unf_ext (0.0.7.4)
xpath (2.1.0)
nokogiri (~> 1.3)
@@ -64,9 +94,9 @@ PLATFORMS
ruby
DEPENDENCIES
+ airborne (~> 0.2.13)
capybara (~> 2.16.1)
capybara-screenshot (~> 1.0.18)
- faraday (~> 0.12)
pry-byebug (~> 3.5.1)
rake (~> 12.3.0)
rspec (~> 3.7)
diff --git a/qa/qa.rb b/qa/qa.rb
index af1d83704f2..062f281f2b3 100644
--- a/qa/qa.rb
+++ b/qa/qa.rb
@@ -1,8 +1,7 @@
$: << File.expand_path(File.dirname(__FILE__))
require 'rspec/core'
-require 'faraday'
-require_relative 'qa/support/matchers/have_gitlab_api_status'
+require 'airborne'
module QA
##
@@ -15,7 +14,6 @@ module QA
autoload :Scenario, 'qa/runtime/scenario'
autoload :Browser, 'qa/runtime/browser'
autoload :Env, 'qa/runtime/env'
- autoload :API, 'qa/runtime/api'
autoload :Session, 'qa/runtime/session'
end
diff --git a/qa/qa/runtime/api.rb b/qa/qa/runtime/api.rb
deleted file mode 100644
index 05df1af5301..00000000000
--- a/qa/qa/runtime/api.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-module QA
- module Runtime
- module API
- VERSION = 'v4'.freeze
-
- class Client
- ##
- # GET an endpoint that belongs to a GitLab instance under a given address
- #
- # Example:
- #
- # get(:gitlab, api('/users', personal_access_token: 'something'))
- # get(:gitlab, api('/users', personal_access_token: 'something'), username: value, ...)
- # get('http://gitlab.example', '/api/v4/users?private_token=something')
- #
- # In case of an address that is a symbol we will try to guess address
- # based on `Runtime::Scenario#something_address`.
- def self.get(address, page, *args)
- session = Session.new(address, page).tap do |s|
- s.add_query_values(args)
- end
- API::Response.new(Faraday.get(session.address))
- end
- end
-
- class Response
- attr_reader :response, :json
-
- def initialize(response)
- @response = response
- @json = @response.status == 200 ? JSON.parse(@response.body) : nil
- end
- end
- end
- end
-end
diff --git a/qa/qa/specs/features/api/users_spec.rb b/qa/qa/specs/features/api/users_spec.rb
index 80ad0b3bd8e..86707d0f13c 100644
--- a/qa/qa/specs/features/api/users_spec.rb
+++ b/qa/qa/specs/features/api/users_spec.rb
@@ -8,25 +8,26 @@ module QA
end
context "when authenticated" do
+ let(:session) { Runtime::Session.new(:gitlab, api('/users', personal_access_token: @access_token)) }
+
scenario 'get list of users' do
- response = Runtime::API::Client.get(:gitlab, api('/users', personal_access_token: @access_token))
- expect(response.response).to have_gitlab_api_status(200)
+ get session.address
+ expect_status(200)
end
scenario 'returns an empty response when an invalid `username` parameter is passed' do
- response = Runtime::API::Client.get(:gitlab, api('/users', personal_access_token: @access_token),
- username: 'invalid')
-
- expect(response.response).to have_gitlab_api_status(200)
- expect(response.json).to be_an Array
- expect(response.json.size).to eq(0)
+ get session.address, { params: {username: 'invalid'} }
+ expect_status(200)
+ expect(json_body).to be_an Array
+ expect(json_body.size).to eq(0)
end
end
scenario "returns authorization error when token is invalid" do
- response = Runtime::API::Client.get(:gitlab, api('/users', personal_access_token: 'invalid'))
+ session = Runtime::Session.new(:gitlab, api('/users', personal_access_token: 'invalid'))
+ get session.address
- expect(response.response).to have_gitlab_api_status(401)
+ expect_status(401)
end
end
end
diff --git a/qa/qa/support/api_helpers.rb b/qa/qa/support/api_helpers.rb
index 7f834f6d4fc..1cd73565250 100644
--- a/qa/qa/support/api_helpers.rb
+++ b/qa/qa/support/api_helpers.rb
@@ -1,6 +1,8 @@
module QA
module Support
module ApiHelpers
+ API_VERSION = 'v4'.freeze
+
# Public: Prepend a request path with the path to the API
#
# path - Path to append
@@ -19,7 +21,7 @@ module QA
# => "/api/v2/issues?foo=bar&private_token=..."
#
# Returns the relative path to the requested API resource
- def api(path, version: Runtime::API::VERSION, personal_access_token: nil, oauth_access_token: nil)
+ def api(path, version: API_VERSION, personal_access_token: nil, oauth_access_token: nil)
full_path = "/api/#{version}#{path}"
if oauth_access_token
diff --git a/qa/qa/support/matchers/have_gitlab_api_status.rb b/qa/qa/support/matchers/have_gitlab_api_status.rb
deleted file mode 100644
index cf51bb416c0..00000000000
--- a/qa/qa/support/matchers/have_gitlab_api_status.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# checks a response from an api call using Faraday
-RSpec::Matchers.define :have_gitlab_api_status do |expected|
- match do |actual|
- expect(actual.status).to eq expected
- end
-
- description do
- "respond with numeric status code #{expected}"
- end
-
- failure_message do |actual|
- response_code = actual.status
-
- "expected the response to have status code #{expected.inspect}" \
- " but it was #{response_code}. The response was: #{actual.body}"
- end
-end