Sha256: 1377660eeaaf3323ef4ebcfdffd1cdfdd0f2aab744e377900f3f3e1c825bd8f2

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 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_false
  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_false
  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_false
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zabbix-ruby-client-0.0.20 spec/lib/plugin_base_spec.rb
zabbix-ruby-client-0.0.19 spec/lib/plugin_base_spec.rb
zabbix-ruby-client-0.0.18 spec/lib/plugin_base_spec.rb