File: pipeline_triggers_spec.rb

package info (click to toggle)
ruby-gitlab 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,660 kB
  • sloc: ruby: 12,582; makefile: 7; sh: 4
file content (159 lines) | stat: -rw-r--r-- 4,673 bytes parent folder | download
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Client do
  it { is_expected.to respond_to :delete_trigger }

  describe '.triggers' do
    before do
      stub_get('/projects/3/triggers', 'triggers')
      @triggers = Gitlab.triggers(3)
    end

    it 'gets the correct resource' do
      expect(a_get('/projects/3/triggers')).to have_been_made
    end

    it "returns an array of project's triggers" do
      expect(@triggers).to be_a Gitlab::PaginatedResponse
      expect(@triggers.first.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7')
    end
  end

  describe '.trigger' do
    before do
      stub_get('/projects/3/triggers/10', 'trigger')
      @trigger = Gitlab.trigger(3, 10)
    end

    it 'gets the correct resource' do
      expect(a_get('/projects/3/triggers/10')).to have_been_made
    end

    it 'returns information about a trigger' do
      expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z')
      expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7')
    end
  end

  describe '.create_trigger' do
    before do
      stub_post('/projects/3/triggers', 'trigger')
      @trigger = Gitlab.create_trigger(3, 'my description')
    end

    it 'gets the correct resource' do
      expect(a_post('/projects/3/triggers')
          .with(body: { description: 'my description' })).to have_been_made
    end

    it 'returns information about a new trigger' do
      expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z')
      expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7')
    end
  end

  describe '.update_trigger' do
    before do
      stub_put('/projects/3/triggers/1', 'trigger')
      @trigger = Gitlab.update_trigger(3, 1, description: 'my description')
    end

    it 'gets the correct resource' do
      expect(a_put('/projects/3/triggers/1')
          .with(body: { description: 'my description' })).to have_been_made
    end

    it 'returns information about the trigger' do
      expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z')
      expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7')
    end
  end

  describe '.trigger_take_ownership' do
    before do
      stub_post('/projects/3/triggers/1/take_ownership', 'trigger')
      @trigger = Gitlab.trigger_take_ownership(3, 1)
    end

    it 'gets the correct resource' do
      expect(a_post('/projects/3/triggers/1/take_ownership')).to have_been_made
    end

    it 'returns information about the trigger' do
      expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z')
      expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7')
    end
  end

  describe '.remove_trigger' do
    before do
      stub_delete('/projects/3/triggers/10', 'empty')
      @trigger = Gitlab.remove_trigger(3, 10)
    end

    it 'gets the correct resource' do
      expect(a_delete('/projects/3/triggers/10')).to have_been_made
    end
  end

  describe '.run_trigger' do
    before do
      stub_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline")
        .to_return(body: load_fixture('run_trigger'), status: 200)
    end

    context 'when private_token is not set' do
      before do
        Gitlab.private_token = nil
      end

      after do
        Gitlab.private_token = 'secret'
      end

      it 'does not raise Error::MissingCredentials' do
        expect { Gitlab.run_trigger(3, '7b9148c158980bbd9bcea92c17522d', 'master', a: 10) }.not_to raise_error
      end
    end

    context 'without variables' do
      before do
        @trigger = Gitlab.run_trigger(3, '7b9148c158980bbd9bcea92c17522d', 'master')
      end

      it 'gets the correct resource' do
        expect(a_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline")
          .with(body: {
                  token: '7b9148c158980bbd9bcea92c17522d',
                  ref: 'master'
                })).to have_been_made
      end

      it 'returns information about the triggered build' do
        expect(@trigger.id).to eq(8)
      end
    end

    context 'with variables' do
      before do
        @trigger = Gitlab.run_trigger(3, '7b9148c158980bbd9bcea92c17522d', 'master', a: 10)
      end

      it 'gets the correct resource' do
        expect(a_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline")
          .with(body: {
                  token: '7b9148c158980bbd9bcea92c17522d',
                  ref: 'master',
                  variables: { a: '10' }
                })).to have_been_made
      end

      it 'returns information about the triggered build' do
        expect(@trigger.id).to eq(8)
        expect(@trigger.variables.a).to eq('10')
      end
    end
  end
end