scooter 4.3.2 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -343,12 +343,8 @@ module Scooter
343
343
 
344
344
  describe '.update_classes' do
345
345
  before do
346
- # find the index of the default Faraday::Adapter::NetHttp handler
347
- # and replace it with the Test adapter
348
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
349
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
350
- stub.post('/classifier-api/v1/update-classes') { [201, {}] }
351
- end
346
+ stub_request(:post, /classifier-api\/v1\/update-classes/).
347
+ to_return(status: 201, body: {}.to_json, headers: {"Content-Type"=> "application/json"})
352
348
  end
353
349
  it 'updates the classes for all environments' do
354
350
  expect { subject.update_classes }.not_to raise_error
@@ -379,12 +375,8 @@ module Scooter
379
375
 
380
376
  describe '.get_list_of_node_groups' do
381
377
  before do
382
- # find the index of the default Faraday::Adapter::NetHttp handler
383
- # and replace it with the Test adapter
384
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
385
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
386
- stub.get('classifier-api/v1/groups') { |env| [200, {}, group_list] }
387
- end
378
+ stub_request(:get, /classifier-api\/v1\/groups/).
379
+ to_return(status: 200, body: group_list.to_json, headers: {"Content-Type"=> "application/json"})
388
380
  end
389
381
  it 'returns list of groups' do
390
382
  expect { subject.get_list_of_node_groups }.not_to raise_error
@@ -395,12 +387,8 @@ module Scooter
395
387
 
396
388
  describe '.get_list_of_nodes' do
397
389
  before do
398
- # find the index of the default Faraday::Adapter::NetHttp handler
399
- # and replace it with the Test adapter
400
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
401
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
402
- stub.get('classifier-api/v1/nodes') { |env| [200, {}, node_list] }
403
- end
390
+ stub_request(:get, /classifier-api\/v1\/nodes/).
391
+ to_return(status: 200, body: node_list.to_json, headers: {"Content-Type"=> "application/json"})
404
392
  end
405
393
  it 'returns list of nodes' do
406
394
  expect { subject.get_list_of_nodes }.not_to raise_error
@@ -411,12 +399,8 @@ module Scooter
411
399
 
412
400
  describe '.get_list_of_environments' do
413
401
  before do
414
- # find the index of the default Faraday::Adapter::NetHttp handler
415
- # and replace it with the Test adapter
416
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
417
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
418
- stub.get('classifier-api/v1/environments') { |env| [200, {}, environment_list] }
419
- end
402
+ stub_request(:get, /classifier-api\/v1\/environments/).
403
+ to_return(status: 200, body: environment_list.to_json, headers: {"Content-Type"=> "application/json"})
420
404
  end
421
405
  it 'returns list of environments' do
422
406
  expect { subject.get_list_of_environments }.not_to raise_error
@@ -427,12 +411,8 @@ module Scooter
427
411
 
428
412
  describe '.get_list_of_classes' do
429
413
  before do
430
- # find the index of the default Faraday::Adapter::NetHttp handler
431
- # and replace it with the Test adapter
432
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
433
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
434
- stub.get('classifier-api/v1/classes') { |env| [200, {}, class_list] }
435
- end
414
+ stub_request(:get, /classifier-api\/v1\/classes/).
415
+ to_return(status: 200, body: class_list.to_json, headers: {"Content-Type"=> "application/json"})
436
416
  end
437
417
  it 'returns list of classes' do
438
418
  expect { subject.get_list_of_classes }.not_to raise_error
@@ -443,12 +423,8 @@ module Scooter
443
423
 
444
424
  describe '.nodes_match?' do
445
425
  before do
446
- # find the index of the default Faraday::Adapter::NetHttp handler
447
- # and replace it with the Test adapter
448
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
449
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
450
- stub.get('classifier-api/v1/nodes') { |env| [200, {}, node_list] }
451
- end
426
+ stub_request(:get, /classifier-api\/v1\/nodes/).
427
+ to_return(status: 200, body: node_list.to_json, headers: {"Content-Type"=> "application/json"})
452
428
  end
