2025-02-26 13:26:37 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2025-03-13 14:50:03 +00:00
|
|
|
require "services/commands/info"
|
2025-02-26 13:26:37 +01:00
|
|
|
|
2025-03-13 14:50:03 +00:00
|
|
|
RSpec.describe Services::Commands::Info do
|
2025-02-26 13:26:37 +01:00
|
|
|
before do
|
2025-03-13 14:50:03 +00:00
|
|
|
allow_any_instance_of(IO).to receive(:tty?).and_return(false)
|
2025-02-26 13:26:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#TRIGGERS" do
|
|
|
|
it "contains all restart triggers" do
|
|
|
|
expect(described_class::TRIGGERS).to eq(%w[info i])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#run" do
|
|
|
|
it "fails with empty list" do
|
|
|
|
expect do
|
|
|
|
described_class.run([], verbose: false, json: false)
|
2025-03-13 14:50:03 +00:00
|
|
|
end.to raise_error UsageError, "Invalid usage: Formula(e) missing, please provide a formula name or use --all"
|
2025-02-26 13:26:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "succeeds with items" do
|
2025-03-13 14:50:03 +00:00
|
|
|
out = "service ()\nRunning: true\nLoaded: true\nSchedulable: false\n"
|
2025-02-26 13:26:37 +01:00
|
|
|
formula = {
|
|
|
|
name: "service",
|
|
|
|
user: "user",
|
|
|
|
status: :started,
|
|
|
|
file: "/dev/null",
|
|
|
|
running: true,
|
|
|
|
loaded: true,
|
|
|
|
schedulable: false,
|
|
|
|
}
|
|
|
|
expect do
|
|
|
|
described_class.run([formula], verbose: false, json: false)
|
|
|
|
end.to output(out).to_stdout
|
|
|
|
end
|
|
|
|
|
|
|
|
it "succeeds with items - JSON" do
|
|
|
|
formula = {
|
|
|
|
name: "service",
|
|
|
|
user: "user",
|
|
|
|
status: :started,
|
|
|
|
file: "/dev/null",
|
|
|
|
running: true,
|
|
|
|
loaded: true,
|
|
|
|
schedulable: false,
|
|
|
|
}
|
|
|
|
out = "#{JSON.pretty_generate([formula])}\n"
|
|
|
|
expect do
|
|
|
|
described_class.run([formula], verbose: false, json: true)
|
|
|
|
end.to output(out).to_stdout
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#output" do
|
|
|
|
it "returns minimal output" do
|
2025-03-13 14:50:03 +00:00
|
|
|
out = "service ()\nRunning: true\n"
|
|
|
|
out += "Loaded: true\nSchedulable: false\n"
|
2025-02-26 13:26:37 +01:00
|
|
|
formula = {
|
|
|
|
name: "service",
|
|
|
|
user: "user",
|
|
|
|
status: :started,
|
|
|
|
file: "/dev/null",
|
|
|
|
running: true,
|
|
|
|
loaded: true,
|
|
|
|
schedulable: false,
|
|
|
|
}
|
|
|
|
expect(described_class.output(formula, verbose: false)).to eq(out)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns normal output" do
|
2025-03-13 14:50:03 +00:00
|
|
|
out = "service ()\nRunning: true\n"
|
|
|
|
out += "Loaded: true\nSchedulable: false\n"
|
2025-02-26 13:26:37 +01:00
|
|
|
out += "User: user\nPID: 42\n"
|
|
|
|
formula = {
|
|
|
|
name: "service",
|
|
|
|
user: "user",
|
|
|
|
status: :started,
|
|
|
|
file: "/dev/null",
|
|
|
|
running: true,
|
|
|
|
loaded: true,
|
|
|
|
schedulable: false,
|
|
|
|
pid: 42,
|
|
|
|
}
|
|
|
|
expect(described_class.output(formula, verbose: false)).to eq(out)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns verbose output" do
|
2025-03-13 14:50:03 +00:00
|
|
|
out = "service ()\nRunning: true\n"
|
|
|
|
out += "Loaded: true\nSchedulable: false\n"
|
|
|
|
out += "User: user\nPID: 42\nFile: /dev/null true\nCommand: /bin/command\n"
|
2025-02-26 13:26:37 +01:00
|
|
|
out += "Working directory: /working/dir\nRoot directory: /root/dir\nLog: /log/dir\nError log: /log/dir/error\n"
|
|
|
|
out += "Interval: 3600s\nCron: 5 * * * *\n"
|
|
|
|
formula = {
|
|
|
|
name: "service",
|
|
|
|
user: "user",
|
|
|
|
status: :started,
|
|
|
|
file: "/dev/null",
|
|
|
|
running: true,
|
|
|
|
loaded: true,
|
|
|
|
schedulable: false,
|
|
|
|
pid: 42,
|
|
|
|
command: "/bin/command",
|
|
|
|
working_dir: "/working/dir",
|
|
|
|
root_dir: "/root/dir",
|
|
|
|
log_path: "/log/dir",
|
|
|
|
error_log_path: "/log/dir/error",
|
|
|
|
interval: 3600,
|
|
|
|
cron: "5 * * * *",
|
|
|
|
}
|
|
|
|
expect(described_class.output(formula, verbose: true)).to eq(out)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|