summaryrefslogtreecommitdiff
path: root/spec/services/google_cloud/create_service_accounts_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/google_cloud/create_service_accounts_service_spec.rb')
-rw-r--r--spec/services/google_cloud/create_service_accounts_service_spec.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/services/google_cloud/create_service_accounts_service_spec.rb b/spec/services/google_cloud/create_service_accounts_service_spec.rb
new file mode 100644
index 00000000000..190e1a8098c
--- /dev/null
+++ b/spec/services/google_cloud/create_service_accounts_service_spec.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+# Mock Types
+MockGoogleOAuth2Credentials = Struct.new(:app_id, :app_secret)
+MockServiceAccount = Struct.new(:project_id, :unique_id)
+
+RSpec.describe GoogleCloud::CreateServiceAccountsService do
+ describe '#execute' do
+ before do
+ allow(Gitlab::Auth::OAuth::Provider).to receive(:config_for)
+ .with('google_oauth2')
+ .and_return(MockGoogleOAuth2Credentials.new('mock-app-id', 'mock-app-secret'))
+
+ allow_next_instance_of(GoogleApi::CloudPlatform::Client) do |client|
+ allow(client).to receive(:create_service_account)
+ .and_return(MockServiceAccount.new('mock-project-id', 'mock-unique-id'))
+ allow(client).to receive(:create_service_account_key)
+ .and_return('mock-key')
+ end
+ end
+
+ it 'creates unprotected vars', :aggregate_failures do
+ project = create(:project)
+
+ service = described_class.new(
+ project,
+ nil,
+ google_oauth2_token: 'mock-token',
+ gcp_project_id: 'mock-gcp-project-id',
+ environment_name: '*'
+ )
+
+ response = service.execute
+
+ expect(response.status).to eq(:success)
+ expect(response.message).to eq('Service account generated successfully')
+ expect(project.variables.count).to eq(3)
+ expect(project.variables.first.protected).to eq(false)
+ expect(project.variables.second.protected).to eq(false)
+ expect(project.variables.third.protected).to eq(false)
+ end
+ end
+end