Module: Dockerspec::Runner::ConfigHelpers

Included in:
Dockerspec::RSpec::Resources::ItsContainer, Base
Defined in:
lib/dockerspec/runner/config_helpers.rb

Overview

Some helpers to get information from a running container.

Instance Method Summary collapse

Instance Method Details

#parse_log(log) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse the stdout/stderr log binary stream.

Examples:

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

Parameters:

  • log (String)

    log to parse in binary format.

Returns:

  • (String)

    parsed log.



38
39
40
# File 'lib/dockerspec/runner/config_helpers.rb', line 38

def parse_log(log)
  log.sub(/^.*?\a/, '')
end

#stderrString

Returns the container stderr logs.

Examples:

Docker Run Example

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

Docker Compose Example

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

Returns:

  • (String)

    The stderr logs.

Raises:



91
92
93
94
# File 'lib/dockerspec/runner/config_helpers.rb', line 91

def stderr
  log = container.logs(stderr: true).to_s
  parse_log(log)
end

#stdoutString

Returns the container stdout logs.

Examples:

Docker Run Example

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

Docker Compose Example

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

Returns:

  • (String)

    The stdout logs.

Raises:



64
65
66
67
# File 'lib/dockerspec/runner/config_helpers.rb', line 64

def stdout
  log = container.logs(stdout: true)
  parse_log(log)
end