From 7eddae31b731b34d3b3450edcd62ba832afe93ca Mon Sep 17 00:00:00 2001 From: Koichi TANAKA Date: Wed, 3 Dec 2014 16:36:27 +0900 Subject: [PATCH] Add spec for Fluentd::Agent::LocalCommon#pid --- .../models/fluentd/agent/local_common_spec.rb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/models/fluentd/agent/local_common_spec.rb diff --git a/spec/models/fluentd/agent/local_common_spec.rb b/spec/models/fluentd/agent/local_common_spec.rb new file mode 100644 index 0000000..a928ce9 --- /dev/null +++ b/spec/models/fluentd/agent/local_common_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' +require 'fileutils' + +describe 'Fluentd::Agent::LocalCommon' do + subject { target_class.new.tap{|t| t.pid_file = pid_file_path} } + + let!(:target_class) { Struct.new(:pid_file){ include Fluentd::Agent::LocalCommon } } + let!(:pid_file_path) { Rails.root.join('tmp', 'fluentd-test', 'local_common_test.pid').to_s } + + describe '#pid' do + context 'no pid file exists' do + its(:pid) { should be_nil } + end + + context 'empty pid file given' do + before { FileUtils.touch pid_file_path } + after { FileUtils.rm pid_file_path } + + its(:pid) { should be_nil } + end + + context 'valid pid file given' do + before { File.write pid_file_path, '99999' } + after { FileUtils.rm pid_file_path } + + its(:pid) { should eq(99999) } + end + end +end