summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/storage_check/gitlab_caller_spec.rb
blob: d869022fd31a1bca290cb3325af994ebbb01251c (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
require 'spec_helper'

describe Gitlab::StorageCheck::GitlabCaller do
  let(:options) { Gitlab::StorageCheck::Options.new('unix://tmp/socket.sock', nil, nil, false) }
  subject(:gitlab_caller) { described_class.new(options) }

  describe '#call!' do
    context 'when a socket is given' do
      it 'calls a socket' do
        fake_connection = double
        expect(fake_connection).to receive(:post)
        expect(Excon).to receive(:new).with('unix://tmp/socket.sock', socket: "tmp/socket.sock") { fake_connection }

        gitlab_caller.call!
      end
    end

    context 'when a host is given' do
      let(:options) { Gitlab::StorageCheck::Options.new('http://localhost:8080', nil, nil, false) }

      it 'it calls a http response' do
        fake_connection = double
        expect(Excon).to receive(:new).with('http://localhost:8080', socket: nil) { fake_connection }
        expect(fake_connection).to receive(:post)

        gitlab_caller.call!
      end
    end
  end

  describe '#headers' do
    it 'Adds the JSON header' do
      headers = gitlab_caller.headers

      expect(headers['Content-Type']).to eq('application/json')
    end

    context 'when a token was provided' do
      let(:options) { Gitlab::StorageCheck::Options.new('unix://tmp/socket.sock', 'atoken', nil, false) }

      it 'adds it to the headers' do
        expect(gitlab_caller.headers['TOKEN']).to eq('atoken')
      end
    end
  end
end