Commit 07a83845 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'fj-11845-expose-web-ide-terminal-services' into 'master'

Expose services in the web ide terminal entity

Closes #11845

See merge request gitlab-org/gitlab-ee!13665
parents ca74ce38 0764add3
...@@ -32,6 +32,10 @@ class WebIdeTerminal ...@@ -32,6 +32,10 @@ class WebIdeTerminal
proxy_project_job_path(project, build, format: :ws) proxy_project_job_path(project, build, format: :ws)
end end
def services
build.services.map(&:alias).compact + Array(build.image&.alias)
end
private private
def web_ide_terminal_route_generator(action, options = {}) def web_ide_terminal_route_generator(action, options = {})
......
...@@ -7,5 +7,6 @@ class WebIdeTerminalEntity < Grape::Entity ...@@ -7,5 +7,6 @@ class WebIdeTerminalEntity < Grape::Entity
expose :cancel_path expose :cancel_path
expose :retry_path expose :retry_path
expose :terminal_path expose :terminal_path
expose :services
expose :proxy_websocket_path, if: ->(_) { Feature.enabled?(:build_service_proxy) } expose :proxy_websocket_path, if: ->(_) { Feature.enabled?(:build_service_proxy) }
end end
---
title: Expose services in the web ide terminal entity
merge_request: 13665
author:
type: other
...@@ -26,4 +26,57 @@ describe WebIdeTerminal do ...@@ -26,4 +26,57 @@ describe WebIdeTerminal do
it 'returns the proxy_websocket_path of the build' do it 'returns the proxy_websocket_path of the build' do
expect(subject.proxy_websocket_path).to end_with("/jobs/#{build.id}/proxy.ws") expect(subject.proxy_websocket_path).to end_with("/jobs/#{build.id}/proxy.ws")
end end
describe 'services' do
let(:services_with_aliases) do
{
services: [{ name: 'postgres', alias: 'postgres' },
{ name: 'docker:stable-dind', alias: 'docker' }]
}
end
before do
allow(build).to receive(:options).and_return(config)
end
context 'when image does not have an alias' do
let(:config) do
{ image: 'ruby:2.1' }.merge(services_with_aliases)
end
it 'returns services aliases' do
expect(subject.services).to eq %w(postgres docker)
end
end
context 'when both image and services have aliases' do
let(:config) do
{ image: { name: 'ruby:2.1', alias: 'ruby' } }.merge(services_with_aliases)
end
it 'returns all aliases' do
expect(subject.services).to eq %w(postgres docker ruby)
end
end
context 'when image and services does not have any alias' do
let(:config) do
{ image: 'ruby:2.1', services: ['postgres'] }
end
it 'returns an empty array' do
expect(subject.services).to be_empty
end
end
context 'when no image nor services' do
let(:config) do
{ script: %w(echo) }
end
it 'returns an empty array' do
expect(subject.services).to be_empty
end
end
end
end end
...@@ -14,6 +14,7 @@ describe WebIdeTerminalEntity do ...@@ -14,6 +14,7 @@ describe WebIdeTerminalEntity do
it { is_expected.to have_key(:cancel_path) } it { is_expected.to have_key(:cancel_path) }
it { is_expected.to have_key(:retry_path) } it { is_expected.to have_key(:retry_path) }
it { is_expected.to have_key(:terminal_path) } it { is_expected.to have_key(:terminal_path) }
it { is_expected.to have_key(:services) }
context 'when feature flag build_service_proxy is enabled' do context 'when feature flag build_service_proxy is enabled' do
before do before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment