Skip to content

Commit 524b6e1

Browse files
authored
Merge pull request #29 from mashhurs/fix-no-file-or-dir-ci-error
Fix the no file or dir CI issue that temfile might be loosing its ref.
2 parents d5ee36e + 2cd95b9 commit 524b6e1

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

spec/outputs/csv_spec.rb

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@
77

88
subject { described_class.new(options) }
99

10-
let(:tmpfile) { Tempfile.new('logstash-spec-output-csv').path }
11-
let(:output) { File.readlines(tmpfile) }
12-
let(:csv_output) { CSV.read(tmpfile) }
10+
let(:tmpfile) { Tempfile.new('logstash-spec-output-csv') }
11+
let(:tmpfile_path) { tmpfile.path }
12+
let(:output) { File.readlines(tmpfile_path) }
13+
let(:csv_output) { CSV.read(tmpfile_path) }
1314

1415
before(:each) do
1516
subject.register
1617
subject.multi_receive(events)
1718
end
1819

20+
# Explicitly close and unlink temp file to ensure immediate cleanup (Tempfile will cleanup eventually)
21+
after(:each) do
22+
tmpfile.close
23+
tmpfile.unlink
24+
end
25+
1926
context "when configured with a single field" do
2027
let(:events) { [ LogStash::Event.new("foo" => "bar") ] }
21-
let(:options) { { "path" => tmpfile, "fields" => "foo" } }
28+
let(:options) { { "path" => tmpfile_path, "fields" => "foo" } }
2229
it "writes a single field to a csv file" do
2330
expect(output.count).to eq(1)
2431
expect(output.first).to eq("bar\n")
@@ -30,7 +37,7 @@
3037
[ LogStash::Event.new("foo" => "bar", "baz" => "quux"),
3138
LogStash::Event.new("foo" => "bar", "baz" => "quux") ]
3239
end
33-
let(:options) { { "path" => tmpfile, "fields" => ["foo", "baz"] } }
40+
let(:options) { { "path" => tmpfile_path, "fields" => ["foo", "baz"] } }
3441
it "writes a line per event " do
3542
expect(output.count).to eq(2)
3643
end
@@ -44,7 +51,7 @@
4451
let(:events) do
4552
[ LogStash::Event.new("foo" => "bar", "baz" => "quux") ]
4653
end
47-
let(:options) { { "path" => tmpfile, "fields" => ["foo", "not_there", "baz"] } }
54+
let(:options) { { "path" => tmpfile_path, "fields" => ["foo", "not_there", "baz"] } }
4855

4956
it "skips on the resulting line" do
5057
expect(output.size).to eq(1)
@@ -56,7 +63,7 @@
5663
let(:events) do
5764
[ LogStash::Event.new("foo" => "one,two", "baz" => "quux") ]
5865
end
59-
let(:options) { { "path" => tmpfile, "fields" => ["foo", "baz"] } }
66+
let(:options) { { "path" => tmpfile_path, "fields" => ["foo", "baz"] } }
6067
it "correctly escapes them" do
6168
expect(output.size).to eq(1)
6269
expect(output[0]).to eq("\"one,two\",quux\n")
@@ -67,7 +74,7 @@
6774
let(:events) do
6875
[ LogStash::Event.new("foo" => 'one\ntwo', "baz" => "quux") ]
6976
end
70-
let(:options) { { "path" => tmpfile, "fields" => ["foo", "baz"] } }
77+
let(:options) { { "path" => tmpfile_path, "fields" => ["foo", "baz"] } }
7178
it "correctly escapes them" do
7279
expect(csv_output.size).to eq(1)
7380
expect(csv_output[0]).to eq(['one\ntwo', 'quux'])
@@ -78,7 +85,7 @@
7885
let(:events) do
7986
[ LogStash::Event.new("foo" => {"one" => "two"}, "baz" => "quux") ]
8087
end
81-
let(:options) { { "path" => tmpfile, "fields" => ["foo", "baz"] } }
88+
let(:options) { { "path" => tmpfile_path, "fields" => ["foo", "baz"] } }
8289

8390
it "are written as json" do
8491
expect(csv_output.size).to eq(1)
@@ -89,7 +96,7 @@
8996
let(:events) do
9097
[ LogStash::Event.new("foo" => {"one" => "two"}, "baz" => "quux") ]
9198
end
92-
let(:options) { { "path" => tmpfile, "fields" => ["[foo][one]", "baz"] } }
99+
let(:options) { { "path" => tmpfile_path, "fields" => ["[foo][one]", "baz"] } }
93100

94101
it "are referenced using field references" do
95102
expect(csv_output.size).to eq(1)
@@ -102,7 +109,7 @@
102109
let(:events) do
103110
[ LogStash::Event.new("foo" => {"one" => "two"}, "baz" => "quux") ]
104111
end
105-
let(:options) { { "path" => tmpfile, "fields" => ["[foo][missing]", "baz"] } }
112+
let(:options) { { "path" => tmpfile_path, "fields" => ["[foo][missing]", "baz"] } }
106113

107114
it "are blank" do
108115
expect(output.size).to eq(1)
@@ -114,7 +121,7 @@
114121
let(:events) do
115122
[ LogStash::Event.new("foo" => "one", "baz" => "two") ]
116123
end
117-
let(:options) { { "path" => tmpfile, "fields" => ["foo", "baz"], "csv_options" => {"col_sep" => "|" } } }
124+
let(:options) { { "path" => tmpfile_path, "fields" => ["foo", "baz"], "csv_options" => {"col_sep" => "|" } } }
118125

119126
it "uses separator in output" do
120127
expect(output.size).to eq(1)
@@ -127,7 +134,7 @@
127134
[ LogStash::Event.new("foo" => "one", "baz" => "two"),
128135
LogStash::Event.new("foo" => "one", "baz" => "two") ]
129136
end
130-
let(:options) { { "path" => tmpfile, "fields" => ["foo", "baz"], "csv_options" => {"col_sep" => "|", "row_sep" => "\t" } } }
137+
let(:options) { { "path" => tmpfile_path, "fields" => ["foo", "baz"], "csv_options" => {"col_sep" => "|", "row_sep" => "\t" } } }
131138

132139
it "uses separator in output" do
133140
expect(output.size).to eq(1)
@@ -149,7 +156,7 @@
149156
[ LogStash::Event.new(event_data) ]
150157
end
151158

152-
let(:options) { { "path" => tmpfile, "fields" => ["f1", "f2", "f3", "f4", "f5"] } }
159+
let(:options) { { "path" => tmpfile_path, "fields" => ["f1", "f2", "f3", "f4", "f5"] } }
153160
it "escapes them correctly" do
154161
expect(csv_output.size).to eq(1)
155162
expect(csv_output[0][0]).to eq("1+1")

0 commit comments

Comments
 (0)