File: remote_mirrors_spec.rb

package info (click to toggle)
ruby-gitlab 6.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,824 kB
  • sloc: ruby: 12,742; makefile: 7; sh: 4; javascript: 3
file content (117 lines) | stat: -rw-r--r-- 3,627 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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Client do
  describe '.remote_mirrors' do
    before do
      stub_get('/projects/5/remote_mirrors', 'remote_mirrors')
      @mirrors = Gitlab.remote_mirrors(5)
    end

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

    it "returns a paginated response of project's push mirrors" do
      expect(@mirrors).to be_an Gitlab::PaginatedResponse
      expect(@mirrors.first).to be_a Gitlab::ObjectifiedHash
      expect(@mirrors.first.enabled).to be(true)
    end
  end

  describe '.remote_mirror' do
    before do
      stub_get('/projects/5/remote_mirrors/123456', 'remote_mirror')
      @mirror = Gitlab.remote_mirror(5, 123_456)
    end

    it 'gets the correct resource' do
      expect(a_get('/projects/5/remote_mirrors/123456')).to have_been_made
    end

    it "returns a paginated response of project's push mirrors" do
      expect(@mirror).to be_a Gitlab::ObjectifiedHash
      expect(@mirror.enabled).to be(true)
      expect(@mirror.url).to include('gitlab.com/mirror/target.git')
    end
  end

  describe '.create_remote_mirror' do
    let(:api_path) { '/projects/5/remote_mirrors' }
    let(:mirror_path) { 'https://username:token@example.com/gitlab/example.git' }

    before do
      stub_post(api_path, 'remote_mirror_create')
      @mirror = Gitlab.create_remote_mirror(5, mirror_path, enabled: false)
    end

    it 'posts to the correct resource' do
      expect(a_post(api_path).with(body: { url: mirror_path, enabled: false }))
        .to have_been_made
    end

    it 'returns a single remote mirror' do
      expect(@mirror).to be_a Gitlab::ObjectifiedHash
      expect(@mirror.enabled).to be(false)
      expect(@mirror.id).to eq(123_456)
      expect(@mirror.url).to include('example.com/gitlab/example.git')
    end
  end

  describe '.edit_remote_mirror' do
    let(:api_path) { '/projects/5/remote_mirrors/123456' }

    before do
      stub_put(api_path, 'remote_mirror_edit')
      @mirror = Gitlab.edit_remote_mirror(
        5,
        123_456,
        only_protected_branches: true,
        keep_divergent_refs: true
      )
    end

    it 'puts to the correct resource' do
      expect(a_put(api_path).with(body: { only_protected_branches: true, keep_divergent_refs: true }))
        .to have_been_made
    end

    it 'returns a single remote mirror' do
      expect(@mirror).to be_a Gitlab::ObjectifiedHash
      expect(@mirror.enabled).to be(false)
      expect(@mirror.only_protected_branches).to be(true)
      expect(@mirror.keep_divergent_refs).to be(true)
    end
  end

  describe '.delete_remote_mirror' do
    before do
      stub_request(:delete, "#{Gitlab.endpoint}/projects/5/remote_mirrors/123456")
        .with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
        .to_return(status: 204)
      @mirror = Gitlab.delete_remote_mirror(5, 123_456)
    end

    it 'deletes the correct resource' do
      expect(a_delete('/projects/5/remote_mirrors/123456')).to have_been_made
    end

    it 'removes the mirror' do
      expect(@mirror.to_h).to be_empty
    end
  end

  describe '.sync_remote_mirror' do
    before do
      stub_request(:post, "#{Gitlab.endpoint}/projects/5/remote_mirrors/123456/sync")
        .with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
        .to_return(status: 204)
      @mirror = Gitlab.sync_remote_mirror(5, 123_456)
    end

    it 'executes a POST to the correct resource' do
      expect(a_post('/projects/5/remote_mirrors/123456/sync')).to have_been_made
    end
  end
end