首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ChefSpec找不到食谱

ChefSpec找不到食谱
EN

Stack Overflow用户
提问于 2016-03-01 05:37:25
回答 1查看 349关注 0票数 0

当我运行我的单元测试用例(用ChefSpec编写)时,我得到以下错误:

厨师::例外::烹饪书笔记:找不到食谱。如果要从另一本烹饪书中加载azuredns,请确保在元数据中配置依赖项。

下面是我的规范文件、食谱文件和元数据文件

azuredns/spec/get_azure_token_spec.rb

代码语言:javascript
复制
require 'chefspec'
require 'rest-client'

describe 'azuredns::get_azure_token' do
  let(:chef_run) do
    # Step into the provider
    runner = ChefSpec::SoloRunner.new(step_into: ['azuredns_token'])
    # Read test data from a json file
    file_path = File.expand_path('test_data.json', __dir__)
    file = File.open(file_path)
    contents = file.read
    node_attr = JSON.parse(contents)
    # Load test data into node object
    runner.node.consume_attributes(node_attr)
    runner.converge(described_recipe)
  end

  before(:each) do
    # Mock post method of RestClient
    allow(RestClient).to receive(:post)
      .and_return({ access_token: 'i-am-a-token' }.to_json)
  end

  it 'retrieves token' do
    expect(chef_run).to retrieve_azuredns_token('azure_token')
  end

  it 'varifies the expected value of azure_rest_token' do
    expect(chef_run.node['azure_rest_token']).to eq('Bearer i-am-a-token')
  end

  it 'does not retrieve token due to incorrect resource name' do
    expect(chef_run).to_not retrieve_azuredns_token('azure_token1')
  end

  it 'raises exception due to error in response' do
    # Mock post method of RestClient
    allow(RestClient).to receive(:post)
      .and_return({ error: 'invalid_grant' }.to_json)
    expect { chef_run }.to raise_error(Exception)
  end
end

azuredns/食谱/get_azure_Token.rb

代码语言:javascript
复制
require 'rest_client'
require 'json'

cloud_name = node['workorder']['cloud']['ciName']
cloud = node['workorder']['services']['dns'][cloud_name]
dns_attributes = cloud['ciAttributes']

#  Establish connection and get a security token
token = azuredns_token 'azure_token' do
  tenant_id dns_attributes['tenant_id']
  client_id dns_attributes['client_id']
  client_secret dns_attributes['client_secret']
end

token.run_action(:retrieve)

azuredns/元数据

代码语言:javascript
复制
name             'Azuredns'
maintainer       'Shaffan'
maintainer_email 'shaffan.chaudhry1@gmail.com'
license          'Apache License, Version 2.0'
description      'Installs/Configures Azure DNS'
version          '0.1.0'
depends          'azure'

请帮帮我!

EN

回答 1

Stack Overflow用户

发布于 2016-03-01 06:00:20

Azuredns != azuredns :-)

修正元数据中的名称。厨师,以及UNIX世界的几乎所有东西,都是区分大小写的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35715436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档