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

mock_ci_spec.rb « integrations « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 83954812bfe4b37853272c0ed8b6724639c865e5 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Integrations::MockCi do
  let_it_be(:project) { build(:project) }

  subject(:integration) { described_class.new(project: project, mock_service_url: generate(:url)) }

  it_behaves_like Integrations::BaseCi

  include_context Integrations::EnableSslVerification

  describe '#commit_status' do
    let(:sha) { generate(:sha) }

    def stub_request(*args)
      WebMock.stub_request(:get, integration.commit_status_path(sha)).to_return(*args)
    end

    def commit_status
      integration.commit_status(sha, 'master')
    end

    it 'returns allowed states' do
      described_class::ALLOWED_STATES.each do |state|
        stub_request(status: 200, body: { status: state }.to_json)

        expect(commit_status).to eq(state)
      end
    end

    it 'returns :pending for 404 responses' do
      stub_request(status: 404)

      expect(commit_status).to eq(:pending)
    end

    it 'returns :error for responses other than 200 or 404' do
      stub_request(status: 500)

      expect(commit_status).to eq(:error)
    end

    it 'returns :error for unknown states' do
      stub_request(status: 200, body: { status: 'unknown' }.to_json)

      expect(commit_status).to eq(:error)
    end

    it 'returns :error for invalid JSON' do
      stub_request(status: 200, body: '')

      expect(commit_status).to eq(:error)
    end

    it 'returns :error for non-hash JSON responses' do
      stub_request(status: 200, body: 23.to_json)

      expect(commit_status).to eq(:error)
    end

    it 'returns :error for JSON responses without a status' do
      stub_request(status: 200, body: { foo: :bar }.to_json)

      expect(commit_status).to eq(:error)
    end

    it 'returns :error when connection is refused' do
      stub_request(status: 500).to_raise(Errno::ECONNREFUSED)

      expect(commit_status).to eq(:error)
    end
  end
end