453
429
  it 'nodes do not match' do
454
430
  expect(subject.nodes_match?(node_list.dup.push('another_array_item'))).to be false
@@ -461,12 +437,8 @@ module Scooter
461
437
 
462
438
  describe '.groups_match?' do
463
439
  before do
464
- # find the index of the default Faraday::Adapter::NetHttp handler
465
- # and replace it with the Test adapter
466
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
467
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
468
- stub.get('classifier-api/v1/groups') { |env| [200, {}, group_list] }
469
- end
440
+ stub_request(:get, /classifier-api\/v1\/groups/).
441
+ to_return(status: 200, body: group_list.to_json, headers: {"Content-Type"=> "application/json"})
470
442
  end
471
443
  it 'groups do not match' do
472
444
  expect(subject.groups_match?(group_list.dup.push('another_array_item'))).to be false
@@ -479,12 +451,8 @@ module Scooter
479
451
 
480
452
  describe '.classes_match?' do
481
453
  before do
482
- # find the index of the default Faraday::Adapter::NetHttp handler
483
- # and replace it with the Test adapter
484
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
485
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
486
- stub.get('classifier-api/v1/classes') { |env| [200, {}, class_list] }
487
- end
454
+ stub_request(:get, /classifier-api\/v1\/classes/).
455
+ to_return(status: 200, body: class_list.to_json, headers: {"Content-Type"=> "application/json"})
488
456
  end
489
457
  it 'classes do not match' do
490
458
  expect(subject.classes_match?(class_list.dup.push('another_array_item'))).to be false
@@ -497,12 +465,8 @@ module Scooter
497
465
 
498
466
  describe '.environments_match?' do
499
467
  before do
500
- # find the index of the default Faraday::Adapter::NetHttp handler
501
- # and replace it with the Test adapter
502
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
503
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
504
- stub.get('classifier-api/v1/environments') { |env| [200, {}, environment_list] }
505
- end
468
+ stub_request(:get, /classifier-api\/v1\/environments/).
469
+ to_return(status: 200, body: environment_list.to_json, headers: {"Content-Type"=> "application/json"})
506
470
  end
507
471
  it 'environments do not match' do
508
472
  expect(subject.environments_match?(environment_list.dup.push('another_array_item'))).to be false
@@ -515,23 +479,26 @@ module Scooter
515
479
 
516
480
  describe '.classifier_database_matches_self?' do
517
481
  before do
518
- # find the index of the default Faraday::Adapter::NetHttp handler
519
- # and replace it with the Test adapter
520
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
521
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
522
- stub.get('classifier-api/v1/nodes') { |env| env[:url].to_s == "https://test.com:4433/classifier-api/v1/nodes" ?
523
- [200, [], node_list] :
524
- [200, [], node_list.dup.push('another_array_item')] }
525
- stub.get('classifier-api/v1/environments') { |env| env[:url].to_s == "https://test.com:4433/classifier-api/v1/environments" ?
526
- [200, [], environment_list] :
527
- [200, [], environment_list.dup.push('another_array_item')] }
528
- stub.get('classifier-api/v1/groups') { |env| env[:url].to_s == "https://test.com:4433/classifier-api/v1/groups" ?
529
- [200, [], group_list] :
530
- [200, [], group_list.dup.push('another_array_item')] }
531
- stub.get('classifier-api/v1/classes') { |env| env[:url].to_s == "https://test.com:4433/classifier-api/v1/classes" ?
532
- [200, [], class_list] :
533
- [200, [], class_list.dup.push('another_array_item')] }
534
- end
482
+ stub_request(:get, 'https://test.com:4433/classifier-api/v1/nodes').
483
+ to_return(status: 200, body: node_list.to_json, headers: {"Content-Type"=> "application/json"})
484
+ stub_request(:get, 'https://test2.com:4433/classifier-api/v1/nodes').
485
+ to_return(status: 200, body: node_list.dup.push('another_array_item').to_json, headers: {"Content-Type"=> "application/json"})
486
+
487
+ stub_request(:get, 'https://test.com:4433/classifier-api/v1/environments').
488
+ to_return(status: 200, body: environment_list.to_json, headers: {"Content-Type"=> "application/json"})
489
+ stub_request(:get, 'https://test2.com:4433/classifier-api/v1/environments').
490
+ to_return(status: 200, body: environment_list.dup.push('another_array_item').to_json, headers: {"Content-Type"=> "application/json"})
491
+
492
+ stub_request(:get, 'https://test.com:4433/classifier-api/v1/groups').
493
+ to_return(status: 200, body: group_list.to_json, headers: {"Content-Type"=> "application/json"})
494
+ stub_request(:get, 'https://test2.com:4433/classifier-api/v1/groups').
495
+ to_return(status: 200, body: group_list.dup.push('another_array_item').to_json, headers: {"Content-Type"=> "application/json"})
496
+
497
+ stub_request(:get, 'https://test.com:4433/classifier-api/v1/classes').
498
+ to_return(status: 200, body: class_list.to_json, headers: {"Content-Type"=> "application/json"})
499
+ stub_request(:get, 'https://test2.com:4433/classifier-api/v1/classes').
500
+ to_return(status: 200, body: class_list.dup.push('another_array_item').to_json, headers: {"Content-Type"=> "application/json"})
501
+
535
502
  expect(subject).to receive(:is_resolvable).exactly(8).times.and_return(true)
