Skip to content

test: cover the driver, transport, and container logic that had none - #497

Open
tas50 wants to merge 1 commit into
mainfrom
test/cover-driver-transport-logic
Open

test: cover the driver, transport, and container logic that had none#497
tas50 wants to merge 1 commit into
mainfrom
test/cover-driver-transport-logic

Conversation

@tas50

@tas50 tas50 commented Aug 30, 2026

Copy link
Copy Markdown
Member

Line coverage of lib/ was 85.3%, and the gaps were not obscure corners.

What was untested

Area Why it matters
Driver#default_image, #default_platform This is what makes "a platform name and nothing else" work, which is the first thing the README promises. Nothing asserted that ubuntu-24.04 becomes ubuntu:24.04, or that centos-7 becomes centos:centos7.
The driver's lazy default_config blocks image, platform, username, run_command, build_context, instance_name, package_name, socket.
Container#hostname Three branches — local, remote socket, internal network — all of which produce something that looks like a host, so getting it wrong fails later as a connection timeout rather than here.
Container#upload, Container::Linux#create create populates the state the transport and verifier read; a key missing from it surfaces as a nil far from the cause.
Every public method on the transport #connection, Connection#execute, #upload, #container, and the temp_dir / username / socket defaults.
Driver#create, #destroy, #container, #wait_for_transport, #verify_dependencies

A spec that was testing itself

describe "socket default config logic" re-implemented the driver's default_config :socket block inside the spec file and asserted on its own copy:

def resolve_socket
  socket = "unix:///var/run/docker.sock"
  socket = "npipe:////./pipe/docker_engine" if Gem.win_platform?
  ENV["DOCKER_HOST"] || socket
end

That passes with the driver's block deleted. It now reads the value back off a driver, which is what Test Kitchen does.

Result

lib/kitchen/docker/container.rb              71.8% -> 100.0%
lib/kitchen/docker/container/linux.rb        88.8% -> 100.0%
lib/kitchen/driver/docker.rb                 78.8% -> 100.0%
lib/kitchen/transport/docker.rb              72.0% -> 100.0%
TOTAL                                        85.3% ->  94.5%

(measured with SimpleCov, which is not added to the Gemfile — it was only used to find the gaps)

The remaining gaps are Container::Windows#execute and three ContainerHelper methods, which #496 covers, and the InSpec verifier patches, which only run when kitchen-inspec is in the bundle — CI unit tests run with BUNDLE_WITHOUT=development, so they are not loaded there.

No production code is changed.

Verification

$ bundle exec rake test
416 examples, 0 failures

$ cookstyle --chefstyle          # Cookstyle 9.0.0 / RuboCop 1.90.0
44 files inspected, no offenses detected

Line coverage of lib/ was 85%, and the gaps were not obscure corners:
the driver's lazy `default_config` blocks, `default_image`,
`default_platform`, `Container#hostname`, `Container#upload`,
`Container::Linux#create`, and every public method on the transport
were untested.

`default_image` and `default_platform` are what makes "a platform name
and nothing else" work, which is the first thing the README promises,
and nothing asserted that `ubuntu-24.04` becomes `ubuntu:24.04`.

The socket default had a spec, but it re-implemented the block inside
the spec file and asserted on its own copy, so it would have passed with
the driver's block deleted. It now reads the value back off a driver,
which is what Test Kitchen does.

Coverage of lib/ goes from 85.3% to 94.5%; the driver, the transport,
the container base class, and the Linux container are now fully covered.

Signed-off-by: Tim Smith <tim@mondoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant