fluentd-ui 1.0.0.beta.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd-ui might be problematic. Click here for more details.

Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +24 -0
  3. data/Gemfile +5 -3
  4. data/Gemfile.lock +88 -75
  5. data/README.md +11 -0
  6. data/Rakefile +1 -1
  7. data/app/javascript/packs/aws_credential.js +1 -1
  8. data/app/javascript/packs/in_tail_parse.js +1 -1
  9. data/app/javascript/packs/owned_plugin_form.js +1 -1
  10. data/app/javascript/packs/settings.js +20 -9
  11. data/app/javascript/packs/transport_config.js +1 -1
  12. data/app/javascript/packs/transport_section.js +1 -1
  13. data/app/javascript/packs/treeview.js +2 -2
  14. data/app/models/plugin.rb +2 -2
  15. data/app/views/fluentd/settings/source_and_output.html.haml +12 -10
  16. data/app/views/layouts/application.html.erb +3 -0
  17. data/app/views/plugins/recommended.html.haml +3 -0
  18. data/app/views/plugins/updated.html.haml +5 -6
  19. data/config.ru +3 -1
  20. data/config/application.rb +1 -1
  21. data/config/application.yml +104 -31
  22. data/config/locales/translation_en.yml +1 -0
  23. data/config/locales/translation_ja.yml +1 -0
  24. data/gemfiles/ruby2.2.gemfile +2 -1
  25. data/lib/fluentd-ui/version.rb +1 -1
  26. data/test/application_system_test_case.rb +8 -0
  27. data/test/controllers/application_controller_test.rb +42 -0
  28. data/test/controllers/fluentd/agents_controller_test.rb +39 -0
  29. data/test/controllers/misc_controller_test.rb +70 -0
  30. data/test/controllers/polling_controller_test.rb +29 -0
  31. data/test/decorators/plugin_decorator_test.rb +26 -0
  32. data/{spec → test}/factories/fluentd.rb +0 -0
  33. data/{spec → test}/factories/plugins.rb +0 -0
  34. data/{spec → test}/factories/user.rb +0 -0
  35. data/{spec/support → test}/fixtures/error0.log +0 -0
  36. data/{spec/support → test}/fixtures/error2.log +0 -0
  37. data/{spec/support → test}/fixtures/error3.log +0 -0
  38. data/{spec/support → test}/fixtures/error4.log +0 -0
  39. data/{spec/support → test}/fixtures/multiline_example.log +0 -0
  40. data/test/integration/dashboard_test.rb +57 -0
  41. data/test/integration/fluentd/setting/histories_test.rb +139 -0
  42. data/test/integration/fluentd/setting/notes_test.rb +27 -0
  43. data/test/integration/fluentd/setting/running_backup_test.rb +65 -0
  44. data/test/integration/fluentd_ui_update_checking_test.rb +27 -0
  45. data/test/integration/sesstions_test.rb +56 -0
  46. data/test/integration/setting_test.rb +126 -0
  47. data/test/integration/users_test.rb +43 -0
  48. data/test/lib/filte_reverse_reader_test.rb +63 -0
  49. data/test/lib/fluentd_ui_test.rb +36 -0
  50. data/test/lib/regexp_preview/multi_line_test.rb +86 -0
  51. data/test/lib/regexp_preview/single_line_test.rb +87 -0
  52. data/test/models/fluent_gem_test.rb +76 -0
  53. data/test/models/fluentd/agent_test.rb +331 -0
  54. data/{spec/models/fluentd/setting/in_forward_spec.rb → test/models/fluentd/setting/in_forward_test.rb} +32 -44
  55. data/test/models/fluentd/setting/in_http_test.rb +30 -0
  56. data/test/models/fluentd/setting/in_monitor_agent_test.rb +30 -0
  57. data/test/models/fluentd/setting/in_syslog_test.rb +88 -0
  58. data/test/models/fluentd/setting/in_tail_test.rb +52 -0
  59. data/test/models/fluentd/setting/out_elasticsearch_test.rb +32 -0
  60. data/test/models/fluentd/setting/out_mongo_test.rb +61 -0
  61. data/test/models/fluentd/setting/out_s3_test.rb +112 -0
  62. data/test/models/fluentd/setting/out_stdout_test.rb +32 -0
  63. data/test/models/fluentd/setting/out_tdlog_test.rb +60 -0
  64. data/test/models/fluentd_log_test.rb +140 -0
  65. data/test/models/fluentd_test.rb +185 -0
  66. data/test/models/plugin_test.rb +144 -0
  67. data/test/models/user_test.rb +48 -0
  68. data/test/support/config_histories.rb +72 -0
  69. data/test/support/configurable_daemon_settings.rb +26 -0
  70. data/test/support/login_macro.rb +12 -0
  71. data/test/support/login_required.rb +8 -0
  72. data/test/support/stub_daemon.rb +14 -0
  73. data/test/system/fluentd/setting/in_forward_test.rb +13 -0
  74. data/test/system/fluentd/setting/in_http_test.rb +13 -0
  75. data/test/system/fluentd/setting/in_monitor_agent.rb +13 -0
  76. data/test/system/fluentd/setting/out_elasticsearch_test.rb +32 -0
  77. data/test/system/fluentd/setting/out_forward_test.rb +41 -0
  78. data/test/system/fluentd/setting/out_stdout_test.rb +15 -0
  79. data/test/system/fluentd/setting/out_tdlog_test.rb +15 -0
  80. data/test/system/source_and_output_test.rb +184 -0
  81. data/test/test_helper.rb +34 -0
  82. metadata +147 -161
  83. data/spec/controllers/application_controller_spec.rb +0 -84
  84. data/spec/controllers/fluentd/agents_controller_spec.rb +0 -61
  85. data/spec/controllers/misc_controller_spec.rb +0 -68
  86. data/spec/controllers/polling_controller_spec.rb +0 -39
  87. data/spec/controllers/sessions_controller_spec.rb +0 -5
  88. data/spec/decorators/plugin_decorator_spec.rb +0 -37
  89. data/spec/features/dashboard_spec.rb +0 -42
  90. data/spec/features/fluentd/setting/histories_spec.rb +0 -110
  91. data/spec/features/fluentd/setting/in_forward_spec.rb +0 -6
  92. data/spec/features/fluentd/setting/in_http_spec.rb +0 -6
  93. data/spec/features/fluentd/setting/in_monitor_agent_spec.rb +0 -6
  94. data/spec/features/fluentd/setting/notes_spec.rb +0 -27
  95. data/spec/features/fluentd/setting/out_forward_spec.rb +0 -38
  96. data/spec/features/fluentd/setting/out_stdout_spec.rb +0 -6
  97. data/spec/features/fluentd/setting/running_backup_spec.rb +0 -106
  98. data/spec/features/fluentd_status_spec.rb +0 -36
  99. data/spec/features/fluentd_ui_update_available_spec.rb +0 -33
  100. data/spec/features/out_elasticsearch_spec.rb +0 -28
  101. data/spec/features/out_forward_spec.rb +0 -36
  102. data/spec/features/out_tdlog_spec.rb +0 -26
  103. data/spec/features/sessions_spec.rb +0 -79
  104. data/spec/features/setting_spec.rb +0 -95
  105. data/spec/features/shared_examples/configurable_daemon_settings.rb +0 -17
  106. data/spec/features/shared_examples/login_required.rb +0 -4
  107. data/spec/features/source_and_output_spec.rb +0 -158
  108. data/spec/features/users_spec.rb +0 -53
  109. data/spec/grok_converter_spec.rb +0 -50
  110. data/spec/lib/file_reverse_reader_spec.rb +0 -93
  111. data/spec/lib/fluentd-ui_spec.rb +0 -35
  112. data/spec/lib/regexp_preview/multi_line_spec.rb +0 -111
  113. data/spec/lib/regexp_preview/single_line_spec.rb +0 -185
  114. data/spec/models/fluent_gem_spec.rb +0 -104
  115. data/spec/models/fluentd/agent/common_spec.rb +0 -82
  116. data/spec/models/fluentd/agent_spec.rb +0 -134
  117. data/spec/models/fluentd/setting/in_http_spec.rb +0 -31
  118. data/spec/models/fluentd/setting/in_monitor_agent_spec.rb +0 -31
  119. data/spec/models/fluentd/setting/in_syslog_spec.rb +0 -98
  120. data/spec/models/fluentd/setting/in_tail_spec.rb +0 -53
  121. data/spec/models/fluentd/setting/out_elasticsearch_spec.rb +0 -31
  122. data/spec/models/fluentd/setting/out_mongo_spec.rb +0 -62
  123. data/spec/models/fluentd/setting/out_s3_spec.rb +0 -128
  124. data/spec/models/fluentd/setting/out_stdout_spec.rb +0 -31
  125. data/spec/models/fluentd/setting/out_tdlog_spec.rb +0 -46
  126. data/spec/models/fluentd_log_spec.rb +0 -171
  127. data/spec/models/fluentd_spec.rb +0 -164
  128. data/spec/models/plugin_spec.rb +0 -191
  129. data/spec/models/user_spec.rb +0 -59
  130. data/spec/spec_helper.rb +0 -85
  131. data/spec/support/config_histories.rb +0 -57
  132. data/spec/support/fluentd_agent_common_behavior.rb +0 -181
  133. data/spec/support/fluentd_agent_restart_strategy.rb +0 -94
  134. data/spec/support/javascript_macro.rb +0 -21
  135. data/spec/support/login_macro.rb +0 -10
  136. data/spec/support/stub_daemon.rb +0 -12