536
503
  end
537
504
  it 'compare with self' do
@@ -28,18 +28,19 @@ module Scooter
28
28
 
29
29
  context '"signin with a page that returns a token' do
30
30
  before do
31
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
32
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
33
- head = {"server"=>"nginx/1.8.1",
34
- "date"=>"Tue, 29 Nov 2016 22:05:41 GMT",
35
- "content-length"=>"0",
36
- "connection"=>"close",
37
- "set-cookie"=>"JSESSIONID=b05e9b11-5e9f-4d6a-9faf-e28a0415197d; Path=/; Secure; HttpOnly, rememberMe=deleteMe; Path=/auth; Max-Age=0; Expires=Mon, 28-Nov-2016 22:05:41 GMT, pl_ssti=0CeHhpz5PPLna7kpaEMcTHjJ62z9eizHTzsxEXNK8W20;Secure;Path=/",
38
- "location"=>"/",
39
- "x-frame-options"=>"DENY"}
40
- stub.post('/auth/login', "username=#{username}&password=#{password}") {[200, head, '']}
41
- stub.get('/') {[200, {}, '']}
42
- end
31
+ stub_request(:post, /auth\/login/).
32
+ to_return(status: 200,
33
+ body: '',
34
+ headers: {"server"=>"nginx/1.8.1",
35
+ "date"=>"Tue, 29 Nov 2016 22:05:41 GMT",
36
+ "content-length"=>"0",
37
+ "connection"=>"close",
38
+ "set-cookie"=>"JSESSIONID=b05e9b11-5e9f-4d6a-9faf-e28a0415197d; Path=/; Secure; HttpOnly, rememberMe=deleteMe; Path=/auth; Max-Age=0; Expires=Mon, 28-Nov-2016 22:05:41 GMT, pl_ssti=0CeHhpz5PPLna7kpaEMcTHjJ62z9eizHTzsxEXNK8W20;Secure;Path=/",
39
+ "location"=>"/",
40
+ "x-frame-options"=>"DENY"})
41
+
42
+ stub_request(:get, 'https://test.com/').
43
+ to_return(status: 200, body: '', headers: {})
43
44
  end
44
45
 
45
46
  it 'sends the credentials' do
@@ -55,18 +55,14 @@ module Scooter
55
55
  before do
56
56
  allow_any_instance_of(Beaker::Http::FaradayBeakerLogger).to receive(:info) { true }
57
57
  allow_any_instance_of(Beaker::Http::FaradayBeakerLogger).to receive(:debug) { true }
