Sha256: c9f175b6d3bd6002dcd59d45b15896d60f9c0c8d446c76b14b0bfa38e6658c2b

Contents?: true

Size: 1.59 KB

Versions: 34

Compression:

Stored size: 1.59 KB

Contents

module Beaker
  class Result
    attr_accessor :host, :cmd, :exit_code, :stdout, :stderr, :output,
                  :raw_stdout, :raw_stderr, :raw_output
    def initialize(host, cmd)
      @host       = host
      @cmd        = cmd
      @stdout     = ''
      @stderr     = ''
      @output     = ''
      @exit_code  = nil
    end

    # Ruby assumes chunked data (like something it receives from Net::SSH)
    # to be binary (ASCII-8BIT). We need to gather all chunked data and then
    # re-encode it as the default encoding it assumes for external text
    # (ie our test files and the strings they're trying to match Net::SSH's
    # output from)
    # This is also the lowest overhead place to normalize line endings, IIRC
    def finalize!
      @raw_stdout = @stdout
      @stdout     = normalize_line_endings( convert( @stdout ) )
      @raw_stderr = @stderr
      @stderr     = normalize_line_endings( convert( @stderr ) )
      @raw_output = @output
      @output     = normalize_line_endings( convert( @output ) )
    end

    def normalize_line_endings string
      return string.gsub(/\r\n?/, "\n")
    end

    def convert string
      # Remove invalid and undefined UTF-8 character encodings
      string.to_s.force_encoding('UTF-8')
      string.to_s.chars.select{|i| i.valid_encoding?}.join
    end

    def log(logger)
      logger.debug "Exited: #{exit_code}" unless exit_code == 0 or !exit_code
    end

    def formatted_output(limit=10)
      @output.split("\n").last(limit).collect {|x| "\t" + x}.join("\n")
    end

    def exit_code_in?(range)
      range.include?(@exit_code)
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
beaker-2.18.2 lib/beaker/result.rb
beaker-2.18.1 lib/beaker/result.rb
beaker-2.18.0 lib/beaker/result.rb
beaker-2.17.0 lib/beaker/result.rb
beaker-2.16.0 lib/beaker/result.rb
beaker-2.15.1 lib/beaker/result.rb
beaker-2.15.0 lib/beaker/result.rb
beaker-2.14.1 lib/beaker/result.rb
beaker-2.14.0 lib/beaker/result.rb
beaker-2.13.0 lib/beaker/result.rb
beaker-2.12.0 lib/beaker/result.rb
beaker-2.11.0 lib/beaker/result.rb
beaker-2.10.0 lib/beaker/result.rb
beaker-2.9.0 lib/beaker/result.rb