Welcome to mirror list, hosted at ThFree Co, Russian Federation.

retry_spec.rb « job « ci « mutations « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 82988854719209ef84081409bb610014b4372a7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'JobRetry', feature_category: :continuous_integration do
  include GraphqlHelpers

  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project) }
  let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user) }

  let(:job) { create(:ci_build, :success, pipeline: pipeline, name: 'build') }

  let(:mutation) do
    variables = {
      id: job.to_global_id.to_s
    }
    graphql_mutation(:job_retry, variables,
      <<-QL
                       errors
                       job {
                         id
                       }
      QL
    )
  end

  let(:mutation_response) { graphql_mutation_response(:job_retry) }

  before_all do
    project.add_maintainer(user)
  end

  it 'returns an error if the user is not allowed to retry the job' do
    post_graphql_mutation(mutation, current_user: create(:user))

    expect(graphql_errors).not_to be_empty
  end

  context 'when the job is a Ci::Build' do
    it 'retries the build' do
      post_graphql_mutation(mutation, current_user: user)

      expect(response).to have_gitlab_http_status(:success)
      new_job_id = GitlabSchema.object_from_id(mutation_response['job']['id']).sync.id

      new_job = ::Ci::Build.find(new_job_id)
      expect(new_job).not_to be_retried
    end
  end

  context 'when the job is a Ci::Bridge' do
    let(:job) { create(:ci_bridge, :success, pipeline: pipeline, name: 'puente') }

    it 'retries the bridge' do
      post_graphql_mutation(mutation, current_user: user)

      expect(response).to have_gitlab_http_status(:success)
      new_job_id = GitlabSchema.object_from_id(mutation_response['job']['id']).sync.id

      new_job = ::Ci::Bridge.find(new_job_id)
      expect(new_job).not_to be_retried
    end
  end

  context 'when given CI variables' do
    let(:job) { create(:ci_build, :success, :actionable, pipeline: pipeline, name: 'build') }

    let(:mutation) do
      variables = {
        id: job.to_global_id.to_s,
        variables: { key: 'MANUAL_VAR', value: 'test manual var' }
      }

      graphql_mutation(:job_retry, variables,
        <<-QL
                        errors
                        job {
                          id
                        }
        QL
      )
    end

    it 'applies them to a retried manual job' do
      post_graphql_mutation(mutation, current_user: user)

      expect(response).to have_gitlab_http_status(:success)

      new_job_id = GitlabSchema.object_from_id(mutation_response['job']['id']).sync.id
      new_job = ::Ci::Build.find(new_job_id)
      expect(new_job.job_variables.count).to be(1)
      expect(new_job.job_variables.first.key).to eq('MANUAL_VAR')
      expect(new_job.job_variables.first.value).to eq('test manual var')
    end
  end

  context 'when the job is not retryable' do
    let(:job) { create(:ci_build, :retried, pipeline: pipeline) }

    it 'returns an error' do
      post_graphql_mutation(mutation, current_user: user)

      expect(mutation_response['job']).to be(nil)
      expect(mutation_response['errors']).to match_array(['Job cannot be retried'])
    end
  end
end