diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/graphql_shared/utils_spec.js | 52 | ||||
-rw-r--r-- | spec/lib/gitlab/database/query_analyzer_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/google_cloud/service_accounts_service_spec.rb | 58 |
3 files changed, 60 insertions, 52 deletions
diff --git a/spec/frontend/graphql_shared/utils_spec.js b/spec/frontend/graphql_shared/utils_spec.js index 4dffb4dc73a..9f478eedbfb 100644 --- a/spec/frontend/graphql_shared/utils_spec.js +++ b/spec/frontend/graphql_shared/utils_spec.js @@ -1,7 +1,6 @@ import { isGid, getIdFromGraphQLId, - getZeroBasedIdFromGraphQLId, convertToGraphQLId, convertToGraphQLIds, convertFromGraphQLIds, @@ -54,7 +53,7 @@ describe('getIdFromGraphQLId', () => { }, { input: 'gid://gitlab/Environments/0', - output: null, + output: 0, }, { input: 'gid://gitlab/Environments/123', @@ -71,55 +70,6 @@ describe('getIdFromGraphQLId', () => { }); }); -describe('getZeroBasedIdFromGraphQLId', () => { - [ - { - input: '', - output: null, - }, - { - input: null, - output: null, - }, - { - input: 2, - output: 2, - }, - { - input: 'gid://', - output: null, - }, - { - input: 'gid://gitlab/', - output: null, - }, - { - input: 'gid://gitlab/Environments', - output: null, - }, - { - input: 'gid://gitlab/Environments/', - output: null, - }, - { - input: 'gid://gitlab/Environments/0', - output: 0, - }, - { - input: 'gid://gitlab/Environments/123', - output: 123, - }, - { - input: 'gid://gitlab/DesignManagement::Version/2', - output: 2, - }, - ].forEach(({ input, output }) => { - it(`getZeroBasedIdFromGraphQLId returns ${output} when passed ${input}`, () => { - expect(getZeroBasedIdFromGraphQLId(input)).toBe(output); - }); - }); -}); - describe('convertToGraphQLId', () => { it('combines $type and $id into $result', () => { expect(convertToGraphQLId(mockType, mockId)).toBe(mockGid); diff --git a/spec/lib/gitlab/database/query_analyzer_spec.rb b/spec/lib/gitlab/database/query_analyzer_spec.rb index 3567bd6a058..f0a3021927b 100644 --- a/spec/lib/gitlab/database/query_analyzer_spec.rb +++ b/spec/lib/gitlab/database/query_analyzer_spec.rb @@ -65,7 +65,7 @@ RSpec.describe Gitlab::Database::QueryAnalyzer do def process_sql(sql) ApplicationRecord.load_balancer.read_write do |connection| - described_class.new.send(:process_sql, sql, connection) + described_class.instance.send(:process_sql, sql, connection) end end end diff --git a/spec/services/google_cloud/service_accounts_service_spec.rb b/spec/services/google_cloud/service_accounts_service_spec.rb new file mode 100644 index 00000000000..a0d09affa72 --- /dev/null +++ b/spec/services/google_cloud/service_accounts_service_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GoogleCloud::ServiceAccountsService do + let_it_be(:project) { create(:project) } + + let(:service) { described_class.new(project) } + + describe 'find_for_project' do + context 'when a project does not have GCP service account vars' do + before do + project.variables.build(key: 'blah', value: 'foo', environment_scope: 'world') + project.save! + end + + it 'returns an empty list' do + expect(service.find_for_project.length).to eq(0) + end + end + + context 'when a project has GCP service account ci vars' do + before do + project.variables.build(environment_scope: '*', key: 'GCP_PROJECT_ID', value: 'prj1') + project.variables.build(environment_scope: '*', key: 'GCP_SERVICE_ACCOUNT_KEY', value: 'mock') + project.variables.build(environment_scope: 'staging', key: 'GCP_PROJECT_ID', value: 'prj2') + project.variables.build(environment_scope: 'staging', key: 'GCP_SERVICE_ACCOUNT', value: 'mock') + project.variables.build(environment_scope: 'production', key: 'GCP_PROJECT_ID', value: 'prj3') + project.variables.build(environment_scope: 'production', key: 'GCP_SERVICE_ACCOUNT', value: 'mock') + project.variables.build(environment_scope: 'production', key: 'GCP_SERVICE_ACCOUNT_KEY', value: 'mock') + project.save! + end + + it 'returns a list of service accounts' do + list = service.find_for_project + + aggregate_failures 'testing list of service accounts' do + expect(list.length).to eq(3) + + expect(list.first[:environment]).to eq('*') + expect(list.first[:gcp_project]).to eq('prj1') + expect(list.first[:service_account_exists]).to eq(false) + expect(list.first[:service_account_key_exists]).to eq(true) + + expect(list.second[:environment]).to eq('staging') + expect(list.second[:gcp_project]).to eq('prj2') + expect(list.second[:service_account_exists]).to eq(true) + expect(list.second[:service_account_key_exists]).to eq(false) + + expect(list.third[:environment]).to eq('production') + expect(list.third[:gcp_project]).to eq('prj3') + expect(list.third[:service_account_exists]).to eq(true) + expect(list.third[:service_account_key_exists]).to eq(true) + end + end + end + end +end |