58
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
59
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
60
- stub.get('/test/route') {[500,
61
- {'content-type' => 'application/json;charset=UTF-8'},
62
- "{ \"key\" : \"value\" }"]}
63
- end
58
+
59
+ stub_request(:get, /test\/route/).
60
+ to_return(status: 500, body: {"key" => "value"}.to_json, headers: {"Content-Type"=> "application/json"})
64
61
  end
65
62
  it 'has a correctly parsed body in the error' do
66
63
  expect{subject.connection.get('/test/route')}.to raise_error do |error|
67
64
  expect(error.response[:body]).to be_a(Hash)
68
65
  end
69
-
70
66
  end
71
67
  end
72
68
  end
@@ -4,12 +4,18 @@ describe Scooter::HttpDispatchers::OrchestratorDispatcher do
4
4
 
5
5
  let(:orchestrator_api) { Scooter::HttpDispatchers::OrchestratorDispatcher.new(host) }
6
6
  let(:job_id) { random_string }
7
+ let(:schedule_task_payload) {
8
+ { 'task' => 'foo' }
9
+ }
10
+ let(:schedule_plan_payload) {
11
+ { 'plan' => 'foo' }
12
+ }
7
13
  let(:environment) {random_string}
8
14
  let(:logger) { double('logger')}
9
15
 
10
16
 
11
- unixhost = { roles: ['test_role'],
12
- 'platform' => 'debian-7-x86_64' }
17
+ unixhost = { roles: ['test_role'],
18
+ 'platform' => 'debian-7-x86_64' }
13
19
  let(:host) { Beaker::Host.create('test.com', unixhost, {:logger => logger}) }
14
20
 
15
21
  subject { orchestrator_api }
@@ -39,9 +45,21 @@ describe Scooter::HttpDispatchers::OrchestratorDispatcher do
39
45
  it { is_expected.to respond_to(:list_jobs).with(1).arguments }
40
46
  it { is_expected.not_to respond_to(:list_jobs).with(2).arguments }
41
47
 
42
- it 'should take a job_id' do
48
+ it 'should accept a max jobs argument' do
43
49
  expect(orchestrator_api.connection).to receive(:get).with('v1/jobs')
44
- expect{ orchestrator_api.list_jobs }.not_to raise_error
50
+ expect{ orchestrator_api.list_jobs(1) }.not_to raise_error
51
+ end
52
+ end
53
+
54
+ describe '.list_plan_jobs' do
55
+
56
+ it { is_expected.to respond_to(:list_jobs).with(0).arguments }
57
+ it { is_expected.to respond_to(:list_jobs).with(1).arguments }
58
+ it { is_expected.not_to respond_to(:list_jobs).with(2).arguments }
59
+
60
+ it 'should take accept a max plan_jobs argument' do
61
+ expect(orchestrator_api.connection).to receive(:get).with('v1/plan_jobs')
62
+ expect{ orchestrator_api.list_plan_jobs(1) }.not_to raise_error
45
63
  end
46
64
  end
47
65
 
@@ -72,7 +90,6 @@ describe Scooter::HttpDispatchers::OrchestratorDispatcher do
72
90
  it { is_expected.not_to respond_to(:get_job_report).with(0).arguments }
73
91
  it { is_expected.to respond_to(:get_job_report).with(1).arguments }
74
92
 
75
-
76
93
  it 'should take a job_id' do
77
94
  expect(orchestrator_api.connection).to receive(:get).with("v1/jobs/#{job_id}/report")
78
95
  expect{ orchestrator_api.get_job_report(job_id) }.not_to raise_error
@@ -172,9 +189,14 @@ describe Scooter::HttpDispatchers::OrchestratorDispatcher do
172
189
  it { is_expected.to respond_to(:create_scheduled_job).with(1).arguments }
173
190
  it { is_expected.not_to respond_to(:create_scheduled_job).with(2).arguments }
174
191
 
175
- it 'should take a job id' do
192
+ it 'should schedule a task' do
176
193
  expect(orchestrator_api.connection).to receive(:post).with("v1/command/schedule_task")
