Sha256: 8519d5866025c25a34f38742ffe5480979e812e9383637c1059efd66f3d9ee7c

Contents?: true

Size: 1.76 KB

Versions: 5

Compression:

Stored size: 1.76 KB

Contents

require "test_utils"
require "logstash/filters/translate"

describe LogStash::Filters::Translate do
  extend LogStash::RSpec

  describe "exact translation" do
    config <<-CONFIG
      filter {
        translate {
          field       => "status"
          destination => "translation"
          dictionary  => [ "200", "OK",
                           "300", "Redirect",
                           "400", "Client Error",
                           "500", "Server Error" ]
          exact       => true
          regex       => false
        }
      }
    CONFIG

    sample("status" => 200) do
      insist { subject["translation"] } == "OK"
    end
  end

  describe "multi translation" do
    config <<-CONFIG
      filter {
        translate {
          field       => "status"
          destination => "translation"
          dictionary  => [ "200", "OK",
                           "300", "Redirect",
                           "400", "Client Error",
                          "500", "Server Error" ]
          exact       => false
          regex       => false
        }
      }
    CONFIG

    sample("status" => "200 & 500") do
      insist { subject["translation"] } == "OK & Server Error"
    end
  end

  describe "regex translation" do
    config <<-CONFIG
      filter {
        translate {
          field       => "status"
          destination => "translation"
          dictionary  => [ "^2[0-9][0-9]$", "OK",
                           "^3[0-9][0-9]$", "Redirect",
                           "^4[0-9][0-9]$", "Client Error",
                           "^5[0-9][0-9]$", "Server Error" ]
          exact       => true
          regex       => true
        }
      }
    CONFIG

    sample("status" => "200") do
      insist { subject["translation"] } == "OK"
    end
  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
logstash-filter-translate-0.1.4 spec/filters/translate.rb
logstash-filter-translate-0.1.3 spec/filters/translate.rb
logstash-filter-translate-0.1.2 spec/filters/translate.rb
logstash-filter-translate-0.1.1 spec/filters/translate.rb
logstash-lib-1.3.2 spec/filters/translate.rb