我对serverspec有个问题。我正在尝试检查ubuntu上安装的软件包版本。
我使用以下代码:
describe 'java packages' do
it 'package openjdk-9-jre should be installed with the correct version' do
expect(package('openjdk-9-jre')).to be_installed.with_version('9~b114-0ubuntu1')
end
endServerspec运行dpkg-query命令检查包,但转义tilda字符,它不起作用。serverspec运行:
dpkg-query -f '${Status} ${Version}' -W openjdk-9-jre | grep -E '^(install|hold) ok installed 9\\~b114-0ubuntu1$'而不是
dpkg-query -f '${Status} ${Version}' -W openjdk-9-jre | grep -E '^(install|hold) ok installed 9~b114-0ubuntu1$'我如何解决这个问题?
发布于 2017-02-23 22:23:33
Specinfra将with_version链中的字符转义为#{Regexp.escape(escape(version))}而不是#{Regexp.escape(version))。由于Specinfra/Serverspec贡献政策的原因,这将需要对Specinfra的PR进行修复。我可以把这个放在我要做的事情清单上,并在完成时通知你,因为我有一个最新的Specinfra分支,并且是这两个分支的贡献者,所以我知道代码库。
同时,你必须做一个command匹配器的变通方法。
describe 'java packages' do
it 'package openjdk-9-jre should be installed with the correct version' do
describe command("dpkg-query -f '${Status} ${Version}' -W openjdk-9-jre") do
its(:stdout) { is_expected.to match('^(install|hold) ok installed 9\~b114\-0ubuntu1$') }
end
end
endSpecinfra PR:https://github.com/mizzy/specinfra/pull/608
https://stackoverflow.com/questions/42417864
复制相似问题