diff options
Diffstat (limited to 'spec/graphql/types/project_type_spec.rb')
-rw-r--r-- | spec/graphql/types/project_type_spec.rb | 144 |
1 files changed, 139 insertions, 5 deletions
diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index d825bd7ebd4..45a718683be 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -33,6 +33,7 @@ RSpec.describe GitlabSchema.types['Project'] do issue_status_counts terraform_states alert_management_integrations container_repositories container_repositories_count pipeline_analytics squash_read_only sast_ci_configuration + cluster_agent cluster_agents agent_configurations ci_template timelogs ] @@ -186,7 +187,7 @@ RSpec.describe GitlabSchema.types['Project'] do expect(analyzer['enabled']).to eq(true) end - context "with guest user" do + context 'with guest user' do before do project.add_guest(user) end @@ -194,7 +195,7 @@ RSpec.describe GitlabSchema.types['Project'] do context 'when project is private' do let(:project) { create(:project, :private, :repository) } - it "returns no configuration" do + it 'returns no configuration' do secure_analyzers_prefix = subject.dig('data', 'project', 'sastCiConfiguration') expect(secure_analyzers_prefix).to be_nil end @@ -214,7 +215,7 @@ RSpec.describe GitlabSchema.types['Project'] do end end - context "with non-member user" do + context 'with non-member user', :sidekiq_inline do before do project.team.truncate end @@ -222,7 +223,7 @@ RSpec.describe GitlabSchema.types['Project'] do context 'when project is private' do let(:project) { create(:project, :private, :repository) } - it "returns no configuration" do + it 'returns no configuration' do secure_analyzers_prefix = subject.dig('data', 'project', 'sastCiConfiguration') expect(secure_analyzers_prefix).to be_nil end @@ -240,7 +241,7 @@ RSpec.describe GitlabSchema.types['Project'] do end context 'when repository is accessible only by team members' do - it "returns no configuration" do + it 'returns no configuration' do project.project_feature.update!( merge_requests_access_level: ProjectFeature::DISABLED, builds_access_level: ProjectFeature::DISABLED, @@ -458,4 +459,137 @@ RSpec.describe GitlabSchema.types['Project'] do it { is_expected.to have_graphql_type(Types::Ci::JobTokenScopeType) } it { is_expected.to have_graphql_resolver(Resolvers::Ci::JobTokenScopeResolver) } end + + describe 'agent_configurations' do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + let_it_be(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + agentConfigurations { + nodes { + agentName + } + } + } + } + ) + end + + let(:agent_name) { 'example-agent-name' } + let(:kas_client) { instance_double(Gitlab::Kas::Client, list_agent_config_files: [double(agent_name: agent_name)]) } + + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } + + before do + project.add_maintainer(user) + allow(Gitlab::Kas::Client).to receive(:new).and_return(kas_client) + end + + it 'returns configured agents' do + agents = subject.dig('data', 'project', 'agentConfigurations', 'nodes') + + expect(agents.count).to eq(1) + expect(agents.first['agentName']).to eq(agent_name) + end + end + + describe 'cluster_agents' do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + let_it_be(:cluster_agent) { create(:cluster_agent, project: project, name: 'agent-name') } + let_it_be(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + clusterAgents { + count + nodes { + id + name + createdAt + updatedAt + + project { + id + } + } + } + } + } + ) + end + + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } + + before do + project.add_maintainer(user) + end + + it 'returns associated cluster agents' do + agents = subject.dig('data', 'project', 'clusterAgents', 'nodes') + + expect(agents.count).to be(1) + expect(agents.first['id']).to eq(cluster_agent.to_global_id.to_s) + expect(agents.first['name']).to eq('agent-name') + expect(agents.first['createdAt']).to be_present + expect(agents.first['updatedAt']).to be_present + expect(agents.first['project']['id']).to eq(project.to_global_id.to_s) + end + + it 'returns count of cluster agents' do + count = subject.dig('data', 'project', 'clusterAgents', 'count') + + expect(count).to be(project.cluster_agents.size) + end + end + + describe 'cluster_agent' do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + let_it_be(:cluster_agent) { create(:cluster_agent, project: project, name: 'agent-name') } + let_it_be(:agent_token) { create(:cluster_agent_token, agent: cluster_agent) } + let_it_be(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + clusterAgent(name: "#{cluster_agent.name}") { + id + + tokens { + count + nodes { + id + } + } + } + } + } + ) + end + + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } + + before do + project.add_maintainer(user) + end + + it 'returns associated cluster agents' do + agent = subject.dig('data', 'project', 'clusterAgent') + tokens = agent.dig('tokens', 'nodes') + + expect(agent['id']).to eq(cluster_agent.to_global_id.to_s) + + expect(tokens.count).to be(1) + expect(tokens.first['id']).to eq(agent_token.to_global_id.to_s) + end + + it 'returns count of agent tokens' do + agent = subject.dig('data', 'project', 'clusterAgent') + count = agent.dig('tokens', 'count') + + expect(cluster_agent.agent_tokens.size).to be(count) + end + end end |