Skip to content

Commit b3758cd

Browse files
100% test coverage. (#353)
1 parent be44812 commit b3758cd

29 files changed

Lines changed: 998 additions & 13 deletions

bin/falcon

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,4 @@
2323

2424
require_relative "../lib/falcon/command"
2525

26-
begin
27-
Falcon::Command.call
28-
rescue Interrupt
29-
# Ignore.
30-
rescue => error
31-
Console.error(Falcon::Command, error)
32-
exit! 1
33-
end
26+
Falcon::Command.call

bin/falcon-host

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,4 @@
2323

2424
require_relative "../lib/falcon/command/host"
2525

26-
begin
27-
Falcon::Command::Host.call
28-
rescue Interrupt
29-
end
26+
Falcon::Command::Host.call

config/covered.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
def ignore_paths
4+
super + ["examples/"]
5+
end

gems.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
gem "sus-fixtures-async"
5555
gem "sus-fixtures-async-http"
56+
gem "sus-fixtures-console"
5657
gem "sus-fixtures-openssl"
5758

5859
gem "bake"

lib/falcon/command.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66

77
require_relative "command/top"
88

9+
require "console"
10+
911
module Falcon
1012
# @namespace
1113
module Command
1214
# The main entry point for the `falcon` executable.
1315
# @parameter arguments [Array(String)] The command line arguments.
1416
def self.call(*arguments)
1517
Top.call(*arguments)
18+
rescue Interrupt
19+
# Ignore.
20+
rescue => error
21+
Console.error(self, error)
22+
exit! 1
1623
end
1724
end
1825
end

lib/falcon/command/host.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
require "samovar"
1010
require "async/service/controller"
11+
require "console"
1112

1213
module Falcon
1314
module Command
@@ -17,6 +18,17 @@ module Command
1718
class Host < Samovar::Command
1819
self.description = "Host the specified applications."
1920

21+
# The main entry point for the `falcon-host` executable.
22+
# @parameter arguments [Array(String)] The command line arguments.
23+
def self.call(...)
24+
super
25+
rescue Interrupt
26+
# Ignore.
27+
rescue => error
28+
Console.error(self, error)
29+
exit! 1
30+
end
31+
2032
# One or more paths to the configuration files.
2133
# @name paths
2234
# @attribute [Array(String)]

lib/falcon/command/serve.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
require_relative "../server"
88
require_relative "../endpoint"
99
require_relative "../service/server"
10+
require_relative "../environment/server"
1011
require_relative "../environment/rackup"
1112

1213
require "async/service/configuration"

lib/falcon/service/virtual.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Copyright, 2020-2024, by Samuel Williams.
55

66
require "async/service/generic"
7+
require "console"
78

89
module Falcon
910
module Service

test/falcon/command.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2026, by Samuel Williams.
5+
6+
require "falcon/command"
7+
require "sus/fixtures/console/captured_logger"
8+
9+
describe Falcon::Command do
10+
include Sus::Fixtures::Console::CapturedLogger
11+
12+
it "reports errors from the command entry point" do
13+
error = RuntimeError.new("boom")
14+
captured_status = nil
15+
16+
mock(Falcon::Command::Top) do |top|
17+
top.replace(:call) do
18+
raise error
19+
end
20+
end
21+
22+
mock(subject) do |command|
23+
command.replace(:exit!) do |status|
24+
captured_status = status
25+
end
26+
end
27+
28+
subject.call
29+
30+
expect(captured_status).to be == 1
31+
32+
expect_console.to have_logged(
33+
severity: be == :error,
34+
subject: be == subject,
35+
arguments: be == [error],
36+
message: be == "boom",
37+
)
38+
end
39+
end

test/falcon/command/host.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2026, by Samuel Williams.
5+
6+
require "falcon/command/host"
7+
require "sus/fixtures/console/captured_logger"
8+
9+
describe Falcon::Command::Host do
10+
include Sus::Fixtures::Console::CapturedLogger
11+
12+
let(:command) do
13+
subject[]
14+
end
15+
16+
it "runs the controller" do
17+
captured_configuration = nil
18+
captured_container_class = nil
19+
20+
mock(Async::Service::Controller) do |controller|
21+
controller.replace(:run) do |configuration, container_class:|
22+
captured_configuration = configuration
23+
captured_container_class = container_class
24+
end
25+
end
26+
27+
command.call
28+
29+
expect(captured_configuration).to be_a(Async::Service::Configuration)
30+
expect(captured_container_class).to be == command.container_class
31+
32+
expect_console.to have_logged(
33+
severity: be == :info,
34+
subject: be == command,
35+
message: be(:include?, "Falcon Host v"),
36+
)
37+
end
38+
39+
it "reports errors from the host entry point" do
40+
error = RuntimeError.new("boom")
41+
captured_status = nil
42+
43+
mock(Async::Service::Controller) do |controller|
44+
controller.replace(:run) do |configuration, container_class:|
45+
raise error
46+
end
47+
end
48+
49+
mock(subject) do |host|
50+
host.replace(:exit!) do |status|
51+
captured_status = status
52+
end
53+
end
54+
55+
subject.call(["missing.rb"])
56+
57+
expect(captured_status).to be == 1
58+
59+
expect_console.to have_logged(
60+
severity: be == :error,
61+
subject: be == subject,
62+
arguments: be == [error],
63+
message: be == "boom",
64+
)
65+
end
66+
end

0 commit comments

Comments
 (0)