Ruby Inspec -describe.one,但其中一个选项需要两个describe命令

46scxncf  于 11个月前  发布在  Ruby
关注(0)|答案(1)|浏览(97)

我有一个不太复杂的Ruby Inspec文件,但我不知道如何正确地构建它。我基本上需要检查rsync是否 * 未安装 * 或禁用。为了检查它是否被禁用,我运行systemctl is-active rsyncsystemctl is-enabled rsync。然后我将输出分别与inactivedisabled匹配。

control "my control" do
  title "title"
  desc "desc"

  describe.one do
    describe package('rsync') do
      it { should_not be_installed }
    end

    # These two should be treated as one option
    describe command('systemctl is-active rsync') do
      its('stdout') { should match "^inactive$" }
    end
    describe command('systemctl is-enabled rsync') do
      its('stdout') { should match "^disabled$" }
    end
  end
end

字符串

z4iuyo4d

z4iuyo4d1#

试试这样的东西:

control "my control" do
  title "title"
  desc "desc"

  if package('rsync').installed?
    # These two should be treated as one option
    describe command('systemctl is-active rsync') do
      its('stdout') { should match "^inactive$" }
    end
    describe command('systemctl is-enabled rsync') do
      its('stdout') { should match "^disabled$" }
    end
  end
end

字符串
或者你应该能够做这样的事情:

control "my control" do
  title "title"
  desc "desc"

  describe.one do
    describe package('rsync') do
      it { should_not be_installed }
    end

    describe 'rsync is inactive and disabled' do
      # These two should be treated as one option
      describe command('systemctl is-active rsync') do
        its('stdout') { should match "^inactive$" }
      end
      describe command('systemctl is-enabled rsync') do
        its('stdout') { should match "^disabled$" }
      end
    end
  end
end

相关问题