require 'json'
require 'uri'
require 'prof/ssh_gateway'

require "support/integration_helpers"

describe "LogSearch deployment" do
  let(:bosh_target) { URI.parse(ENV["BOSH_TARGET"]).hostname }
  let(:ssh_key_file) { ENV["BOSH_INSTANCE_SSH_KEY"] }
  let(:deployment) { Deployment.load_file(ENV["BOSH_MANIFEST"]) }
  let(:log) { TestLog.new }
  let(:gateway) do
    Prof::SshGateway.new(
      gateway_host: bosh_target,
      gateway_username: 'vcap',
      ssh_key: File.read(ssh_key_file)
    )
  end

  it "ingests logs" do
    gateway.execute_on(deployment.ingestor_ip, "echo '#{log.line}' | nc localhost 5514")

    sleep 60

    index = "logstash-#{log.time.day}"
    uri = URI("http://localhost:9200/#{index}/_search?q=#{log.data}")
    output = gateway.execute_on(deployment.master_ip, "curl -s #{uri}")
    response = JSON.parse(output)
    expect(JSON.parse(response["hits"]["hits"].first["@message"])["testvalue"]).to eq log.data
  end
end


require 'json'
require 'uri'
require 'prof/ssh_gateway'

require "support/integration_helpers"

describe "LogSearch deployment" do
  let(:bosh_target) { URI.parse(ENV["BOSH_TARGET"]).hostname }
  let(:ssh_key_file) { ENV["BOSH_INSTANCE_SSH_KEY"] }
  let(:deployment) { Deployment.load_file(ENV["BOSH_MANIFEST"]) }
  let(:log) { TestLog.new }
  let(:gateway) do
    Prof::SshGateway.new(
      gateway_host: bosh_target,
      gateway_username: 'vcap',
      ssh_key: File.read(ssh_key_file)
    )
  end

  it "ingests logs" do
    gateway.execute_on(deployment.ingestor_ip, "echo '#{log.line}' | nc localhost 5514")

    sleep 60

    index = "logstash-#{log.time.day}"
    uri = URI("http://localhost:9200/#{index}/_search?q=#{log.data}")
    output = gateway.execute_on(deployment.master_ip, "curl -s #{uri}")
    response = JSON.parse(output)
    expect(JSON.parse(response["hits"]["hits"].first["_source"]["@message"])["testvalue"]).to eq log.data
  end
end


Fix bug in test when accessing @message field
Fix bug in test when accessing @message field

[#116514499]

Signed-off-by: Derik Evangelista <70505a31063ee00d819d9d243caf579a659cbb4f@pivotal.io>
