Skip to content

Commit 7240ef5

Browse files
botandrose-machinebotandrose
authored andcommitted
acceptance tests for the remaining commands, need to not actually exec in order to get test coverage.
1 parent b9b14d2 commit 7240ef5

6 files changed

Lines changed: 157 additions & 2 deletions

File tree

features/list.feature

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Feature: List command
2+
As a developer
3+
I want to list all my application services
4+
So that I can see what services are configured
5+
6+
Scenario: Shows all services
7+
Given a procsd.yml with:
8+
"""
9+
app: myapp
10+
formation: web=1,worker=2
11+
environment:
12+
PORT: 3000
13+
processes:
14+
web:
15+
ExecStart: /bin/sleep infinity
16+
worker:
17+
ExecStart: /bin/sleep infinity
18+
"""
19+
When I run "procsd create"
20+
Then the command should succeed
21+
When I run "procsd list"
22+
Then the command should succeed with:
23+
"""
24+
myapp.target
25+
○ ├─myapp-web.1.service
26+
○ ├─myapp-worker.1.service
27+
○ └─myapp-worker.2.service
28+
"""

features/logs.feature

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Feature: Logs command
2+
As a developer
3+
I want to view logs from my application services
4+
So that I can debug and monitor my application
5+
6+
Scenario: Shows service logs
7+
Given a procsd.yml with:
8+
"""
9+
app: myapp
10+
formation: web=1
11+
environment:
12+
PORT: 3000
13+
processes:
14+
web:
15+
ExecStart: ruby -e "STDOUT.sync=true; puts :ServiceStarted; sleep"
16+
"""
17+
When I run "procsd create"
18+
Then the command should succeed
19+
When I run "procsd start"
20+
Then the command should succeed
21+
When I wait 2 seconds
22+
When I run "procsd logs -n 10"
23+
Then the command should succeed
24+
And the output should match patterns:
25+
"""
26+
\d{4}-\d{2}-\d{2}T\S+ myapp-web\.1\[\d+\]: ServiceStarted
27+
"""
28+
29+
Scenario: Shows logs for a specific service
30+
Given a procsd.yml with:
31+
"""
32+
app: myapp
33+
formation: web=1,worker=1
34+
environment:
35+
PORT: 3000
36+
processes:
37+
web:
38+
ExecStart: ruby -e "STDOUT.sync=true; puts :WebStarted; sleep"
39+
worker:
40+
ExecStart: ruby -e "STDOUT.sync=true; puts :WorkerStarted; sleep"
41+
"""
42+
When I run "procsd create"
43+
Then the command should succeed
44+
When I run "procsd start"
45+
Then the command should succeed
46+
When I wait 2 seconds
47+
When I run "procsd logs web -n 10"
48+
Then the command should succeed
49+
And the output should match patterns:
50+
"""
51+
\d{4}-\d{2}-\d{2}T\S+ myapp-web\.1\[\d+\]: WebStarted
52+
"""

features/status.feature

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Feature: Status command
2+
As a developer
3+
I want to check the status of my application services
4+
So that I can see if they are running correctly
5+
6+
Scenario: Shows service status
7+
Given a procsd.yml with:
8+
"""
9+
app: myapp
10+
formation: web=1
11+
environment:
12+
PORT: 3000
13+
processes:
14+
web:
15+
ExecStart: /bin/sleep infinity
16+
"""
17+
When I run "procsd create"
18+
Then the command should succeed
19+
When I run "procsd start"
20+
Then the command should succeed
21+
When I run "procsd status --short"
22+
Then the command should succeed with:
23+
"""
24+
myapp-web.1.service loaded active running myapp-web.1.service
25+
"""
26+
27+
Scenario: Shows target status with --target option
28+
Given a procsd.yml with:
29+
"""
30+
app: myapp
31+
formation: web=1
32+
environment:
33+
PORT: 3000
34+
processes:
35+
web:
36+
ExecStart: /bin/sleep infinity
37+
"""
38+
When I run "procsd create"
39+
Then the command should succeed
40+
When I run "procsd start"
41+
Then the command should succeed
42+
When I run "procsd status --target --short"
43+
Then the command should succeed with:
44+
"""
45+
myapp.target loaded active active myapp.target
46+
"""

features/step_definitions/procsd_steps.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
@container.write_file("/home/testuser/myapp/Procfile", content)
77
end
88

9+
When("I wait {int} seconds") do |seconds|
10+
sleep(seconds)
11+
end
12+
913
When("I run {string}") do |command|
1014
@result = @container.exec(
1115
"#{ContainerHelper::CONTAINER_GEM_SRC}/bin/coverage #{command}",
@@ -34,6 +38,20 @@ def procsd_output
3438
expect(procsd_output).to eq(expected.strip)
3539
end
3640

41+
Then("the output should match patterns:") do |patterns|
42+
output_lines = procsd_output.lines.map(&:chomp)
43+
pattern_lines = patterns.strip.lines.map(&:strip)
44+
45+
expect(output_lines.size).to eq(pattern_lines.size),
46+
"Expected #{pattern_lines.size} lines, got #{output_lines.size}:\n#{procsd_output}"
47+
48+
pattern_lines.each_with_index do |pattern, i|
49+
regex = Regexp.new("^#{pattern}$")
50+
expect(output_lines[i]).to match(regex),
51+
"Line #{i + 1}: expected to match #{regex.inspect}, got #{output_lines[i].inspect}"
52+
end
53+
end
54+
3755
Then("the systemd directory should contain {string}") do |filename|
3856
files = @container.list_service_files("*")
3957
expect(files).to include(filename)

features/support/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,20 @@ RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
2222
/lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup* \
2323
/lib/systemd/system/systemd-update-utmp*
2424

25-
# Create a test user that can run sudo without password
25+
# Create a test user that can run sudo without password and read journal logs
2626
RUN useradd -m -s /bin/bash testuser && \
27+
usermod -aG systemd-journal testuser && \
2728
echo "testuser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/testuser
2829

30+
# Configure journald for persistent storage
31+
RUN mkdir -p /etc/systemd/journald.conf.d && \
32+
echo -e "[Journal]\nStorage=persistent" > /etc/systemd/journald.conf.d/storage.conf
33+
34+
# Create journal directory with correct group ownership upfront
35+
RUN mkdir -p /var/log/journal && \
36+
chgrp systemd-journal /var/log/journal && \
37+
chmod 2755 /var/log/journal
38+
2939
# Install gems needed by procsd
3040
RUN gem install thor dotenv simplecov --no-document
3141

lib/procsd/cli.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ def execute(command, type: :system)
375375
when :system
376376
system *command
377377
when :exec
378-
exec *command
378+
system *command
379+
exit($?.exitstatus || 1)
379380
end
380381
end
381382

0 commit comments

Comments
 (0)