Skip to content
代码片段 群组 项目
未验证 提交 9387f7b4 编辑于 作者: Dzmitry Meshcharakou's avatar Dzmitry Meshcharakou 提交者: GitLab
浏览文件

Merge branch '444752-google-artifact-registry-client-user-agent' into 'master'

No related branches found
No related tags found
无相关合并请求
...@@ -125,6 +125,8 @@ def client ...@@ -125,6 +125,8 @@ def client
scope: CLOUD_PLATFORM_SCOPE scope: CLOUD_PLATFORM_SCOPE
) )
config.credentials = ::Google::Cloud::ArtifactRegistry::V1::ArtifactRegistry::Credentials.new(ext_credentials) config.credentials = ::Google::Cloud::ArtifactRegistry::V1::ArtifactRegistry::Credentials.new(ext_credentials)
config.rpcs.list_docker_images.metadata = user_agent_metadata
config.rpcs.get_docker_image.metadata = user_agent_metadata
end end
end end
strong_memoize_attr :client strong_memoize_attr :client
...@@ -132,6 +134,12 @@ def client ...@@ -132,6 +134,12 @@ def client
def artifact_registry_integration def artifact_registry_integration
project.google_cloud_platform_artifact_registry_integration project.google_cloud_platform_artifact_registry_integration
end end
def user_agent_metadata
user_agent = "gitlab-rails-dot-com:google-cloud-integration/#{Gitlab::VERSION}"
{ 'user-agent' => user_agent }
end
end end
end end
end end
...@@ -18,13 +18,20 @@ ...@@ -18,13 +18,20 @@
let(:artifact_registry_location) { artifact_registry_integration&.artifact_registry_location } let(:artifact_registry_location) { artifact_registry_integration&.artifact_registry_location }
let(:artifact_registry_repository) { artifact_registry_integration&.artifact_registry_repository } let(:artifact_registry_repository) { artifact_registry_integration&.artifact_registry_repository }
let(:client) { described_class.new(wlif_integration: wlif_integration, user: user) } let(:client) { described_class.new(wlif_integration: wlif_integration, user: user) }
let(:expected_metadata) { { 'user-agent' => "gitlab-rails-dot-com:google-cloud-integration/#{Gitlab::VERSION}" } }
shared_context 'with a client double' do shared_context 'with a client double' do
let(:client_double) { instance_double('::Google::Cloud::ArtifactRegistry::V1::ArtifactRegistry::Client') }
let(:config_double) do let(:config_double) do
instance_double('Google::Cloud::ArtifactRegistry::V1::ArtifactRegistry::Client::Configuration') instance_double('Google::Cloud::ArtifactRegistry::V1::ArtifactRegistry::Client::Configuration')
end end
let(:rpcs_double) do
instance_double('Google::Cloud::ArtifactRegistry::V1::ArtifactRegistry::Client::Configuration::Rpcs')
end
let(:rpc_list_docker_images_double) { instance_double('Gapic::Config::Method') }
let(:rpc_get_docker_image_double) { instance_double('Gapic::Config::Method') }
let(:client_double) { instance_double('::Google::Cloud::ArtifactRegistry::V1::ArtifactRegistry::Client') }
let(:dummy_response) { Object.new } let(:dummy_response) { Object.new }
before do before do
...@@ -34,6 +41,11 @@ ...@@ -34,6 +41,11 @@
allow(config_double).to receive(:credentials=) allow(config_double).to receive(:credentials=)
.with(instance_of(::Google::Cloud::ArtifactRegistry::V1::ArtifactRegistry::Credentials)) .with(instance_of(::Google::Cloud::ArtifactRegistry::V1::ArtifactRegistry::Credentials))
allow(config_double).to receive(:rpcs).and_return(rpcs_double)
allow(rpcs_double).to receive(:list_docker_images).and_return(rpc_list_docker_images_double)
allow(rpcs_double).to receive(:get_docker_image).and_return(rpc_get_docker_image_double)
allow(rpc_list_docker_images_double).to receive(:metadata=)
allow(rpc_get_docker_image_double).to receive(:metadata=)
allow(::Google::Cloud::ArtifactRegistry::V1::ArtifactRegistry::Client).to receive(:new) do |_, &block| allow(::Google::Cloud::ArtifactRegistry::V1::ArtifactRegistry::Client).to receive(:new) do |_, &block|
block.call(config_double) block.call(config_double)
client_double client_double
...@@ -96,6 +108,7 @@ ...@@ -96,6 +108,7 @@
shared_examples 'returning the expected response' do |expected_page_size: described_class::DEFAULT_PAGE_SIZE| shared_examples 'returning the expected response' do |expected_page_size: described_class::DEFAULT_PAGE_SIZE|
it 'returns the expected response' do it 'returns the expected response' do
expect(rpc_list_docker_images_double).to receive(:metadata=).with(expected_metadata)
expect(client_double).to receive(:list_docker_images) do |request| expect(client_double).to receive(:list_docker_images) do |request|
expect(request).to be_a ::Google::Cloud::ArtifactRegistry::V1::ListDockerImagesRequest expect(request).to be_a ::Google::Cloud::ArtifactRegistry::V1::ListDockerImagesRequest
expect(request.page_size).to eq(expected_page_size) expect(request.page_size).to eq(expected_page_size)
...@@ -140,6 +153,7 @@ ...@@ -140,6 +153,7 @@
subject(:docker_image) { client.docker_image(name: name) } subject(:docker_image) { client.docker_image(name: name) }
it 'returns the expected response' do it 'returns the expected response' do
expect(rpc_get_docker_image_double).to receive(:metadata=).with(expected_metadata)
expect(client_double).to receive(:get_docker_image) do |request| expect(client_double).to receive(:get_docker_image) do |request|
expect(request).to be_a ::Google::Cloud::ArtifactRegistry::V1::GetDockerImageRequest expect(request).to be_a ::Google::Cloud::ArtifactRegistry::V1::GetDockerImageRequest
expect(request.name).to eq(name) expect(request.name).to eq(name)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册