2025-02-26 13:26:37 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2025-03-13 14:50:03 +00:00
|
|
|
require "services/commands/cleanup"
|
|
|
|
require "services/system"
|
|
|
|
require "services/cli"
|
2025-02-26 13:26:37 +01:00
|
|
|
|
2025-03-13 14:50:03 +00:00
|
|
|
RSpec.describe Services::Commands::Cleanup do
|
2025-02-26 13:26:37 +01:00
|
|
|
describe "#TRIGGERS" do
|
|
|
|
it "contains all restart triggers" do
|
|
|
|
expect(described_class::TRIGGERS).to eq(%w[cleanup clean cl rm])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#run" do
|
|
|
|
it "root - prints on empty cleanup" do
|
2025-03-13 14:50:03 +00:00
|
|
|
expect(Services::System).to receive(:root?).once.and_return(true)
|
|
|
|
expect(Services::Cli).to receive(:kill_orphaned_services).once.and_return([])
|
|
|
|
expect(Services::Cli).to receive(:remove_unused_service_files).once.and_return([])
|
2025-02-26 13:26:37 +01:00
|
|
|
|
|
|
|
expect do
|
|
|
|
described_class.run
|
|
|
|
end.to output("All root services OK, nothing cleaned...\n").to_stdout
|
|
|
|
end
|
|
|
|
|
|
|
|
it "user - prints on empty cleanup" do
|
2025-03-13 14:50:03 +00:00
|
|
|
expect(Services::System).to receive(:root?).once.and_return(false)
|
|
|
|
expect(Services::Cli).to receive(:kill_orphaned_services).once.and_return([])
|
|
|
|
expect(Services::Cli).to receive(:remove_unused_service_files).once.and_return([])
|
2025-02-26 13:26:37 +01:00
|
|
|
|
|
|
|
expect do
|
|
|
|
described_class.run
|
|
|
|
end.to output("All user-space services OK, nothing cleaned...\n").to_stdout
|
|
|
|
end
|
|
|
|
|
|
|
|
it "prints nothing on cleanup" do
|
2025-03-13 14:50:03 +00:00
|
|
|
expect(Services::System).not_to receive(:root?)
|
|
|
|
expect(Services::Cli).to receive(:kill_orphaned_services).once.and_return(["a"])
|
|
|
|
expect(Services::Cli).to receive(:remove_unused_service_files).once.and_return(["b"])
|
2025-02-26 13:26:37 +01:00
|
|
|
|
|
|
|
expect do
|
|
|
|
described_class.run
|
|
|
|
end.not_to output("All user-space services OK, nothing cleaned...\n").to_stdout
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|