|
11 | 11 |
|
12 | 12 | let(:number_of_files) { 5 }
|
13 | 13 | let(:dummy_content) { "foobar\n" * 100 }
|
| 14 | + let(:factory) { LogStash::Outputs::S3::TemporaryFileFactory.new(prefix, tags, "none", temporary_directory)} |
14 | 15 |
|
15 | 16 | before do
|
16 | 17 | clean_remote_files(prefix)
|
17 |
| - # Use the S3 factory to create mutliples files with dummy content |
18 |
| - factory = LogStash::Outputs::S3::TemporaryFileFactory.new(prefix, tags, "none", temporary_directory) |
| 18 | + end |
19 | 19 |
|
20 |
| - # Creating a factory always create a file |
21 |
| - factory.current.write(dummy_content) |
22 |
| - factory.current.fsync |
23 | 20 |
|
24 |
| - (number_of_files - 1).times do |
25 |
| - factory.rotate! |
| 21 | + context 'with a non-empty tempfile' do |
| 22 | + before do |
| 23 | + # Creating a factory always create a file |
26 | 24 | factory.current.write(dummy_content)
|
27 | 25 | factory.current.fsync
|
| 26 | + |
| 27 | + (number_of_files - 1).times do |
| 28 | + factory.rotate! |
| 29 | + factory.current.write(dummy_content) |
| 30 | + factory.current.fsync |
| 31 | + end |
| 32 | + end |
| 33 | + it "uploads the file to the bucket" do |
| 34 | + subject.register |
| 35 | + try(20) do |
| 36 | + expect(bucket_resource.objects(:prefix => prefix).count).to eq(number_of_files) |
| 37 | + expect(Dir.glob(File.join(temporary_directory, "*")).size).to eq(0) |
| 38 | + expect(bucket_resource.objects(:prefix => prefix).first.acl.grants.collect(&:permission)).to include("READ", "WRITE") |
| 39 | + end |
28 | 40 | end
|
29 | 41 | end
|
30 | 42 |
|
31 |
| - it "uploads the file to the bucket" do |
32 |
| - subject.register |
33 |
| - try(20) do |
34 |
| - expect(bucket_resource.objects(:prefix => prefix).count).to eq(number_of_files) |
35 |
| - expect(Dir.glob(File.join(temporary_directory, "*")).size).to eq(0) |
36 |
| - expect(bucket_resource.objects(:prefix => prefix).first.acl.grants.collect(&:permission)).to include("READ", "WRITE") |
| 43 | + context 'with an empty tempfile' do |
| 44 | + before do |
| 45 | + factory.current |
| 46 | + factory.rotate! |
| 47 | + end |
| 48 | + |
| 49 | + it "should remove the temporary file" do |
| 50 | + expect(Dir.glob(::File.join(temporary_directory, "**", "*")).size).to be > 0 |
| 51 | + subject.register |
| 52 | + puts Dir.glob(::File.join(temporary_directory, "**", "*")) |
| 53 | + expect(Dir.glob(::File.join(temporary_directory, "**", "*")).size).to eq(0) |
| 54 | + end |
| 55 | + |
| 56 | + it "should not upload the file to the bucket" do |
| 57 | + expect(bucket_resource.objects(:prefix => prefix).count).to eq(0) |
| 58 | + expect(Dir.glob(::File.join(temporary_directory, "**", "*")).size).to be > 0 |
| 59 | + subject.register |
| 60 | + |
| 61 | + # Sleep to give enough time for plugin upload to s3 if it attempts to upload empty temporary file to S3 |
| 62 | + sleep 5 |
| 63 | + expect(bucket_resource.objects(:prefix => prefix).count).to eq(0) |
37 | 64 | end
|
38 | 65 | end
|
39 | 66 | end
|
|
0 commit comments