177
- expect{ orchestrator_api.create_scheduled_job(job_id) }.not_to raise_error
194
+ expect{ orchestrator_api.create_scheduled_job(schedule_task_payload) }.not_to raise_error
195
+ end
196
+
197
+ it 'should schedule a plan' do
198
+ expect(orchestrator_api.connection).to receive(:post).with("v1/command/schedule_plan")
199
+ expect{ orchestrator_api.create_scheduled_job(schedule_plan_payload) }.not_to raise_error
178
200
  end
179
201
  end
180
202
 
@@ -229,12 +251,8 @@ describe Scooter::HttpDispatchers::OrchestratorDispatcher do
229
251
  it {is_expected.to respond_to(:get_last_jobs).with(4).arguments }
230
252
 
231
253
  before do
232
- # find the index of the default Faraday::Adapter::NetHttp handler
233
- # and replace it with the Test adapter
234
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
235
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
236
- stub.get('/orchestrator/v1/jobs') { [200, {}] }
237
- end
254
+ stub_request(:get, /orchestrator\/v1\/jobs/).
255
+ to_return(status: 200, body: {}.to_json, headers: {"Content-Type"=> "application/json"})
238
256
  end
239
257
 
240
258
  it 'should make a request with query params' do
@@ -276,12 +294,8 @@ describe Scooter::HttpDispatchers::OrchestratorDispatcher do
276
294
  it {is_expected.to respond_to(:list_scheduled_jobs).with(2).arguments }
277
295
 
278
296
  before do
279
- # find the index of the default Faraday::Adapter::NetHttp handler
280
- # and replace it with the Test adapter
281
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
282
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
283
- stub.get('/orchestrator/v1/scheduled_jobs') { [200, {}] }
284
- end
297
+ stub_request(:get, /orchestrator\/v1\/scheduled_jobs/).
298
+ to_return(status: 200, body: {}.to_json, headers: {"Content-Type"=> "application/json"})
285
299
  end
286
300
 
287
301
  it 'should make a request with query params' do
@@ -29,12 +29,8 @@ module Scooter
29
29
  context 'with a beaker host passed in' do
30
30
  describe '.query_nodes' do
31
31
  before do
32
- # find the index of the default Faraday::Adapter::NetHttp handler
33
- # and replace it with the Test adapter
34
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
35
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
36
- stub.post('/pdb/query/v4/nodes') { [200, []] }
37
- end
32
+ stub_request(:post, /pdb\/query\/v4\/nodes/).
33
+ to_return(status: 200, body: [], headers: {})
38
34
  end
39
35
  it 'query for all nodes' do
40
36
  expect { subject.query_nodes }.not_to raise_error
@@ -51,12 +47,8 @@ module Scooter
51
47
 
52
48
  describe '.query_catalogs' do
53
49
  before do
54
- # find the index of the default Faraday::Adapter::NetHttp handler
55
- # and replace it with the Test adapter
56
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
57
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
58
- stub.post('/pdb/query/v4/catalogs') { [200, []] }
59
- end
50
+ stub_request(:post, /pdb\/query\/v4\/catalogs/).
51
+ to_return(status: 200, body: [], headers: {})
60
52
  end
61
53
  it 'query for all catalogs' do
62
54
  expect { subject.query_catalogs }.not_to raise_error
@@ -73,12 +65,8 @@ module Scooter
73
65
 
74
66
  describe '.query_reports' do
75
67
  before do
76
- # find the index of the default Faraday::Adapter::NetHttp handler
77
- # and replace it with the Test adapter
78
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
79
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
80
- stub.post('/pdb/query/v4/reports') { [200, []] }
81
- end
68
+ stub_request(:post, /pdb\/query\/v4\/reports/).
69
+ to_return(status: 200, body: [], headers: {})
82
70
  end
83
71
  it 'query for all reports' do
84
72
  expect { subject.query_reports }.not_to raise_error
@@ -95,12 +83,8 @@ module Scooter
95
83
 
96
84
  describe '.query_facts' do
97
85
  before do
