超级基本的chefspec测试失败了生产食谱,知道工作

时间:2018-05-14 15:41:04

标签: unit-testing chef devops chefspec

我正在尝试运行一个厨师规范测试,检查nginx食谱是否正常运行。这只是一个简单的测试。那么它根本不会正常工作。我可以让我的命令指向它并运行测试,但它不会传递给生产!已经部署了好几个月的烹饪书,工作得很好,当我kitchen test server在运行列表中运行一堆食谱时,它也会收敛。

当我们部署厨师食谱时,我们部署了一个名为init_setup的东西,它运行了大量的东西,其中一个是nginx食谱。我想我可以在没有其他人的情况下将其作为独立的食谱进行测试。我在这里错了,还是有办法像执行kitchen verify server

那样运行chefspec测试

测试

#
# Cookbook:: nginx
# Spec:: default
#
# Copyright:: 2018, The Authors, All Rights Reserved.

require 'spec_helper'


describe 'nginx::default' do
  context 'When all attributes are default, on Ubuntu 16.04' do
    let(:chef_run) do
      # for a complete list of available platforms and versions see:
      # https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
      runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
      runner.converge(described_recipe)
    end

    it 'converges successfully' do
      expect { chef_run }.to_not raise_error
    end
  end
end

错误

F

Failures:

  1) nginx::default When all attributes are default, on Ubuntu 16.04 converges successfully
     Failure/Error: expect { chef_run }.to_not raise_error

       expected no Exception, got #<NameError: uninitialized constant ChefSpec> with backtrace:
         # ./cookbooks/nginx/spec/unit/recipes/default_spec.rb:15:in `block (3 levels) in <top (required)>'
         # ./cookbooks/nginx/spec/unit/recipes/default_spec.rb:20:in `block (4 levels) in <top (required)>'
         # ./cookbooks/nginx/spec/unit/recipes/default_spec.rb:20:in `block (3 levels) in <top (required)>'
     # ./cookbooks/nginx/spec/unit/recipes/default_spec.rb:20:in `block (3 levels) in <top (required)>'

Finished in 0.0273 seconds (files took 0.37841 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./cookbooks/nginx/spec/unit/recipes/default_spec.rb:19 # nginx::default When all attributes are default, on Ubuntu 16.04 converges successfully

帮助规范

# frozen_string_literal: true
require 'chefspec'
require 'chefspec/berkshelf'

在nginx目录中时出错

CPName-Username:nginx josh.kirby$ chef exec rspec 
spec/unit/recipes/default_spec.rb

[2018-05-14T13:37:07-04:00] WARN: Port 8889 not available
F

Failures:

  1) nginx::default When all attributes are default, on Ubuntu 16.04 converges successfully
     Failure/Error: expect { chef_run }.to_not raise_error

       expected no Exception, got #<NoMethodError: undefined method `[]' for nil:NilClass> with backtrace:
         # /var/folders/pj/c4gpnwws6n7gb7x_plpv9hzc0000gp/T/chefspec20180514-23893-d5kb58file_cache_path/cookbooks/nginx/recipes/_configure.rb:23:in `from_file'
         # /var/folders/pj/c4gpnwws6n7gb7x_plpv9hzc0000gp/T/chefspec20180514-23893-d5kb58file_cache_path/cookbooks/nginx/recipes/default.rb:324:in `from_file'
         # ./spec/unit/recipes/default_spec.rb:16:in `block (3 levels) in <top (required)>'
         # ./spec/unit/recipes/default_spec.rb:20:in `block (4 levels) in <top (required)>'
         # ./spec/unit/recipes/default_spec.rb:20:in `block (3 levels) in <top (required)>'
     # ./spec/unit/recipes/default_spec.rb:20:in `block (3 levels) in <top (required)>'

Finished in 4.16 seconds (files took 1.93 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/unit/recipes/default_spec.rb:19 # nginx::default When all attributes are default, on Ubuntu 16.04 converges successfully

1 个答案:

答案 0 :(得分:0)

在评论中解决,最初是在错误的文件夹中,然后是正确的失败,因为不存在所需的属性。