I am very new to Chef and the TDD workflow. I was able to write a simple
unit test with ChefSpec to make sure users in my users data bag get created
with some mocking using the create_data_bag inside
the ChefSpec::ServerRunner.new block. I would like to extend this check to
my Serverspec integration testing, but I am struggling with how to
stub/mock my users data bag in Serverspec. Thank you for your help and
guidance.
In Serverspec, you need to have "real" data bags to send to the node being
tested for the remote chef-client to have something to retrieve, vs
ChefSpec's stubbing of data bags.
There's a few ways to do it, but one we've adopted for the simplicity is
placing a json file:
/test/integration/data_bags//.json
Test Kitchen will then auto-load any items from that path.
If you want to change the path, you can, see here for more:
I am very new to Chef and the TDD workflow. I was able to write a simple
unit test with ChefSpec to make sure users in my users data bag get created
with some mocking using the create_data_bag inside
the ChefSpec::ServerRunner.new block. I would like to extend this check to
my Serverspec integration testing, but I am struggling with how to
stub/mock my users data bag in Serverspec. Thank you for your help and
guidance.
In Serverspec, you need to have "real" data bags to send to the node being
tested for the remote chef-client to have something to retrieve, vs
ChefSpec's stubbing of data bags.
There's a few ways to do it, but one we've adopted for the simplicity is
placing a json file:
/test/integration/data_bags//.json
Test Kitchen will then auto-load any items from that path.
If you want to change the path, you can, see here for more: kitchen.yml
I am very new to Chef and the TDD workflow. I was able to write a simple
unit test with ChefSpec to make sure users in my users data bag get created
with some mocking using the create_data_bag inside
the ChefSpec::ServerRunner.new block. I would like to extend this check to
my Serverspec integration testing, but I am struggling with how to
stub/mock my users data bag in Serverspec. Thank you for your help and
guidance.
Check out the pattern in this cookbook for a way to handle this in Test Kitchen with Serverspec. Of particular note is the ‘data_bag_path’ line in the .kitchen.yml, and the files in tests/fixtures.
I am very new to Chef and the TDD workflow. I was able to write a simple unit test with ChefSpec to make sure users in my users data bag get created with some mocking using the create_data_bag inside the ChefSpec::ServerRunner.new block. I would like to extend this check to my Serverspec integration testing, but I am struggling with how to stub/mock my users data bag in Serverspec. Thank you for your help and guidance.
For TK, you'd want the data bag on disk, but for chefspec, I don't know how
to get that stubbed file into chefspec. You can stub the response in your
rspec directlly, though. Here's an example from our drone-ci cookbook's
specs:
before do
allow(Chef::EncryptedDataBagItem).to receive(:load).with('ci',
'config').and_return(
'{"id": "config","client": "ABC","secret": "123"}'
)
end
On Thu, Mar 12, 2015 at 11:40 AM, Charles Johnson charles@chef.io wrote:
Hi Jimmy,
Check out the pattern in this cookbook for a way to handle this in Test
Kitchen with Serverspec. Of particular note is the 'data_bag_path' line in
the .kitchen.yml, and the files in tests/fixtures.
I am very new to Chef and the TDD workflow. I was able to write a simple
unit test with ChefSpec to make sure users in my users data bag get created
with some mocking using the create_data_bag inside
the ChefSpec::ServerRunner.new block. I would like to extend this check to
my Serverspec integration testing, but I am struggling with how to
stub/mock my users data bag in Serverspec. Thank you for your help and
guidance.
For TK, you'd want the data bag on disk, but for chefspec, I don't know
how to get that stubbed file into chefspec. You can stub the response in
your rspec directlly, though. Here's an example from our drone-ci
cookbook's specs:
before do
allow(Chef::EncryptedDataBagItem).to receive(:load).with('ci',
'config').and_return(
'{"id": "config","client": "ABC","secret": "123"}'
)
end
On Thu, Mar 12, 2015 at 11:40 AM, Charles Johnson charles@chef.io wrote:
Hi Jimmy,
Check out the pattern in this cookbook for a way to handle this in Test
Kitchen with Serverspec. Of particular note is the 'data_bag_path' line in
the .kitchen.yml, and the files in tests/fixtures.
I am very new to Chef and the TDD workflow. I was able to write a simple
unit test with ChefSpec to make sure users in my users data bag get created
with some mocking using the create_data_bag inside
the ChefSpec::ServerRunner.new block. I would like to extend this check to
my Serverspec integration testing, but I am struggling with how to
stub/mock my users data bag in Serverspec. Thank you for your help and
guidance.
Thank you so, so much for the amazingly fast response to my question and
supplying such clear examples. I really appreciate it. I will point my
TestKitchen to the appropriate data_bag_path. Thank you again.
For TK, you'd want the data bag on disk, but for chefspec, I don't know
how to get that stubbed file into chefspec. You can stub the response in
your rspec directlly, though. Here's an example from our drone-ci
cookbook's specs:
before do
allow(Chef::EncryptedDataBagItem).to receive(:load).with('ci',
'config').and_return(
'{"id": "config","client": "ABC","secret": "123"}'
)
end
On Thu, Mar 12, 2015 at 11:40 AM, Charles Johnson charles@chef.io
wrote:
Hi Jimmy,
Check out the pattern in this cookbook for a way to handle this in Test
Kitchen with Serverspec. Of particular note is the 'data_bag_path' line in
the .kitchen.yml, and the files in tests/fixtures.
I am very new to Chef and the TDD workflow. I was able to write a
simple unit test with ChefSpec to make sure users in my users data bag get
created with some mocking using the create_data_bag inside
the ChefSpec::ServerRunner.new block. I would like to extend this check to
my Serverspec integration testing, but I am struggling with how to
stub/mock my users data bag in Serverspec. Thank you for your help and
guidance.
Thank you so, so much for the amazingly fast response to my question and
supplying such clear examples. I really appreciate it. I will point my
TestKitchen to the appropriate data_bag_path. Thank you again.
Jimmy
On Thu, Mar 12, 2015 at 11:59 AM, Nathan Williams <nath.e.will@gmail.com
<javascript:_e(%7B%7D,'cvml','nath.e.will@gmail.com');>> wrote:
heh, and i totally misunderstood the question >__<. nm!
On Thu, Mar 12, 2015 at 11:57 AM, Nathan Williams <nath.e.will@gmail.com
<javascript:_e(%7B%7D,'cvml','nath.e.will@gmail.com');>> wrote:
For TK, you'd want the data bag on disk, but for chefspec, I don't know
how to get that stubbed file into chefspec. You can stub the response in
your rspec directlly, though. Here's an example from our drone-ci
cookbook's specs:
before do
allow(Chef::EncryptedDataBagItem).to receive(:load).with('ci',
'config').and_return(
'{"id": "config","client": "ABC","secret": "123"}'
)
end
On Thu, Mar 12, 2015 at 11:40 AM, Charles Johnson <charles@chef.io
<javascript:_e(%7B%7D,'cvml','charles@chef.io');>> wrote:
Hi Jimmy,
Check out the pattern in this cookbook for a way to handle this in Test
Kitchen with Serverspec. Of particular note is the 'data_bag_path' line in
the .kitchen.yml, and the files in tests/fixtures.
On March 12, 2015 at 10:59:22 AM, Jimmy Huang ( jimmy.huang@duragility.com
<javascript:_e(%7B%7D,'cvml','jimmy.huang@duragility.com');>) wrote:
Hi,
I am very new to Chef and the TDD workflow. I was able to write a
simple unit test with ChefSpec to make sure users in my users data bag get
created with some mocking using the create_data_bag inside
the ChefSpec::ServerRunner.new block. I would like to extend this check to
my Serverspec integration testing, but I am struggling with how to
stub/mock my users data bag in Serverspec. Thank you for your help and
guidance.
Thank you so, so much for the amazingly fast response to my question and
supplying such clear examples. I really appreciate it. I will point my
TestKitchen to the appropriate data_bag_path. Thank you again.
For TK, you'd want the data bag on disk, but for chefspec, I don't know
how to get that stubbed file into chefspec. You can stub the response in
your rspec directlly, though. Here's an example from our drone-ci
cookbook's specs:
before do
allow(Chef::EncryptedDataBagItem).to receive(:load).with('ci',
'config').and_return(
'{"id": "config","client": "ABC","secret": "123"}'
)
end
On Thu, Mar 12, 2015 at 11:40 AM, Charles Johnson charles@chef.io
wrote:
Hi Jimmy,
Check out the pattern in this cookbook for a way to handle this in
Test Kitchen with Serverspec. Of particular note is the 'data_bag_path'
line in the .kitchen.yml, and the files in tests/fixtures.
I am very new to Chef and the TDD workflow. I was able to write a
simple unit test with ChefSpec to make sure users in my users data bag get
created with some mocking using the create_data_bag inside
the ChefSpec::ServerRunner.new block. I would like to extend this check to
my Serverspec integration testing, but I am struggling with how to
stub/mock my users data bag in Serverspec. Thank you for your help and
guidance.