98
- # find the index of the default Faraday::Adapter::NetHttp handler
99
- # and replace it with the Test adapter
100
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
101
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
102
- stub.post('/pdb/query/v4/facts') { [200, []] }
103
- end
86
+ stub_request(:post, /pdb\/query\/v4\/facts/).
87
+ to_return(status: 200, body: [], headers: {})
104
88
  end
105
89
  it 'query for all facts' do
106
90
  expect { subject.query_facts }.not_to raise_error
@@ -121,12 +105,10 @@ module Scooter
121
105
 
122
106
  describe '.nodes_match?' do
123
107
  before do
124
- # find the index of the default Faraday::Adapter::NetHttp handler
125
- # and replace it with the Test adapter
126
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
127
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
128
- stub.post('/pdb/query/v4/nodes') { [200, [], [{ 'certname' => 'name', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }]] }
129
- end
108
+ stub_request(:post, /pdb\/query\/v4\/nodes/).
109
+ to_return(status: 200,
110
+ body: [{ 'certname' => 'name', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }],
111
+ headers: {})
130
112
  end
131
113
  it 'nodes different size' do
132
114
  expect(subject.send(:nodes_match?, [{ 'certname' => 'name', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' },
@@ -148,12 +130,10 @@ module Scooter
148
130
 
149
131
  describe '.catalogs_match?' do
150
132
  before do
151
- # find the index of the default Faraday::Adapter::NetHttp handler
152
- # and replace it with the Test adapter
153
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
154
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
155
- stub.post('/pdb/query/v4/catalogs') { [200, [], [{ 'catalog_uuid' => 'catalog_uuid_1', 'producer_timestamp' => 'time' }]] }
156
- end
133
+ stub_request(:post, /pdb\/query\/v4\/catalogs/).
134
+ to_return(status: 200,
135
+ body: [{ 'catalog_uuid' => 'catalog_uuid_1', 'producer_timestamp' => 'time' }],
136
+ headers: {})
157
137
  end
158
138
  it 'catalogs different size' do
159
139
  expect(subject.send(:catalogs_match?, [{ 'catalog_uuid' => 'catalog_uuid_1', 'producer_timestamp' => 'time' },
@@ -170,13 +150,12 @@ module Scooter
170
150
 
171
151
  describe '.facts_match?' do
172
152
  before do
173
- # find the index of the default Faraday::Adapter::NetHttp handler
174
- # and replace it with the Test adapter
175
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
176
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
177
- stub.post('/pdb/query/v4/facts') { [200, [], [{ 'name' => 'name', 'value' => 'value' }]] }
178
- end
153
+ stub_request(:post, /pdb\/query\/v4\/facts/).
154
+ to_return(status: 200,
155
+ body: [{ 'name' => 'name', 'value' => 'value' }],
156
+ headers: {})
179
157
  end
158
+
180
159
  it 'facts different size' do
181
160
  expect(subject.send(:facts_match?, [{ 'name' => 'name', 'value' => 'value' },
182
161
  { 'name2' => 'name', 'value2' => 'value' }])).to be false
@@ -192,12 +171,10 @@ module Scooter
192
171
 
193
172
  describe '.reports_match?' do
194
173
  before do
195
- # find the index of the default Faraday::Adapter::NetHttp handler
196
- # and replace it with the Test adapter
197
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
198
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
199
- stub.post('/pdb/query/v4/reports') { [200, [], [{ 'hash' => 'hash_value', 'producer_timestamp' => 'time' }]] }
200
- end
174
+ stub_request(:post, /pdb\/query\/v4\/reports/).
175
+ to_return(status: 200,
176
+ body: [{ 'hash' => 'hash_value', 'producer_timestamp' => 'time' }],
177
+ headers: {})
201
178
  end
202
179
  it 'reports different size' do
203
180
  expect(subject.send(:reports_match?, [{ 'hash' => 'hash_value', 'producer_timestamp' => 'time' },
@@ -214,23 +191,43 @@ module Scooter
214
191
 
215
192
  describe '.replica_db_synced_with_master_db?' do
216
193
  before do
217
- # find the index of the default Faraday::Adapter::NetHttp handler
218
- # and replace it with the Test adapter
219
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
220
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
221
- stub.post('/pdb/query/v4/nodes') { |env| env[:url].to_s == "https://test.com:8081/pdb/query/v4/nodes" ?
222
- [200, [], [{ 'certname' => 'test.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }, { 'certname' => 'test.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }]] :
223
- [200, [], [{ 'certname' => 'test.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }, { 'certname' => 'test.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }]] }
224
- stub.post('/pdb/query/v4/catalogs') { |env| env[:url].to_s == "https://test.com:8081/pdb/query/v4/catalogs" ?
225
- [200, [], [{ 'certname' => 'test.com', 'catalog_uuid' => 'catalog_uuid_1', 'producer_timestamp' => 'time' }]] :
226
- [200, [], [{ 'certname' => 'test2.com', 'catalog_uuid' => 'catalog_uuid_2', 'producer_timestamp' => 'time2' }]] }
227
- stub.post('/pdb/query/v4/facts') { |env| env[:url].to_s == "https://test.com:8081/pdb/query/v4/facts" ?
228
- [200, [], [{ 'name' => 'name', 'value' => 'value' }]] :
229
- [200, [], [{ 'name' => 'name2', 'value' => 'value2' }]] }
230
- stub.post('/pdb/query/v4/reports') { |env| env[:url].to_s == "https://test.com:8081/pdb/query/v4/reports" ?
231
- [200, [], [{ 'certname' => 'test.com', 'hash' => 'hash_value', 'producer_timestamp' => 'time' }]] :
232
- [200, [], [{ 'certname' => 'test2.com', 'hash' => 'hash_value2', 'producer_timestamp' => 'time2' }]] }
233
- end
194
+ stub_request(:post, "https://test.com:8081/pdb/query/v4/nodes").
195
+ to_return(status: 200,
196
+ body: [{ 'certname' => 'test.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }, { 'certname' => 'test.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }],
197
+ headers: {})
198
+ stub_request(:post, "https://test2.com:8081/pdb/query/v4/nodes").
199
+ to_return(status: 200,
200
+ body: [{ 'certname' => 'test2.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }, { 'certname' => 'test.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }],
201
+ headers: {})
202
+
203
+ stub_request(:post, "https://test.com:8081/pdb/query/v4/catalogs").
204
+ to_return(status: 200,
205
+ body: [{ 'certname' => 'test.com', 'catalog_uuid' => 'catalog_uuid_1', 'producer_timestamp' => 'time' }],
206
+ headers: {})
207
+ stub_request(:post, "https://test2.com:8081/pdb/query/v4/catalogs").
208
+ to_return(status: 200,
209
+ body: [{ 'certname' => 'test2.com', 'catalog_uuid' => 'catalog_uuid_2', 'producer_timestamp' => 'time2' }],
210
+ headers: {})
211
+
212
+ stub_request(:post, "https://test.com:8081/pdb/query/v4/facts").
213
+ to_return(status: 200,
214
+ body: [{ 'name' => 'name', 'value' => 'value' }],
215
+ headers: {})
216
+ stub_request(:post, "https://test2.com:8081/pdb/query/v4/facts").
217
+ to_return(status: 200,
218
+ body: [{ 'name' => 'name2', 'value' => 'value2' }],
219
+ headers: {})
220
+
221
+ stub_request(:post, "https://test.com:8081/pdb/query/v4/reports").
222
+ to_return(status: 200,
223
+ body: [{ 'certname' => 'test.com', 'hash' => 'hash_value', 'producer_timestamp' => 'time' }],
224
+ headers: {})
225
+ stub_request(:post, "https://test2.com:8081/pdb/query/v4/reports").
226
+ to_return(status: 200,
227
+ body: [{ 'certname' => 'test2.com', 'hash' => 'hash_value2', 'producer_timestamp' => 'time2' }],
228
+ headers: {})
229
+
230
+
234
231
  expect(subject).to receive(:is_resolvable).exactly(8).times.and_return(true)
235
232
  expect(subject).to receive(:master_has_node?).twice.and_return(true)
236
233
  end