module Dockerspec::Runner::ConfigHelpers

Some helpers to get information from a running container.

Public Instance Methods

parse_log(log) click to toggle source

Parse the stdout/stderr log binary stream.

@example

parse_log("String1") #=> "String1"
parse_log("\x02\x00\x00\x00\x00\x00\x00\aSTDERR") #=> "STDERR"

@param log [String] log to parse in binary format. @return [String] parsed log.

@api private

# File lib/dockerspec/runner/config_helpers.rb, line 38
def parse_log(log)
  log.sub(/^.*?\a/, '')
end
stderr() click to toggle source

Returns the container stderr logs.

@example Docker Run Example

describe docker_run('mysql') do
  its(:stderr) { should include 'mysqld: ready for connections.' }
end

@example Docker Compose Example

describe docker_compose('.', wait: 30) do
  describe its_container(:myapp) do
    its(:stderr) { should eq '' }
  end
end

@return [String] The stderr logs.

@raise [Dockerspec::RunnerError] When cannot select the container to

test.

@api public

# File lib/dockerspec/runner/config_helpers.rb, line 91
def stderr
  log = container.logs(stderr: true).to_s
  parse_log(log)
end
stdout() click to toggle source

Returns the container stdout logs.

@example Docker Run Example

describe docker_run('mysql') do
  its(:stdout) { should include 'MySQL init process done.' }
end

@example Docker Compose Example

describe docker_compose('.', wait: 30) do
  describe its_container(:db) do
    its(:stdout) { should include 'MySQL init process done.' }
  end
end

@return [String] The stdout logs.

@raise [Dockerspec::RunnerError] When cannot select the container to

test.

@api public

# File lib/dockerspec/runner/config_helpers.rb, line 64
def stdout
  log = container.logs(stdout: true)
  parse_log(log)
end