【发布时间】:2020-07-08 19:30:55
【问题描述】:
我正在尝试测试 ntp 设置。 我已经配置了一个安装了 ntp 服务的 VM。 我能够登录到 vm 并运行验证 ntp 确实已安装并限制查询的命令:
vagrant@vagrant:~> sudo ntpq -p
localhost: timed out, nothing received
***Request timed out
但是,当我尝试在测试中测试这个确切的命令时,它返回空... 我显然在这里遗漏了一些重要的东西,但我不知道是什么。
这是我的测试:
control 'ntp configuration' do
describe command('sudo nptq -p') do
its('stdout') { should match('localhost: timed out, nothing received') }
end
end
还有错误:
× ntp configuration: Command: `sudo nptq -p`
× Command: `sudo nptq -p` stdout is expected to match "localhost: timed out, nothing received"
expected "" to match "localhost: timed out, nothing received"
我试过stdout和stderr,都没有用。
但是,我确实注意到的一件事是,从 vm 本身的命令行运行此命令需要几秒钟才能返回消息。 然而,该测试以明显更短的时间返回一个空字符串。
有人能解释一下吗? :)
【问题讨论】:
-
错误可能在stderr,而不是stdout。
-
我实际上尝试了stderr和stdout。
-
我认为你的测试中有错字 -
nptq,但应该是ntpq。测试中也不需要sudo,因为测试已经以root身份运行。 -
谢谢你们,显然这是两者的结合。错字显然破坏了命令,而我正在寻找的结果确实是在 stderr 中定义的。
标签: ruby bash chef-infra ntp