Skip to content

Commit 8d3911b

Browse files
committed
test: add tests
1 parent 1f2626e commit 8d3911b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/test_app.rb

+45
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,51 @@ def initialize(formatter)
190190
end
191191
end
192192

193+
describe "lock and unlock log dir" do
194+
before do
195+
app.log_base_dir = File.join(make_tmpdir, "log", "path")
196+
end
197+
198+
it "locks directory" do
199+
full_path = app.find_and_create_log_dir("tag")
200+
app.lock_log_dir
201+
202+
assert app.log_dir_locked?
203+
assert_equal File.join(full_path, ".lock"), app.lock_file.path
204+
end
205+
206+
it "raises LogDirNotInitialized when trying to lock " \
207+
"an unexisting directory" do
208+
assert_raises(Roby::Application::LogDirNotInitialized) do
209+
app.lock_log_dir
210+
end
211+
end
212+
213+
it "unlocks directory when it is reset" do
214+
full_path = app.find_and_create_log_dir("tag")
215+
app.lock_log_dir
216+
app.reset_log_dir
217+
218+
refute app.log_dir_locked?
219+
end
220+
221+
it "makes sure locks directory using the temp file" do
222+
full_path = app.find_and_create_log_dir("tag")
223+
temp_lock_file = File.join(full_path, ".lock.tmp")
224+
final_lock_file = File.join(full_path, ".lock")
225+
226+
refute File.exist?(final_lock_file)
227+
refute app.log_dir_locked?
228+
229+
app.lock_log_dir
230+
231+
refute File.exist?(temp_lock_file)
232+
assert File.exist?(final_lock_file)
233+
assert app.log_dir_locked?
234+
assert_equal final_lock_file, app.lock_file.path
235+
end
236+
end
237+
193238
describe "#find_and_create_log_dir" do
194239
before do
195240
app.log_base_dir = File.join(make_tmpdir, "log", "path")

0 commit comments

Comments
 (0)