fleet-api 0.9.0 → 1.0.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.
@@ -1,123 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Fleet::Client::Job do
4
-
5
- subject { Fleet::Client.new }
6
-
7
- let(:response) { double(:response) }
8
-
9
- describe '#list_jobs' do
10
-
11
- before do
12
- allow(subject).to receive(:get).and_return(response)
13
- end
14
-
15
- it 'GETs the Fleet job key' do
16
- opts = { consistent: true, recursive: true, sorted: true }
17
- expect(subject).to receive(:get)
18
- .with('v2/keys/_coreos.com/fleet/job', opts)
19
- .and_return(response)
20
-
21
- subject.list_jobs
22
- end
23
-
24
- it 'returns the job response' do
25
- expect(subject.list_jobs).to eql(response)
26
- end
27
- end
28
-
29
- describe '#get_job' do
30
-
31
- let(:service_name) { 'foo.service' }
32
-
33
- before do
34
- allow(subject).to receive(:get).and_return(response)
35
- end
36
-
37
- it 'GETs the named Fleet job key' do
38
- opts = { consistent: true, recursive: true, sorted: false }
39
- expect(subject).to receive(:get)
40
- .with("v2/keys/_coreos.com/fleet/job/#{service_name}/object", opts)
41
- .and_return(response)
42
-
43
- subject.get_job(service_name)
44
- end
45
-
46
- it 'returns the job response' do
47
- expect(subject.get_job(service_name)).to eql(response)
48
- end
49
- end
50
-
51
- describe '#create_job' do
52
-
53
- let(:service_name) { 'foo.service' }
54
- let(:service_def) { { name: service_name } }
55
-
56
- before do
57
- allow(subject).to receive(:put).and_return(response)
58
- end
59
-
60
- it 'PUTs the service def to the Fleet job key' do
61
- opts = {
62
- querystring: { 'prevExist' => false },
63
- body: { value: service_def.to_json }
64
- }
65
-
66
- expect(subject).to receive(:put)
67
- .with("v2/keys/_coreos.com/fleet/job/#{service_name}/object", opts)
68
- .and_return(response)
69
-
70
- subject.create_job(service_name, service_def)
71
- end
72
-
73
- it 'returns the job response' do
74
- expect(subject.create_job(service_name, service_def)).to eql(response)
75
- end
76
- end
77
-
78
- describe '#delete_job' do
79
-
80
- let(:service_name) { 'foo.service' }
81
-
82
- before do
83
- allow(subject).to receive(:delete).and_return(response)
84
- end
85
-
86
- it 'DELETEs the named Fleet job key' do
87
- opts = { dir: false, recursive: true }
88
- expect(subject).to receive(:delete)
89
- .with("v2/keys/_coreos.com/fleet/job/#{service_name}", opts)
90
- .and_return(response)
91
-
92
- subject.delete_job(service_name)
93
- end
94
-
95
- it 'returns the job response' do
96
- expect(subject.delete_job(service_name)).to eql(response)
97
- end
98
- end
99
-
100
- describe '#update_job_target_state' do
101
-
102
- let(:service_name) { 'foo.service' }
103
- let(:state) { :foobared }
104
-
105
- before do
106
- allow(subject).to receive(:put).and_return(response)
107
- end
108
-
109
- it 'PUTs the state to the Fleet job state key' do
110
- opts = { value: state }
111
-
112
- expect(subject).to receive(:put)
113
- .with("v2/keys/_coreos.com/fleet/job/#{service_name}/target-state", opts)
114
- .and_return(response)
115
-
116
- subject.update_job_target_state(service_name, state)
117
- end
118
-
119
- it 'returns the job response' do
120
- expect(subject.update_job_target_state(service_name, state)).to eql(response)
121
- end
122
- end
123
- end
@@ -1,90 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Fleet::Middleware::Response::RaiseError do
4
-
5
- describe '#on_complete' do
6
-
7
- context 'when HTTP status is 200' do
8
-
9
- let(:env) { { status: 200 } }
10
-
11
- it 'raises no errors' do
12
- expect { subject.on_complete(env) }.to_not raise_error
13
- end
14
- end
15
-
16
- context 'when the HTTP status is a known error (404)' do
17
-
18
- let(:message) { 'not found' }
19
- let(:error_code) { 999 }
20
- let(:cause) { 'just because ' }
21
-
22
- let(:env) do
23
- {
24
- status: 404,
25
- body: "{ \"message\": \"#{message}\", \"errorCode\": #{error_code}, \"cause\": \"#{cause}\" }"
26
- }
27
- end
28
-
29
- it 'raises a NotFound execption' do
30
- expect { subject.on_complete(env) }.to raise_error(Fleet::NotFound)
31
- end
32
-
33
- it 'sets the message on the exception' do
34
- begin
35
- subject.on_complete(env)
36
- rescue Fleet::NotFound => ex
37
- expect(ex.message).to eq message
38
- end
39
- end
40
-
41
- it 'sets the error code on the exception' do
42
- begin
43
- subject.on_complete(env)
44
- rescue Fleet::NotFound => ex
45
- expect(ex.error_code).to eq error_code
46
- end
47
- end
48
-
49
- it 'sets the cause on the exception' do
50
- begin
51
- subject.on_complete(env)
52
- rescue Fleet::NotFound => ex
53
- expect(ex.cause).to eq cause
54
- end
55
- end
56
- end
57
-
58
- context 'when HTTP status is an unknown error' do
59
-
60
- let(:env) do
61
- {
62
- status: 499,
63
- body: "{ \"message\": \"err\" }"
64
- }
65
- end
66
-
67
- it 'raises an Error execption' do
68
- expect { subject.on_complete(env) }.to raise_error(Fleet::Error)
69
- end
70
- end
71
-
72
- context 'when error body is not JSON parseable' do
73
-
74
- let(:env) do
75
- {
76
- status: 499,
77
- body: 'FOO BAR'
78
- }
79
- end
80
-
81
- it 'sets the error message to be the response body' do
82
- begin
83
- subject.on_complete(env)
84
- rescue Fleet::Error => ex
85
- expect(ex.message).to eq env[:body]
86
- end
87
- end
88
- end
89
- end
90
- end