Sha256: c9a14dd9975a8b898cc6485490f81c638d86483c44e61cc90f77256cf43a3f2d

Contents?: true

Size: 1.37 KB

Versions: 6

Compression:

Stored size: 1.37 KB

Contents

# encoding: utf-8

require 'spec_helper'
require "zabbix-ruby-client/plugins"
ZabbixRubyClient::Plugins.scan_dirs ["zabbix-ruby-client/plugins"]
require "zabbix-ruby-client/plugins/load"

describe ZabbixRubyClient::Plugins::Load do

  before :all do
    @logfile = File.expand_path("../../files/logs/spec.log", __FILE__)
    ZabbixRubyClient::Log.set_logger(@logfile)
  end

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

  it "prepare data to be usable" do
    expected = ["0.89", "1.29", "1.05", "2", "2768"]
    stubfile = File.expand_path('../../../../spec/files/system/loadavg', __FILE__)
    allow(ZabbixRubyClient::Plugins::Load).to receive(:getline).and_return(File.read(stubfile).strip)
    data = ZabbixRubyClient::Plugins::Load.send(:get_info)
    expect(data).to eq expected
  end

  it "populate a hash with extracted data" do
    expected = [
      "local load[one] 123456789 0.89",
      "local load[five] 123456789 1.29",
      "local load[fifteen] 123456789 1.05",
      "local load[procs] 123456789 2"
    ]
    stubfile = File.expand_path('../../../../spec/files/system/loadavg', __FILE__)
    allow(ZabbixRubyClient::Plugins::Load).to receive(:getline).and_return(File.read(stubfile))
    allow(Time).to receive(:now).and_return("123456789")
    data = ZabbixRubyClient::Plugins::Load.send(:collect, 'local')
    expect(data).to eq expected
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

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