44 lines
1.3 KiB
Ruby
44 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
RSpec.describe Gitlab::EtagCaching::Router do
|
|
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
|
|
|
|
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 'pipelines_graph'
|
|
expect(result.router).to eq Gitlab::EtagCaching::Router::Graphql
|
|
end
|
|
|
|
it 'matches pipeline sha endpoint' do
|
|
result = match_route('/api/graphql', 'pipelines/sha/4asd12lla2jiwjdqw9as32glm8is8hiu8s2c5jsw')
|
|
|
|
expect(result).to be_present
|
|
expect(result.name).to eq 'ci_editor'
|
|
expect(result.router).to eq Gitlab::EtagCaching::Router::Graphql
|
|
end
|
|
end
|
|
end
|
|
|
|
def match_route(path, header = nil)
|
|
headers = { 'X-GITLAB-GRAPHQL-RESOURCE-ETAG' => header }.compact
|
|
|
|
described_class.match(
|
|
double(path_info: path, headers: headers)
|
|
)
|
|
end
|
|
end
|