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
rootString | Pathname The project root.
-
parameter
commandArray(String) The Docker Compose command.
-
parameter
runnerInterface(: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
pathString 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
nameString | Nil The scenario name, or all scenarios when omitted.
-
parameter
pathString The directory containing integration test scenarios.
-
parameter
serviceString The service whose exit status determines the result.
-
parameter
buildBoolean 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