-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_minio_update_spec.rb
More file actions
164 lines (132 loc) · 4.34 KB
/
Copy pathcheck_minio_update_spec.rb
File metadata and controls
164 lines (132 loc) · 4.34 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# frozen_string_literal: true
require 'webmock/rspec'
require_relative '../bin/check-minio-update'
CheckMinioUpdate.class_variable_set(:@@autorun, false)
describe CheckMinioUpdate do
before do
stub_checksum_request
allow(check).to(receive(:output))
allow(Open3).to(
receive(:capture3).and_return([stdout, stderr, double(success?: success)])
)
end
let(:checksum_request) do
stub_request(
:get,
'https://dl.min.io/server/minio/release/linux-amd64/minio.sha256sum'
).to_return(response)
end
let(:response) do
{
body: '3832278ee2bb74d41b617788b4244e410b29e4a8 minio.RELEASE.2022-07-17T15-43-14Z', # rubocop:disable Layout/LineLength
status: 200
}
end
alias_method :stub_checksum_request, :checksum_request
let(:check) do
CheckMinioUpdate.new.tap do |check|
check.config[:checkurl] = 'https://dl.min.io/server/minio/release'
check.config[:platform] = 'linux-amd64'
end
end
let(:stdout) do
'Mar 25 07:37:03 weact-staging-db-07 minio[220013]: Version: RELEASE.2022-07-17T15-43-14Z (go1.21.8 linux/amd64)' # rubocop:disable Layout/LineLength
end
let(:stderr) { nil }
let(:success) { true }
context 'with matching local and remote version' do
it 'should be ok' do
expect { check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 0
end
expect(check).to have_received(:output).with(
'No new minio version available'
)
expect(checksum_request).to have_been_requested
end
end
context 'with different local and remote versions' do
let(:response) do
{
body:
'285ec90006a6961ebcb7dd9685acc0ebcd08f561 '\
'minio.RELEASE.3022-07-17T15-43-14Z',
status: 200
}
end
it 'should be critical' do
expect { check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 2
end
expect(check).to have_received(:output).with(
'New minio version available RELEASE.3022-07-17T15-43-14Z'
)
expect(checksum_request).to have_been_requested
end
end
context 'with unknown local version' do
context 'when minio executable not found' do
let(:stdout) { nil }
let(:stderr) { 'minio not found' }
let(:success) { false }
it 'should be unknown' do
expect { check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 3
end
expect(check).to have_received(:output).with(
'Unable to gather local minio version: minio not found'
)
expect(checksum_request).not_to have_been_requested
end
end
context 'when release could not be extracted' do
let(:stdout) { 'INVALID' }
it 'should be unknown' do
expect { check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 3
end
expect(check).to have_received(:output).with(
'Unable to extract release: INVALID'
)
expect(checksum_request).not_to have_been_requested
end
end
end
context 'with unknown remote version' do
context 'with release url not found' do
let(:response) { { body: '404 Not Found', status: 404 } }
it 'should be unknown' do
expect { check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 3
end
expect(check).to have_received(:output).with(
'Unable to gather latest minio version: 404 Not Found'
)
expect(checksum_request).to have_been_requested
end
end
context 'when release could not be extracted' do
let(:response) do
{
body: '3832278ee2bb74d41b617788b4244e410b29e4a8 INVALID',
status: 200
}
end
it 'should be unknown' do
expect { check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 3
end
expect(check).to have_received(:output).with(
'Unable to extract release: 3832278ee2bb74d41b617788b4244e410b29e4a8 INVALID' # rubocop:disable Layout/LineLength
)
expect(checksum_request).to have_been_requested
end
end
end
end