Chef DevOps Chef DevOps Testing & Quality Assurance 2 — Questions and Answers
Question 1: In ChefSpec, which call creates a simulated Chef run for unit testing?
- chef_run.apply
- ChefSpec::Runner.run
- ChefSpec::SoloRunner.converge (Correct answer)
- chef_simulate.start
Correct answer: ChefSpec::SoloRunner.converge
ChefSpec::SoloRunner.converge creates a simulated in-memory Chef run for unit testing without actually applying changes to a node.
Question 2: What does the `kitchen converge` command do to the test instance?
- Verifies test assertions only
- Applies the cookbook's recipes to the test instance (Correct answer)
- Creates the test instance only
- Destroys the test instance
Correct answer: Applies the cookbook's recipes to the test instance
The `kitchen converge` command applies the cookbook's recipes to the already-created test instance, bringing it to the desired state.
Question 3: Which InSpec resource would you use to assert that a system service is running?
- package
- file
- service (Correct answer)
- port
Correct answer: service
The InSpec `service` resource tests whether a system service is installed, enabled, and currently running.
Question 4: What is the purpose of `kitchen verify` in the Test Kitchen lifecycle?
- Apply cookbook recipes to the instance
- Run InSpec or Serverspec tests against the converged instance (Correct answer)
- Create the virtual machine
- Upload the cookbook to Chef Server
Correct answer: Run InSpec or Serverspec tests against the converged instance
`kitchen verify` executes the defined test suite (InSpec, Serverspec, etc.) against a converged Test Kitchen instance to assert the desired state was achieved.
Question 5: In ChefSpec, which RSpec-style matcher asserts that a package would be installed during a Chef run?
- have_resource(:package)
- install_package('name')
- to install_package('name') (Correct answer)
- be_installed('name')
Correct answer: to install_package('name')
The ChefSpec matcher `to install_package('name')` uses RSpec expect syntax to assert the Chef run would install the specified package.
Question 6: What is the default Test Kitchen driver used for local cookbook testing?
- Vagrant (Correct answer)
- Docker
- AWS EC2
- Hyper-V
Correct answer: Vagrant
Vagrant is Test Kitchen's default driver, using virtual machines (typically with VirtualBox) to create isolated local test instances.
In ChefSpec, which call creates a simulated Chef run for unit testing?