From e8236456c23edec616ae3f4ac242a487bdafe359 Mon Sep 17 00:00:00 2001 From: uu59 Date: Tue, 18 Nov 2014 16:01:39 +0900 Subject: [PATCH] Add feature spec --- app/models/fluentd/setting/config.rb | 4 + .../settings/source_and_output.html.haml | 54 ++++++----- config/locales/translation_en.yml | 1 + config/locales/translation_ja.yml | 1 + .../fluentd/setting/source_and_output_spec.rb | 92 +++++++++++++++++++ 5 files changed, 128 insertions(+), 24 deletions(-) create mode 100644 spec/features/fluentd/setting/source_and_output_spec.rb diff --git a/app/models/fluentd/setting/config.rb b/app/models/fluentd/setting/config.rb index bddc694..6cc0b2c 100644 --- a/app/models/fluentd/setting/config.rb +++ b/app/models/fluentd/setting/config.rb @@ -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" diff --git a/app/views/fluentd/settings/source_and_output.html.haml b/app/views/fluentd/settings/source_and_output.html.haml index e230408..84f673f 100644 --- a/app/views/fluentd/settings/source_and_output.html.haml +++ b/app/views/fluentd/settings/source_and_output.html.haml @@ -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 diff --git a/config/locales/translation_en.yml b/config/locales/translation_en.yml index 664d679..643a84f 100644 --- a/config/locales/translation_en.yml +++ b/config/locales/translation_en.yml @@ -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 diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index 51b688e..873f90a 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -125,6 +125,7 @@ ja: in: 入力 out: 出力 current: 現在の設定 + setting_empty: 設定されていません show: page_title: 設定ファイルの編集 edit: diff --git a/spec/features/fluentd/setting/source_and_output_spec.rb b/spec/features/fluentd/setting/source_and_output_spec.rb new file mode 100644 index 0000000..aba8121 --- /dev/null +++ b/spec/features/fluentd/setting/source_and_output_spec.rb @@ -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 } + + # http://docs.fluentd.org/articles/in_forward + type forward + port 24224 + + + + # http://docs.fluentd.org/articles/out_stdout + type stdout + + + + 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 + + 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