Bake Test IntegrationSourceBakeTestIntegrationController

class Controller

Runs Docker Compose integration test scenarios.

Definitions

def initialize(root = Dir.pwd, command: DEFAULT_COMMAND, runner: Kernel.method(:system))

Initialize a controller for the given project root.

Signature

parameter root String | Pathname

The project root.

parameter command Array(String)

The Docker Compose command.

parameter runner Interface(:call)

The command runner.

Implementation

def initialize(root = Dir.pwd, command: DEFAULT_COMMAND, runner: Kernel.method(:system))
	@root = Pathname.new(root)
	@command = command
	@runner = runner
end

def scenarios(path: "integration")

Enumerate integration test scenario directories in deterministic order.

Signature

parameter path String

The directory containing integration test scenarios.

returns Array(Pathname)

The discovered scenario directories.

Implementation

def scenarios(path: "integration")
	@root.join(path).glob("*/#{COMPOSE_FILE}").sort.map(&:dirname)
end

def run(name: nil, path: "integration", service: "tests", build: true)

Run one or all integration test scenarios.

Signature

parameter name String | Nil

The scenario name, or all scenarios when omitted.

parameter path String

The directory containing integration test scenarios.

parameter service String

The service whose exit status determines the result.

parameter build Boolean

Whether Compose should build images before running tests.

raises ArgumentError

If no matching scenarios exist.

Implementation

def run(name: nil, path: "integration", service: "tests", build: true)
	scenarios = self.scenarios(path: path)
	
	if name
		scenarios.select!{|scenario| scenario.basename.to_s == name.to_s}
	end
	
	if scenarios.empty?
		raise ArgumentError, "No integration test scenarios found#{" for #{name.inspect}" if name}!"
	end
	
	scenarios.each do |scenario|
		run_scenario(scenario, service: service, build: build)
	end
end