21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-02 17:00:49 +02:00
chexpire/test/services/system_command_test.rb

31 lines
846 B
Ruby
Raw Normal View History

# Copyright (C) 2018 Colin Darie <colin@darie.eu>, 2018 Evolix <info@evolix.fr>
# License: GNU AGPL-3+ (see full text in LICENSE file)
2018-05-29 22:33:12 +02:00
require "test_helper"
class SystemCommandTest < ActiveSupport::TestCase
test "should execute and log a command" do
mock_logger = Minitest::Mock.new
2018-05-30 13:23:15 +02:00
expected_cmd = 'whois "example.org"'
2018-05-29 22:33:12 +02:00
expected_result = SystemCommand::Result.new(
2018-05-30 13:23:15 +02:00
expected_cmd,
0,
"my result",
"",
)
mock_logger.expect(:log, nil, [:before_command, expected_cmd])
mock_logger.expect(:log, nil, [:after_command, expected_result])
2018-05-29 22:33:12 +02:00
command = SystemCommand.new("whois", "example.org", logger: mock_logger)
2018-05-30 13:23:15 +02:00
assert_equal expected_cmd, command.syscmd
2018-05-29 22:33:12 +02:00
2018-05-30 13:23:15 +02:00
command.stub(:call, expected_result) do
assert_equal expected_result, command.execute
2018-05-29 22:33:12 +02:00
end
mock_logger.verify
end
end