test/test/cluster/unit/cluster_test.rb in elasticsearch-extensions-0.0.23 vs test/test/cluster/unit/cluster_test.rb in elasticsearch-extensions-0.0.24
- old
+ new
@@ -100,10 +100,17 @@
FileUtils.expects(:rm_rf).with("/tmp/elasticsearch_test")
@subject.__remove_cluster_data
end
+ should "not log when :quiet" do
+ c = Cluster::Cluster.new quiet: true
+
+ STDERR.expects(:puts).never
+ c.__log 'QUIET'
+ end
+
context "when starting a cluster, " do
should "return false when it's already running" do
Process.expects(:spawn).never
c = Cluster::Cluster.new
@@ -125,11 +132,11 @@
c.expects(:__remove_cluster_data).returns(true)
c.expects(:wait_for_green).returns(true)
c.expects(:__check_for_running_processes).returns(true)
c.expects(:__determine_version).returns('5.0')
- c.expects(:__print_cluster_info).returns(true)
+ c.expects(:__cluster_info).returns('CLUSTER INFO')
assert_equal true, c.start
end
end
@@ -196,12 +203,10 @@
cluster_name: 'test',
number_of_nodes: 1
end
should "return true" do
- @subject.stubs(:__print_cluster_info)
-
@subject
.expects(:__get_cluster_health)
.with('yellow')
.returns({'status' => 'yellow', 'cluster_name' => 'test', 'number_of_nodes' => 1})
@@ -252,10 +257,11 @@
assert_equal '2.0', @subject.__determine_version
end
should "return version from `elasticsearch --version`" do
File.expects(:exist?).with('/foo/bar/bin/../lib/').returns(false)
+ File.expects(:exist?).with('/foo/bar/bin/elasticsearch').returns(true)
Process.stubs(:wait)
Process.expects(:spawn)
.with do |command, options|
assert_equal "/foo/bar/bin/elasticsearch --version", command
@@ -268,19 +274,20 @@
assert_equal '2.0', @subject.__determine_version
end
should "raise an exception when the version cannot be parsed from .jar" do
- # Incorrect jar version
+ # Incorrect jar version (no dots)
File.expects(:exist?).with('/foo/bar/bin/../lib/').returns(true)
Dir.expects(:entries).with('/foo/bar/bin/../lib/').returns(['elasticsearch-100.jar'])
assert_raise(RuntimeError) { @subject.__determine_version }
end
should "raise an exception when the version cannot be parsed from command output" do
File.expects(:exist?).with('/foo/bar/bin/../lib/').returns(false)
+ File.expects(:exist?).with('/foo/bar/bin/elasticsearch').returns(true)
Process.stubs(:wait)
Process.expects(:spawn)
.with do |command, options|
assert_equal "/foo/bar/bin/elasticsearch --version", command
@@ -297,9 +304,19 @@
# There's no Elasticsearch version 3...
File.expects(:exist?).with('/foo/bar/bin/../lib/').returns(true)
Dir.expects(:entries).with('/foo/bar/bin/../lib/').returns(['elasticsearch-3.2.1.jar'])
assert_raise(RuntimeError) { @subject.__determine_version }
+ end
+
+ should "raise an exception when the command cannot be found" do
+ @subject = Elasticsearch::Extensions::Test::Cluster::Cluster.new
+
+ File.expects(:exist?).with('./../lib/').returns(false)
+ File.expects(:exist?).with('elasticsearch').returns(false)
+ @subject.expects(:`).returns('')
+
+ assert_raise(Errno::ENOENT) { @subject.__determine_version }
end
end
end
end