Project

General

Profile

Revision 367f39d2

Added by Sebastian Gräßl over 5 years ago

Fixes #19694 - Align rubocop configuration with foreman-core

And fix offenses

View differences:

test/units/registry_api_test.rb
18 18
      let(:password) { 'secretpassword' }
19 19

  
20 20
      subject do
21
        Service::RegistryApi.new({
22
          url: url,
23
          password: password,
24
          user: user })
21
        Service::RegistryApi.new(
22
          :url => url,
23
          :password => password,
24
          :user => user
25
        )
25 26
      end
26 27

  
27 28
      test 'it sets the same user and password' do
......
37 38

  
38 39
    test 'calls get on #connection' do
39 40
      subject.connection
40
        .expects(:get).at_least_once
41
        .returns(json)
41
             .expects(:get).at_least_once
42
             .returns(json)
42 43

  
43 44
      subject.get(path)
44 45
    end
......
73 74
    test 'returns the response raw body if it is not JSON' do
74 75
      response = 'This is not JSON'
75 76
      subject.connection.stubs(:get)
76
        .returns(response)
77
             .returns(response)
77 78
      assert_equal response, subject.get('/v1/')
78 79
    end
79 80
  end
......
83 84
    let(:query) { 'centos' }
84 85

  
85 86
    test "calls #get with path and query" do
86
      subject.expects(:get).with(path, {q: query}) do |path_param, params|
87
      subject.expects(:get).with(path, q: query) do |path_param, params|
87 88
        assert_equal path, path_param
88 89
        assert_equal query, params[:q]
89 90
      end.returns({})
......
94 95
    test "falls back to #catalog if #get fails" do
95 96
      subject.expects(:catalog).with(query)
96 97

  
97
      subject.expects(:get).with(path, {q: query})
98
        .raises('Error')
98
      subject.expects(:get).with(path, q: query)
99
             .raises('Error')
99 100

  
100 101
      subject.search(query)
101 102
    end
......
112 113

  
113 114
    test "calls #get with path" do
114 115
      subject.expects(:get).with(path)
115
        .returns(catalog)
116
             .returns(catalog)
116 117

  
117 118
      subject.catalog(query)
118 119
    end
......
139 140

  
140 141
    test "falls back to #tags_v2 if #get fails" do
141 142
      subject.expects(:get).with(path)
142
        .raises('Error')
143
             .raises('Error')
143 144

  
144 145
      subject.expects(:tags_v2).with(query)
145 146
      subject.tags(query)
......
148 149
    # https://registry.access.redhat.com returns a hash not an array
149 150
    test 'handles a hash response correctly' do
150 151
      tags_hash = {
151
        "7.0-21": "e1f5733f050b2488a17b7630cb038bfbea8b7bdfa9bdfb99e63a33117e28d02f",
152
	"7.0-23": "bef54b8f8a2fdd221734f1da404d4c0a7d07ee9169b1443a338ab54236c8c91a",
153
	"7.0-27": "8e6704f39a3d4a0c82ec7262ad683a9d1d9a281e3c1ebbb64c045b9af39b3940"
152
        "7.0-21" => "e1f5733f050b2488a17b7630cb038bfbea8b7bdfa9bdfb99e63a33117e28d02f",
153
        "7.0-23" => "bef54b8f8a2fdd221734f1da404d4c0a7d07ee9169b1443a338ab54236c8c91a",
154
        "7.0-27" => "8e6704f39a3d4a0c82ec7262ad683a9d1d9a281e3c1ebbb64c045b9af39b3940"
154 155
      }
155 156
      subject.expects(:get).with(path)
156
        .returns(tags_hash)
157
             .returns(tags_hash)
157 158
      assert_equal '7.0-21', subject.tags(query).first['name']
158 159
    end
159 160
  end
......
166 167

  
167 168
    setup do
168 169
      subject.stubs(:get).with(v1_path)
169
        .raises('404 Not found')
170
             .raises('404 Not found')
170 171
    end
171 172

  
172 173
    test 'calls #get with path' do
173 174
      subject.expects(:get).with(path)
174
        .returns(tags)
175
             .returns(tags)
175 176
      subject.tags(query)
176 177
    end
177 178

  
......
185 186
  describe '#ok?' do
186 187
    test 'calls the API via #get with /v1/' do
187 188
      subject.connection.expects(:get)
188
        .with('/', nil, Service::RegistryApi::DEFAULTS[:connection].merge({ path: '/v1/' }))
189
        .returns('Docker Registry API')
189
             .with('/', nil, Service::RegistryApi::DEFAULTS[:connection].merge(path: '/v1/'))
190
             .returns('Docker Registry API')
190 191
      assert subject.ok?
191 192
    end
192 193

  
193 194
    test 'calls #get with /v2/ if /v1/fails' do
194 195
      subject.stubs(:get).with('/v1/')
195
        .raises('404 page not found')
196
             .raises('404 page not found')
196 197
      subject.expects(:get).with('/v2/')
197
        .returns({})
198
             .returns({})
198 199
      assert subject.ok?
199 200
    end
200 201
  end

Also available in: Unified diff