2016-09-12 21 views
0

Ich versuche ChefSpec zu verwenden, um eine Implementierung von Chef und Hashicorp VaultChefspec mit Hashicorp Vault

Rezept

chef_gem 'vault' do 
    compile_time true if Chef::Resource::ChefGem.instance_methods(false).include?(:compile_time) 
end 

require 'vault' 

Vault.address = 'https://address:8200' 
Vault.token = citadel['foo/bar'] 
Vault.auth_token.renew_self 

-Test

require_relative '../spec_helper' 

describe 'wrapper::default' do 
    context 'role is foo' do 
    let(:chef_run) do 
     ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |node| 
     node.default['role'] = 'foo' 
     const_set(:Vault, Module.new) 
     end.converge(described_recipe) 
    end 

    before(:each) do 
     allow_any_instance_of(Chef::Recipe).to receive(:require).and_call_original 
     allow_any_instance_of(Chef::Recipe).to receive(:require).with('vault').and_return(true) 
     allow_any_instance_of(::Vault).to receive(:address).and_call_original 
     allow_any_instance_of(::Vault).to receive(:address).with('https://localhost:8200').and_return(true) 
    end 

    it 'install vault gem' do 
     expect(chef_run).to install_chef_gem('vault') 
    end 
    end 
end 

Fehler

Failure/Error: expect(Chef::Recipe::Vault).to receive(:address).and_call_original 

    NameError: 
     uninitialized constant Vault 
zu testen

Wie stoße ich den Vault va Versprechungen? Dies ist Hashicorp Vault, nicht Chef-Tresor.

Antwort

1

Ich antwortete bereits auf Ihre E-Mail, Sie wollen allow_any_instance_of(::Vault) und ähnliche, und Sie müssen möglicherweise das Modul (const_set(:Vault, Module.new)) erstellen, wenn es nicht bereits existiert.

+0

Aktualisiert meine Frage, ich fügte eine Konstante hinzu und nahm das Chef :: Rezept heraus, immer noch nicht initialisierte Konstante – jsmickey

+0

Bitte sehen Sie das zweite Bit von oben, wo Sie das Modul mit entweder 'const_set' oder' stub_const' vor Ihnen erstellen müssen kann Sachen draufstecken. – coderanger

Verwandte Themen