Sha256: 10a05942bbd947d74dad3c5d7b52eb1a59a3b73a795e489be2e36f3508545000

Contents?: true

Size: 1.87 KB

Versions: 7

Compression:

Stored size: 1.87 KB

Contents

# encoding: utf-8

require 'spec_helper'
require "zabbix-ruby-client/logger"
require "zabbix-ruby-client/plugin_base"

describe ZabbixRubyClient::PluginBase do

  before :all do
    @logfile = File.expand_path("../files/logs/spec.log", __FILE__)
    ZabbixRubyClient::Log.set_logger(@logfile)
    @stubfile = File.expand_path('../../../spec/files/system/net_dev', __FILE__)
    @expected_line = "eth0: 8523363858 17554648    0    0    0     0          0    589997 2479556217 15780062    0    0    0     0       0          0"
  end

  after :all do
    FileUtils.rm_rf @logfile if File.exists? @logfile
  end

  after :each do
    FileUtils.rm "/tmp/xxxxx" if File.exists? "/tmp/xxxxx"
  end

  it "extracts a line from a file" do
    line = ZabbixRubyClient::PluginBase.getline(@stubfile, "eth0: ")
    expect(line).to eq @expected_line
  end

  it "logs a debug entry when it extracts a line from a file" do
    expect(ZabbixRubyClient::Log).to receive(:debug).with("File #{@stubfile}: #{@expected_line}")
    ZabbixRubyClient::PluginBase.getline(@stubfile, "eth0: ")
  end

  it "logs a warn entry when a line is not found in a file" do
    expect(ZabbixRubyClient::Log).to receive(:warn).with("File #{@stubfile}: pattern \" xxx \" not found.")
    x = ZabbixRubyClient::PluginBase.getline(@stubfile, " xxx ")
    expect(x).to be_falsey
  end

  it "logs an error entry when a file is not found" do
    expect(ZabbixRubyClient::Log).to receive(:error).with("File not found: /tmp/xxxxx")
    x = ZabbixRubyClient::PluginBase.getline("/tmp/xxxxx", " xxx ")
    expect(x).to be_falsey
  end

  it "logs an error entry when a file is not readable" do
    FileUtils.touch "/tmp/xxxxx"
    FileUtils.chmod 0300, "/tmp/xxxxx"
    expect(ZabbixRubyClient::Log).to receive(:error).with("File not readable: /tmp/xxxxx")
    x = ZabbixRubyClient::PluginBase.getline("/tmp/xxxxx", " xxx ")
    expect(x).to be_falsey
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
zabbix-ruby-client-0.1.3 spec/lib/plugin_base_spec.rb
zabbix-ruby-client-0.1.2 spec/lib/plugin_base_spec.rb
zabbix-ruby-client-0.1.1 spec/lib/plugin_base_spec.rb
zabbix-ruby-client-0.1.0 spec/lib/plugin_base_spec.rb
zabbix-ruby-client-0.0.23 spec/lib/plugin_base_spec.rb
zabbix-ruby-client-0.0.22 spec/lib/plugin_base_spec.rb
zabbix-ruby-client-0.0.21 spec/lib/plugin_base_spec.rb