Add feature spec

This commit is contained in:
uu59 2014-11-18 16:01:39 +09:00
parent 22dd9c4bdb
commit e8236456c2
5 changed files with 128 additions and 24 deletions

View File

@ -11,6 +11,10 @@ class Fluentd
@file = config_file
end
def empty?
config.elements.length.zero?
end
def sources
config.elements.find_all do |elm|
elm.name == "source"

View File

@ -46,27 +46,33 @@
= icon('fa-file-text-o fa-lg')
= t("fluentd.common.setup_out_forward")
%h2= t('.current')
.row
.col-xs-6
%h3= t('.in')
- @config.sources.each_with_index do |elm, idx|
.panel.panel-default
.panel-heading{"data-toggle" => "collapse", "href" => "#source#{idx}", "title" => elm.inspect}
= elm["type"]
= icon('fa-caret-down')
.panel-body.collapse{"id" => "source#{idx}"}
%pre= elm.to_s
.col-xs-6
%h3= t('.out')
- @config.matches.each_with_index do |elm, idx|
.panel.panel-default
.panel-heading{"data-toggle" => "collapse", "href" => "#match#{idx}", "title" => elm.inspect}
= elm["type"]
(
= elm.arg
)
= icon('fa-caret-down')
.panel-body.collapse{"id" => "match#{idx}"}
%pre= elm.to_s
.current-settings
%h2= t('.current')
.row
.col-xs-6.input
%h3= t('.in')
- if @config.sources.empty?
%p.empty= t('.setting_empty')
- else
- @config.sources.each_with_index do |elm, idx|
.panel.panel-default
.panel-heading{"data-toggle" => "collapse", "href" => "#source#{idx}", "title" => elm.inspect}
= elm["type"]
= icon('fa-caret-down')
.panel-body.collapse{"id" => "source#{idx}"}
%pre= elm.to_s
.col-xs-6.output
%h3= t('.out')
- if @config.matches.empty?
%p.empty= t('.setting_empty')
- else
- @config.matches.each_with_index do |elm, idx|
.panel.panel-default
.panel-heading{"data-toggle" => "collapse", "href" => "#match#{idx}", "title" => elm.inspect}
= elm["type"]
(
= elm.arg
)
= icon('fa-caret-down')
.panel-body.collapse{"id" => "match#{idx}"}
%pre= elm.to_s

View File

@ -126,6 +126,7 @@ en:
in: Source
out: Output
current: Current setting
setting_empty: Not exists
show:
page_title: Config File
in_out_head: In/Out setting

View File

@ -125,6 +125,7 @@ ja:
in: 入力
out: 出力
current: 現在の設定
setting_empty: 設定されていません
show:
page_title: 設定ファイルの編集
edit:

View File

@ -0,0 +1,92 @@
require "spec_helper"
describe "source_and_output", js: true do
let(:exists_user) { build(:user) }
let(:daemon) { build(:fluentd, variant: "td-agent") }
before do
Fluentd.stub(:instance).and_return(daemon)
Fluentd::Agent::TdAgent.any_instance.stub(:detached_command).and_return(true)
end
before do
visit '/sessions/new'
within("form") do
fill_in 'session_name', :with => exists_user.name
fill_in 'session_password', :with => exists_user.password
end
click_button I18n.t("terms.sign_in")
end
before do
daemon.agent.config_write config_contents
visit source_and_output_daemon_setting_path
end
context "config is blank" do
let(:config_contents) { "" }
it do
page.should have_content(I18n.t("fluentd.settings.source_and_output.setting_empty"))
page.should have_css(".input .empty")
page.should have_css(".output .empty")
end
end
context "config is given" do
let(:config_contents) { <<-CONF.strip_heredoc }
<source>
# http://docs.fluentd.org/articles/in_forward
type forward
port 24224
</source>
<match debug.*>
# http://docs.fluentd.org/articles/out_stdout
type stdout
</match>
<match s3.*>
type s3
aws_key_id fofoaiofa
aws_sec_key aaaaaaaaaaaaaae
s3_bucket test
s3_endpoint s3-us-west-1.amazonaws.com
format out_file
include_time_key false
add_newline false
output_tag true
output_time true
store_as gzip
use_ssl true
buffer_type memory
</match>
CONF
it do
page.should_not have_content(I18n.t("fluentd.settings.source_and_output.setting_empty"))
page.should have_css('.input .panel .panel-heading')
page.should have_css('.output .panel .panel-heading')
end
it ".panel-body is hidden by default and click .panel-heading for display" do
page.should_not have_css('.input .panel .panel-body')
page.should_not have_css('.output .panel .panel-body')
all(".input .panel .panel-heading").first.click
page.should have_css('.input .panel .panel-body')
all(".output .panel .panel-heading").first.click
page.should have_css('.output .panel .panel-body')
end
it "display plugin name" do
within ".input" do
page.should have_content("forward")
end
within ".output" do
page.should have_content("stdout")
page.should have_content("s3")
end
end
end
end