windows - Windows 上的 Test-Kitchen serverspec 测试异常

标签 windows chef-infra test-kitchen serverspec

当使用 chef generate cookbook hello 命令时,生成的 serverspec spec_helper.rb 文件将不适用于 Test-Kitchen 1.4.1 和 windows。

kitchen verify 命令将在 windows 平台上抛出以下内容:

C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:98:in `spawn': No such file or directory - /bin/sh -c ls\ /etc/arch-release (Errno::ENOENT)
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:98:in `spawn_command'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:13:in `block in run_command'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:133:in `with_env'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:12:in `run_command'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/detect_os.rb:13:in `run_command'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/detect_os/arch.rb:3:in `detect'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/detect_os.rb:5:in `detect'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:24:in `block in detect_os'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:23:in `each'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:23:in `detect_os'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:9:in `os'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/suites/serverspec/windows_spec.rb:4:in `<top (required)>'

最佳答案

更改测试厨房 spec_helper.rb 文件以测试 windows 并相应地设置后端和操作系统,解决了这个问题:

require 'serverspec'

if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil?
  set :backend, :exec
else
  set :backend, :cmd
  set :os, family: 'windows'
end

然后您可以针对不同的平台进行测试,例如:

require 'spec_helper'

case os[:family]
when 'windows'
  describe file('C:\Users\vagrant\foo.txt') do
    it { should be_file }
  end
when 'darwin' # mac os x
  describe file('/user/vagrant/foo.txt') do
    it { should be_file }
  end
when 'ubuntu'
  describe file('/home/vagrant/foo.txt') do
    it { should be_file }
  end
end

关于windows - Windows 上的 Test-Kitchen serverspec 测试异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31418609/

相关文章:

linux - 通过非标准 ssh 端口使用 Chef & Amazon

linux - Chef 厨房无法从 Windows 10 集成 bash 工作

macos - 类:厨房::ActionFailed-测试厨房+ Docker +远程API

vagrant - 厨房创建 new_box 命令不起作用

c++ - 使用 SendMessage 获取垃圾来填充列表框

python - Hook 并在 Windows 消息队列中记录 "everything"

c++ - 使用 TDM-GCC-64、Cmake 和 CodeBlocks 在 Windows 8 中构建 OpenCV 静态库时出错

c++ - DLL 和 STL 以及静态数据(天哪!)

chef-infra - 使用 Chef 服务器和 Vagrant 提供开发人员环境而无需注册节点

ruby - Chef 在错误的文件夹中寻找模板