summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/etag_caching/router_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/etag_caching/router_spec.rb')
-rw-r--r--spec/lib/gitlab/etag_caching/router_spec.rb147
1 files changed, 22 insertions, 125 deletions
diff --git a/spec/lib/gitlab/etag_caching/router_spec.rb b/spec/lib/gitlab/etag_caching/router_spec.rb
index dbd9cc230f1..c748ee00721 100644
--- a/spec/lib/gitlab/etag_caching/router_spec.rb
+++ b/spec/lib/gitlab/etag_caching/router_spec.rb
@@ -3,136 +3,33 @@
require 'spec_helper'
RSpec.describe Gitlab::EtagCaching::Router do
- it 'matches issue notes endpoint' do
- result = described_class.match(
- '/my-group/and-subgroup/here-comes-the-project/noteable/issue/1/notes'
- )
-
- expect(result).to be_present
- expect(result.name).to eq 'issue_notes'
- end
-
- it 'matches MR notes endpoint' do
- result = described_class.match(
- '/my-group/and-subgroup/here-comes-the-project/noteable/merge_request/1/notes'
- )
-
- expect(result).to be_present
- expect(result.name).to eq 'merge_request_notes'
- end
-
- it 'matches issue title endpoint' do
- result = described_class.match(
- '/my-group/my-project/-/issues/123/realtime_changes'
- )
-
- expect(result).to be_present
- expect(result.name).to eq 'issue_title'
- end
-
- it 'matches with a project name that includes a suffix of create' do
- result = described_class.match(
- '/group/test-create/-/issues/123/realtime_changes'
- )
-
- expect(result).to be_present
- expect(result.name).to eq 'issue_title'
- end
-
- it 'matches with a project name that includes a prefix of create' do
- result = described_class.match(
- '/group/create-test/-/issues/123/realtime_changes'
- )
-
- expect(result).to be_present
- expect(result.name).to eq 'issue_title'
- end
-
- it 'matches project pipelines endpoint' do
- result = described_class.match(
- '/my-group/my-project/-/pipelines.json'
- )
-
- expect(result).to be_present
- expect(result.name).to eq 'project_pipelines'
- end
-
- it 'matches commit pipelines endpoint' do
- result = described_class.match(
- '/my-group/my-project/-/commit/aa8260d253a53f73f6c26c734c72fdd600f6e6d4/pipelines.json'
- )
-
- expect(result).to be_present
- expect(result.name).to eq 'commit_pipelines'
- end
-
- it 'matches new merge request pipelines endpoint' do
- result = described_class.match(
- '/my-group/my-project/-/merge_requests/new.json'
- )
-
- expect(result).to be_present
- expect(result.name).to eq 'new_merge_request_pipelines'
- end
-
- it 'matches merge request pipelines endpoint' do
- result = described_class.match(
- '/my-group/my-project/-/merge_requests/234/pipelines.json'
- )
-
- expect(result).to be_present
- expect(result.name).to eq 'merge_request_pipelines'
- end
-
- it 'matches build endpoint' do
- result = described_class.match(
- '/my-group/my-project/builds/234.json'
- )
-
- expect(result).to be_present
- expect(result.name).to eq 'project_build'
- end
-
- it 'does not match blob with confusing name' do
- result = described_class.match(
- '/my-group/my-project/-/blob/master/pipelines.json'
- )
-
- expect(result).to be_blank
- end
+ describe '.match', :aggregate_failures do
+ context 'with RESTful routes' do
+ it 'matches project pipelines endpoint' do
+ result = match_route('/my-group/my-project/-/pipelines.json')
+
+ expect(result).to be_present
+ expect(result.name).to eq 'project_pipelines'
+ expect(result.router).to eq Gitlab::EtagCaching::Router::Restful
+ end
+ end
- it 'matches the cluster environments path' do
- result = described_class.match(
- '/my-group/my-project/-/clusters/47/environments'
- )
+ context 'with GraphQL routes' do
+ it 'matches pipelines endpoint' do
+ result = match_route('/api/graphql', 'pipelines/id/12')
- expect(result).to be_present
- expect(result.name).to eq 'cluster_environments'
+ expect(result).to be_present
+ expect(result.name).to eq 'pipelines_graph'
+ expect(result.router).to eq Gitlab::EtagCaching::Router::Graphql
+ end
+ end
end
- it 'matches the environments path' do
- result = described_class.match(
- '/my-group/my-project/environments.json'
- )
+ def match_route(path, header = nil)
+ headers = { 'X-GITLAB-GRAPHQL-RESOURCE-ETAG' => header }.compact
- expect(result).to be_present
- expect(result.name).to eq 'environments'
- end
-
- it 'matches pipeline#show endpoint' do
- result = described_class.match(
- '/my-group/my-project/-/pipelines/2.json'
+ described_class.match(
+ double(path_info: path, headers: headers)
)
-
- expect(result).to be_present
- expect(result.name).to eq 'project_pipeline'
- end
-
- it 'has a valid feature category for every route', :aggregate_failures do
- feature_categories = YAML.load_file(Rails.root.join('config', 'feature_categories.yml')).to_set
-
- described_class::ROUTES.each do |route|
- expect(feature_categories).to include(route.feature_category), "#{route.name} has a category of #{route.feature_category}, which is not valid"
- end
end
end