class IndexTestCase

Public Instance Methods

setup() click to toggle source
Calls superclass method TestCaseWithSplunkConnection#setup
# File test/test_index.rb, line 7
def setup
  super

  @index_name = temporary_name()
  @index = @service.indexes.create(@index_name)
  assert_eventually_true() do
    @index.refresh()["disabled"] == "0"
  end
end
teardown() click to toggle source
Calls superclass method TestCaseWithSplunkConnection#teardown
# File test/test_index.rb, line 17
def teardown
  if @service.splunk_version[0] >= 5
    @service.indexes.
        select() { |index| index.name.start_with?("delete-me")}.
        each() do |index|
      if index.fetch("disabled") == "1"
        index.enable()
      end
      index.delete()
    end
  end

  super
end
test_delete() click to toggle source
# File test/test_index.rb, line 32
def test_delete
  if @service.splunk_version[0] < 5
    return
  end
  assert_true(@service.indexes.has_key?(@index_name))
  @service.indexes.delete(@index_name)
  assert_eventually_true() do
    !@service.indexes.has_key?(@index_name)
  end
end
test_disable_enable() click to toggle source
# File test/test_index.rb, line 43
def test_disable_enable
  @index.disable()
  if @service.splunk_version[0] < 6
    checked_restart(@service)
  end
  @index.refresh()
  assert_equal('1', @index["disabled"])

  @index.enable()
  @index.refresh()
  assert_equal("0", @index["disabled"])
end
test_submit_and_clean() click to toggle source
# File test/test_index.rb, line 66
def test_submit_and_clean
  original_count = Integer(@index.refresh()["totalEventCount"])
  @index.submit("Boris 1", :sourcetype => "Boris", :host => "Meep")
  @index.submit("Boris 2", :sourcetype => "Boris", :host => "Meep")
  assert_eventually_true(100) do
    Integer(@index.refresh()["totalEventCount"]) == original_count + 2
  end

  @index.clean(timeout=500)
  assert_equal(0, Integer(@index.refresh()["totalEventCount"]))
end
test_submit_via_attach() click to toggle source
# File test/test_index.rb, line 56
def test_submit_via_attach
  event_count = Integer(@index["totalEventCount"])
  socket = @index.attach()
  socket.write("Hello, Boris!\r\n")
  socket.close()
  assert_eventually_true(10) do
    Integer(@index.refresh()["totalEventCount"]) == event_count+1
  end
end
test_upload() click to toggle source
# File test/test_index.rb, line 78
def test_upload
  if not has_test_data?(@service)
      fail("Install the SDK test data to test uploads.")
  end

  install_app_from_collection("file_to_upload")

  original_count = Integer(@index.refresh().fetch("totalEventCount"))
  @index.upload(path_in_app("file_to_upload", ["log.txt"]))

  assert_eventually_true() do
    Integer(@index.refresh()["totalEventCount"]) == original_count + 4
  end
end