Skip to content

Commit 0b2767b

Browse files
committed
Add tests for bankrupt:purge task
1 parent 4f460bf commit 0b2767b

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ RSpec/DescribeClass:
1919
Exclude:
2020
- 'spec/bankrupt/tasks_spec.rb'
2121

22+
RSpec/ExampleLength:
23+
Exclude:
24+
- 'spec/bankrupt/tasks_spec.rb'
25+
2226
RSpec/MessageSpies:
2327
Enabled: false
2428

spec/bankrupt/tasks_spec.rb

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def etag
7777
MockResponse.new
7878
end
7979

80-
# rubocop:disable RSpec/ExampleLength
8180
it 'uploads files to s3' do
8281
allow(Aws::S3::Client).to receive(:new).and_return(s3_double)
8382

@@ -113,6 +112,54 @@ def etag
113112

114113
Rake::Task['bankrupt:cdn'].invoke
115114
end
116-
# rubocop:enable RSpec/ExampleLength
115+
end
116+
117+
describe 'purge' do
118+
before do
119+
Rake::Task['bankrupt:manifest'].reenable
120+
Rake::Task['bankrupt:manifest'].invoke
121+
Rake::Task['bankrupt:purge'].reenable
122+
end
123+
124+
let(:s3_double) { Aws::S3::Client.new(stub_responses: true) }
125+
let(:s3_response) do
126+
class MockResponse
127+
def deleted
128+
[1]
129+
end
130+
end
131+
132+
MockResponse.new
133+
end
134+
135+
it 'exits when there aren\'t any files in the manifest' do
136+
allow(Aws::S3::Client).to receive(:new).and_return(s3_double)
137+
allow(s3_double).to receive(:list_objects_v2).and_return(contents: [])
138+
allow(JSON).to receive(:parse).and_return({})
139+
140+
expect { Rake::Task['bankrupt:purge'].invoke }.to(
141+
raise_exception(SystemExit) do |ex|
142+
expect(ex.status).to eq(1)
143+
end
144+
)
145+
end
146+
147+
it 'deletes the objects not in the manifest' do
148+
allow(Aws::S3::Client).to receive(:new).and_return(s3_double)
149+
150+
s3_double.stub_responses(:list_objects_v2, contents:
151+
[
152+
{ key: 'test/app-123.css' },
153+
{ key: 'test/app-9b33890bb13bb1d8f975e9ab3902c05f.js' },
154+
{ key: 'test/app-a4197ed8dcb93d681801318bd25a41ed.css' }
155+
])
156+
157+
expect(s3_double).to receive(:delete_objects).with(
158+
bucket: 'bankrupt-test',
159+
delete: { objects: [{ key: 'test/app-123.css' }] }
160+
).and_return(s3_response)
161+
162+
Rake::Task['bankrupt:purge'].invoke
163+
end
117164
end
118165
end

0 commit comments

Comments
 (0)