@@ -0,0 +1,32 @@
1
+ require "test_helper"
2
+
3
+ require "fluent/plugin/buf_file"
4
+
5
+ module Fluentd::Setting
6
+ class OutStdoutTest < ActiveSupport::TestCase
7
+ setup do
8
+ @klass = Fluentd::Setting::OutStdout
9
+ @instance = @klass.new({})
10
+ end
11
+
12
+ test "#valid?" do
13
+ assert do
14
+ @instance.valid?
15
+ end
16
+ end
17
+
18
+ test "#plugin_name" do
19
+ assert_equal("stdout", @instance.plugin_name)
20
+ end
21
+
22
+ test "#plugin_type" do
23
+ assert_equal("output", @instance.plugin_type)
24
+ end
25
+
26
+ test "#to_config" do
27
+ assert do
28
+ @instance.to_config.to_s.include?("@type stdout")
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,60 @@
1
+ require "test_helper"
2
+ require "fluent/plugin/buf_file"
3
+
4
+ module Fluentd::Setting
5
+ class OutTdlogTest < ActiveSupport::TestCase
6
+ setup do
7
+ @klass = Fluentd::Setting::OutTdlog
8
+ @valid_attributes = {
9
+ pattern: "td.*.*",
10
+ apikey: "APIKEY",
11
+ auto_create_table: "true",
12
+ buffer: {
13
+ "0" => {
14
+ type: "file",
15
+ path: "/tmp/buffer"
16
+ }
17
+ }
18
+ }
19
+ @instance = @klass.new(@valid_attributes)
20
+ end
21
+
22
+ sub_test_case "#valid?" do
23
+ test "valid" do
24
+ assert do
25
+ @instance.valid?
26
+ end
27
+ end
28
+
29
+ test "invalid if apikey is missing" do
30
+ params = @valid_attributes.dup
31
+ params.delete(:apikey)
32
+ instance = @klass.new(params)
33
+ assert_false(instance.valid?)
34
+ assert_equal(["'apikey' parameter is required"], instance.errors.full_messages)
35
+ end
36
+ end
37
+
38
+ test "#plugin_name" do
39
+ assert_equal("tdlog", @instance.plugin_name)
40
+ end
41
+
42
+ test "#plugin_type" do
43
+ assert_equal("output", @instance.plugin_type)
44
+ end
45
+
46
+ test "#to_config" do
47
+ expected = <<-CONFIG.strip_heredoc
48
+ <match td.*.*>
49
+ @type tdlog
50
+ apikey APIKEY
51
+ <buffer>
52
+ @type file
53
+ path /tmp/buffer
54
+ </buffer>
55
+ </match>
56
+ CONFIG
57
+ assert_equal(expected, @instance.to_config.to_s)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,140 @@
1
+ require "test_helper"
2
+
3
+ class FluentdLogTest < ActiveSupport::TestCase
4
+ sub_test_case "#read" do
5
+ setup do
6
+ @logfile = Rails.root.join("tmp", "dummylog").to_s
7
+ @log = FluentdLog.new(@logfile)
8
+ end
9
+
10
+ test "compatible with utf-8" do
11
+ content = "utf8あいう\n"
12
+ File.write(@logfile, content)
13
+ assert_equal(content, @log.read)
14
+ end
15
+
16
+ test "incompatible with utf-8" do
17
+ content = "eucあいう\n".encode('euc-jp').force_encoding('ascii-8bit')
18
+ File.open(@logfile, "wb") {|file| file.write(content) }
19
+ assert_equal(content, @log.read)
20
+ end
21
+ end
22
+
23
+ sub_test_case "#tail" do
24
+ setup do
25
+ @logfile = Rails.root.join("tmp", "dummylog").to_s
26
+ @log = FluentdLog.new(@logfile)
27
+ File.open(@logfile, "wb") do |file|
28
+ 5.times do |n|
29
+ file.puts(n)
30
+ end
31
+ end
32
+ end
33
+
34
+ data("tail(5)" => [5, %w(4 3 2 1 0)],
35
+ "tail(3)" => [3, %w(4 3 2)],
36
+ "tail(99)" => [99, %w(4 3 2 1 0)])
37
+ test "5 line log" do |(limit, expected)|
38
+ assert_equal(@log.tail(limit), expected)
39
+ end
40
+ end
41
+
42
+ sub_test_case "#logged_errors" do
43
+ data("have 0 error log" => "error0.log",
44
+ "have error log" => "error2.log")
45
+ test "#last_error_message" do |path|
46
+ logfile = fixture_path(path)
47
+ log = FluentdLog.new(logfile)
48
+ if path == "error0.log"
49
+ assert do
50
+ log.last_error_message.empty?
51
+ end
52
+ else
53
+ assert_equal(log.last_error_message, log.recent_errors(1).first[:subject])
54
+ end
55
+ end
56
+
57
+ sub_test_case "#errors_since" do
58
+ setup do
59
+ @logged_time = Time.parse("2014-05-27")
60
+ @now = Time.parse("2014-05-29")
61
+ Timecop.freeze(@now)
62
+ end
63
+
64
+ teardown do
65
+ Timecop.return
66
+ end
67
+
68
+ test "have no errors" do
69
+ log = FluentdLog.new(fixture_path("error0.log"))
70
+ assert do
71
+ log.errors_since(100.days.ago).empty?
72
+ end
73
+ end
74
+
75
+ sub_test_case "have errors" do
76
+ setup do
77
+ @log = FluentdLog.new(fixture_path("error2.log"))
78
+ end
79
+
80
+ test "unreachable since" do
81
+ assert do
82
+ @log.errors_since(0.days.ago).empty?
83
+ end
84
+ end
85
+
86
+ test "reachable since" do
87
+ errors = @log.errors_since(100.days.ago)
88
+ assert_equal("unexpected error error_class=Errno::EADDRINUSE error=#<Errno::EADDRINUSE: Address already in use - bind(2) for \"0.0.0.0\" port 24224>",
89
+ errors[0][:subject].slice(/\[error\]: (.+)/, 1))
90
+ assert do
91
+ Time.parse(errors[0][:subject]) >= Time.parse(errors[1][:subject])
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ sub_test_case "recent_errors" do
98
+ test "have 0 error log" do
99
+ log = FluentdLog.new(fixture_path("error0.log"))
100
+ assert do
101
+ log.recent_errors(2).empty?
102
+ end
103
+ end
104
+
105
+ sub_test_case "have 2 error log" do
106
+ setup do
107
+ @log = FluentdLog.new(fixture_path("error2.log"))
108
+ end
109
+
110
+ data("limit=1" => 1,
111
+ "limit=2" => 2)
112
+ test "limit" do |limit|
113
+ assert_equal(limit, @log.recent_errors(limit).length)
114
+ end
115
+
116
+ test "contains stack trace" do
117
+ errors = @log.recent_errors(2)
118
+ assert_equal("unexpected error error_class=Errno::EADDRINUSE error=#<Errno::EADDRINUSE: Address already in use - bind(2) for \"0.0.0.0\" port 24224>",
119
+ errors[0][:subject].slice(/\[error\]: (.+)/, 1))
120
+ assert do
121
+ Time.parse(errors[0][:subject]) >= Time.parse(errors[1][:subject])
122
+ end
123
+ end
124
+ end
125
+
126
+ sub_test_case "have 3 errors including sequential 2 error log" do
127
+ test "count 3 errors" do
128
+ log = FluentdLog.new(fixture_path("error3.log"))
129
+ errors = log.recent_errors(3)
130
+ assert_equal(errors[0][:subject].slice(/::EADDRINUSE: (\d) Address already in use/, 1), "3")
131
+ assert_equal(errors[0][:notes].size, 1)
132
+ assert_equal(errors[1][:subject].slice(/::EADDRINUSE: (\d) Address already in use/, 1), "2")
133
+ assert_equal(errors[1][:notes].size, 2)
134
+ assert_equal(errors[2][:subject].slice(/::EADDRINUSE: (\d) Address already in use/, 1), "1")
135
+ assert_equal(errors[2][:notes].size, 0)
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,185 @@
1
+ require "test_helper"
2
+
3
+ class FluentdTest < ActiveSupport::TestCase
4
+ module PathPermission
5
+ def self.included(base)
6
+ base.class_eval do
7
+ setup do
8
+ setup_target
9
+ end
10
+
11
+ sub_test_case "file exists" do
12
+ setup do
13
+ FileUtils.touch(@path)
14
+ end
15
+
16
+ teardown do
17
+ FileUtils.rm_f(@path)
18
+ end
19
+
20
+ test "writable" do
21
+ FileUtils.chmod(0600, @path)
22
+ @fluentd.check_permission(@column)
23
+ assert do
24
+ @fluentd.errors.blank?
25
+ end
26
+ end
27
+
28
+ test "not writable" do
29
+ FileUtils.chmod(0400, @path)
30
+ @fluentd.check_permission(@column)
31
+ assert do
32
+ @fluentd.errors.present?
33
+ end
34
+ assert_equal(I18n.t('activerecord.errors.messages.lack_write_permission'), @fluentd.errors[@column].first)
35
+ end
36
+
37
+ test "not readable" do
38
+ FileUtils.chmod(0200, @path)
39
+ @fluentd.check_permission(@column)
40
+ assert do
41
+ @fluentd.errors.present?
42
+ end
43
+ assert_equal(I18n.t('activerecord.errors.messages.lack_read_permission'), @fluentd.errors[@column].first)
44
+ end
45
+
46
+ test "is directory" do
47
+ @fluentd.__send__("#{@column}=", Rails.root + "tmp")
48
+ @fluentd.check_permission(@column)
49
+ assert do
50
+ @fluentd.errors.present?
51
+ end
52
+ assert_equal(I18n.t('activerecord.errors.messages.is_a_directory'), @fluentd.errors[@column].first)
53
+ end
54
+ end
55
+
56
+ sub_test_case "file not exists" do
57
+ setup do
58
+ @dir = File.dirname(@path)
59
+ FileUtils.rm_f(@path)
60
+ end
61
+
62
+ teardown do
63
+ FileUtils.chmod_R(0755, @dir)
64
+ end
65
+
66
+ test "writable" do
67
+ FileUtils.chmod(0700, @dir)
68
+ @fluentd.check_permission(@column)
69
+ assert do
70
+ @fluentd.errors.blank?
71
+ end
72
+ end
73
+
74
+ test "not writable" do
75
+ FileUtils.chmod(0500, @dir)
76
+ @fluentd.check_permission(@column)
77
+ assert do
78
+ @fluentd.errors.present?
79
+ end
80
+ assert_equal(I18n.t('activerecord.errors.messages.lack_write_permission'), @fluentd.errors[@column].first)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ setup do
88
+ @fluentd = FactoryBot.build(:fluentd)
89
+ end
90
+
91
+ teardown do
92
+ File.unlink(Fluentd.json_path) if File.exist?(Fluentd.json_path)
93
+ end
94
+
95
+ sub_test_case "#valid?" do
96
+ setup do
97
+ %w(pid_file log_file config_file).each do |column|
98
+ FileUtils.mkdir_p(File.dirname(@fluentd.__send__(column)))
99
+ FileUtils.touch(@fluentd.__send__(column))
100
+ end
101
+ end
102
+
103
+ data("fluentd" => ["fluentd_gem", true],
104
+ "not declared in Fluentd.variants" => ["foobar", false])
105
+ test "variant" do |(variant, result)|
106
+ @fluentd.variant = variant
107
+ assert_equal(result, @fluentd.valid?)
108
+ end
109
+
110
+ sub_test_case "pid_file" do
111
+ def setup_target
112
+ @column = :pid_file
113
+ @path = @fluentd.pid_file
114
+ end
115
+ include PathPermission
116
+ end
117
+
118
+ sub_test_case "log_file" do
119
+ def setup_target
120
+ @column = :log_file
121
+ @path = @fluentd.log_file
122
+ end
123
+ include PathPermission
124
+ end
125
+
126
+ sub_test_case "config_file" do
127
+ def setup_target
128
+ @column = :config_file
129
+ @path = @fluentd.config_file
130
+ end
131
+ include PathPermission
132
+ end
133
+ end
134
+
135
+ data("fluentd_gem" => { variant: "fluentd_gem", fluentd_gem?: true },
136
+ "td-agent" => { variant: "td-agent", fluentd_gem?: false })
137
+ test "variant" do |data|
138
+ @fluentd.variant = data[:variant]
139
+ assert_equal(data[:fluentd_gem?], @fluentd.fluentd_gem?)
140
+ @fluentd.load_settings_from_agent_default
141
+ expected = {
142
+ pid_file: @fluentd.agent.class.default_options[:pid_file],
143
+ log_file: @fluentd.agent.class.default_options[:log_file],
144
+ config_file: @fluentd.agent.class.default_options[:config_file]
145
+ }
146
+ actual = {
147
+ pid_file: @fluentd.pid_file,
148
+ log_file: @fluentd.log_file,
149
+ config_file: @fluentd.config_file,
150
+ }
151
+ assert_equal(expected, actual)
152
+ end
153
+
154
+ data("fluentd_gem" => ["fluentd_gem", Fluentd::Agent::FluentdGem],
155
+ "td-agent" => ["td-agent", Fluentd::Agent::TdAgent])
156
+ test "#agent" do |(variant, klass)|
157
+ @fluentd.variant = variant
158
+ assert do
159
+ @fluentd.agent.instance_of?(klass)
160
+ end
161
+ end
162
+
163
+ sub_test_case "#ensure_default_config_file" do
164
+ setup do
165
+ @config_file = Rails.root + "tmp/test.conf"
166
+ @fluentd.config_file = @config_file
167
+ end
168
+
169
+ test "doesn't exist" do
170
+ File.unlink(@config_file) if File.exist?(@config_file)
171
+ @fluentd.save
172
+ assert do
173
+ File.exist?(@fluentd.config_file)
174
+ end
175
+ end
176
+
177
+ test "already exist" do
178
+ FileUtils.touch(@config_file)
179
+ @fluentd.save
180
+ assert do
181
+ File.exist?(@fluentd.config_file)
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,144 @@
1
+ require "test_helper"
2
+
3
+ class PluginTest < ActiveSupport::TestCase
4
+ setup do
5
+ @plugin = FactoryBot.build(:plugin)
6
+ end
7
+
8
+ sub_test_case ".installed" do
9
+ setup do
10
+ gem_list = <<-GEM_LIST.strip_heredoc
11
+ dummy (3.3.3)
12
+ fluent-plugin-foo (0.1.2)
13
+ more_dummy (0.0.1)
14
+ GEM_LIST
15
+ stub(FluentGem).gem { "gem" }
16
+ stub(FluentGem).__double_definition_create__.call(:`, "gem list 2>&1") { gem_list }
17
+ @target = Plugin.new(gem_name: "fluent-plugin-foo", version: "0.1.2")
18
+ end
19
+
20
+ test "detect foo plugin" do
21
+ assert_equal(@target.inspect, Plugin.installed.first.inspect)
22
+ end
23
+
24
+ test "detected foo plugin is marked as installed" do
25
+ assert do
26
+ @target.installed?
27
+ end
28
+ end
29
+
30
+ test "detected foo plugin version to be installed_version" do
31
+ assert_equal(@target.version, @target.installed_version)
32
+ end
33
+ end
34
+
35
+ sub_test_case "#valid?" do
36
+ data("nil is invalid" => [nil, false],
37
+ "something filled is valid" => ["foobar", true])
38
+ test "gem_name" do |(name, is_valid)|
39
+ @plugin.gem_name = name
40
+ assert_equal(is_valid, @plugin.valid?)
41
+ end
42
+
43
+ data("nil is invalid" => [nil, false],
44
+ "something filled is valid" => ["0.0.1", true])
45
+ test "version" do |(version, is_valid)|
46
+ @plugin.version = version
47
+ assert_equal(is_valid, @plugin.valid?)
48
+ end
49
+ end
50
+
51
+ sub_test_case "#install!" do
52
+ def install_plugin(is_valid, is_installed)
53
+ stub(@plugin).valid? { is_valid }
54
+ stub(@plugin).installed? { is_installed }
55
+ @plugin.install!
56
+ end
57
+
58
+
59
+ data("installed" => [true, 0],
60
+ "not installed" => [false, 1])
61
+ test "valid" do |(is_installed, n)|
62
+ mock(FluentGem).install(anything, "--no-ri", "--no-rdoc", "-v", anything).times(n) {}
63
+ install_plugin(true, is_installed)
64
+ end
65
+
66
+ data("installed" => [true, :install],
67
+ "not installed" => [false, :installed])
68
+ test "invalid" do |(is_installed, method)|
69
+ mock(FluentGem).__send__(method).times(0)
70
+ install_plugin(false, is_installed)
71
+ end
72
+
73
+ test "system command error" do
74
+ stub(FluentGem).gem { "gem" }
75
+ mock(FluentGem).system("gem", "install", "fluent-plugin-dummy", "--no-ri", "--no-rdoc", "-v", "1.2.3").at_least(1) { false }
76
+ assert_raise(FluentGem::GemError.new("failed command: `gem install fluent-plugin-dummy --no-ri --no-rdoc -v 1.2.3`")) do
77
+ @plugin.install!
78
+ end
79
+ end
80
+ end
81
+
82
+ data("installed" => [true, 1],
83
+ "uninstalled" => [false, 0])
84
+ test "#uninstall!" do |(is_installed, n)|
85
+ installed_plugin = FactoryBot.build(:plugin, gem_name: "fluent-plugin-foobar")
86
+ mock(installed_plugin).installed? { is_installed }
87
+ mock(installed_plugin).gem_uninstall.times(n) {}
88
+ installed_plugin.uninstall!
89
+ end
90
+
91
+ test "#upgrade!" do
92
+ installed_plugin = FactoryBot.build(:plugin, gem_name: "fluent-plugin-foobar", version: "1.0.0")
93
+ stub(installed_plugin).installed? { true }
94
+ stub(FluentGem).gem { "gem" }
95
+ stub(FluentGem).run("gem", "install", "fluent-plugin-foobar", "--no-ri", "--no-rdoc", "-v", "1.2.0") { true }
96
+ mock(installed_plugin).uninstall! {}
97
+ mock(FluentGem).install("fluent-plugin-foobar", "--no-ri", "--no-rdoc", "-v", "1.2.0") {}
98
+ installed_plugin.upgrade!("1.2.0")
99
+ end
100
+
101
+ test "#to_param" do
102
+ assert do
103
+ @plugin.to_param == @plugin.gem_name
104
+ end
105
+ end
106
+
107
+ sub_test_case "Gem version" do
108
+ setup do
109
+ @plugin = FactoryBot.build(:plugin, version: "1.0.0")
110
+ @versions = %w(1.0.1 0.99.1 1.0.0 0.99.0 0.1.0 0.0.3 0.0.2 0.0.1)
111
+ @authors = %w(foo bar)
112
+ json_response = @versions.map do |version|
113
+ {
114
+ number: version,
115
+ summary: "summary of #{version}",
116
+ authors: @authors
117
+ }
118
+ end.to_json
119
+ stub_request(:get, @plugin.gem_json_url).to_return(body: json_response)
120
+ end
121
+
122
+ test "latest version is 1.0.0" do
123
+ assert_equal("1.0.1", @plugin.latest_version)
124
+ end
125
+
126
+ test "1.0.0 is not lates" do
127
+ assert do
128
+ !@plugin.latest_version?
129
+ end
130
+ end
131
+
132
+ test "released_versions is sorted" do
133
+ assert_equal(@versions.sort_by{|ver| Gem::Version.new(ver) }.reverse, @plugin.released_versions)
134
+ end
135
+
136
+ test "authors" do
137
+ assert_equal(@authors, @plugin.authors)
138
+ end
139
+
140
+ test "summary" do
141
+ assert_equal("summary of #{@plugin.version}", @plugin.summary)
142
+ end
143
+ end
144
+ end