-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_minio_update_spec.rb
More file actions
116 lines (97 loc) · 2.99 KB
/
Copy pathcheck_minio_update_spec.rb
File metadata and controls
116 lines (97 loc) · 2.99 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
# 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.shasum'
).to_return(response)
end
let(:response) do
{
body:
'285ec90006a6961ebcb7dd9685acc0ebcd08f561 '\
'minio.RELEASE.2021-07-08T19-43-25Z',
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) { 'minio version RELEASE.2021-07-08T19-43-25Z' }
let(:stderr) { nil }
let(:success) { true }
context 'with matching local and remote version' do
it 'should be ok if versions are equal' 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.2022-07-08T19-43-25Z',
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.2022-07-08T19-43-25Z'
)
expect(checksum_request).to have_been_requested
end
end
context 'with unknown local version' 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).to have_been_requested
end
end
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
end