Sha256: 394980b0cfa3f80e09270fb78658ace36352031831a7cadf310319234eb4196c

Contents?: true

Size: 1.56 KB

Versions: 9

Compression:

Stored size: 1.56 KB

Contents

require 'csv'
require 'yaml'
require_relative '../test_helper'
require_relative '../../../lib/inspec_tools/csv'

class SummaryTest < Minitest::Test
  def test_that_summary_exists
    refute_nil ::InspecTools::Summary
  end

  def test_summary_init_with_valid_params
    inspec_json = File.read('examples/sample_json/rhel-simp.json')
    assert(InspecTools::Summary.new(inspec_json))
  end

  def test_summary_init_with_invalid_params
    json = nil
    assert_raises(StandardError) { InspecTools::Summary.new(json) }
  end

  def test_inspec_to_summary
    inspec_json = File.read('examples/sample_json/rhel-simp.json')
    inspec_tools = InspecTools::Summary.new(inspec_json)
    summary = inspec_tools.to_summary
    assert_equal(77.3, summary[:compliance])
    assert_equal(33, summary[:status][:failed][:medium])
  end

  def test_inspec_results_compliance_pass
    inspec_json = File.read('examples/sample_json/rhel-simp.json')
    threshold = YAML.safe_load('{compliance.min: 77, failed.critical.max: 0, failed.high.max: 3}')
    inspec_tools = InspecTools::Summary.new(inspec_json)
    assert_output(/Compliance threshold met/) { inspec_tools.threshold(threshold) }
  end

  def test_inspec_results_compliance_fail
    inspec_json = File.read('examples/sample_json/rhel-simp.json')
    threshold = YAML.safe_load('{compliance.min: 80, failed.critical.max: 0, failed.high.max: 0}')
    inspec_tools = InspecTools::Summary.new(inspec_json)
    assert_output(%r{Expected compliance.min:80 got:77.3(\r\n|\r|\n)Expected failed.high.max:0 got:3}) { inspec_tools.threshold(threshold) }
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
inspec_tools-1.4.2 test/unit/inspec_tools/summary_test.rb
inspec_tools-1.4.1 test/unit/inspec_tools/summary_test.rb
inspec_tools-1.4.0 test/unit/inspec_tools/summary_test.rb
inspec_tools-1.3.6 test/unit/inspec_tools/summary_test.rb
inspec_tools-1.3.5 test/unit/inspec_tools/summary_test.rb
inspec_tools-1.3.0 test/unit/inspec_tools/summary_test.rb
inspec_tools-1.2.2 test/unit/inspec_tools/summary_test.rb
inspec_tools-1.2.1 test/unit/inspec_tools/summary_test.rb
inspec_tools-1.2.0 test/unit/inspec_tools/summary_test.rb