如何在厨师中为递归创建的目录编写规范
How to write spec for a Directories created recursively, in chef
例如。
正在使用 Chef 中的 directory
资源创建目录。
directory '/app/my_app/log' do
owner 'myuser'
group 'myuser'
recursively true
end
正在编写此资源的规范。
it 'creates directory /app' do
expect(chef_run).to create_directory('/app').with(
user: 'myuser',
group: 'myuser'
)
end
it 'creates directory /app/my_app' do
expect(chef_run).to create_directory('/app/my_app').with(
user: 'myuser',
group: 'myuser'
)
end
it 'creates directory /app/my_app/log' do
expect(chef_run).to create_directory('/app/my_app/log').with(
user: 'myuser',
group: 'myuser'
)
end
规范应该这样写吗?我想知道我是否做错了,如果是这样那么你会怎么做?
谢谢!
您只需检查 recursive: true
,就像在 with()
调用中检查 user
和 group
一样。没有为中间目录创建目录资源,只有一个。
it 'creates directory /app/my_app/log' do
expect(chef_run).to create_directory('/app/my_app/log').with(
user: 'myuser',
group: 'myuser',
recursive: true,
)
end
例如。
正在使用 Chef 中的 directory
资源创建目录。
directory '/app/my_app/log' do
owner 'myuser'
group 'myuser'
recursively true
end
正在编写此资源的规范。
it 'creates directory /app' do
expect(chef_run).to create_directory('/app').with(
user: 'myuser',
group: 'myuser'
)
end
it 'creates directory /app/my_app' do
expect(chef_run).to create_directory('/app/my_app').with(
user: 'myuser',
group: 'myuser'
)
end
it 'creates directory /app/my_app/log' do
expect(chef_run).to create_directory('/app/my_app/log').with(
user: 'myuser',
group: 'myuser'
)
end
规范应该这样写吗?我想知道我是否做错了,如果是这样那么你会怎么做?
谢谢!
您只需检查 recursive: true
,就像在 with()
调用中检查 user
和 group
一样。没有为中间目录创建目录资源,只有一个。
it 'creates directory /app/my_app/log' do
expect(chef_run).to create_directory('/app/my_app/log').with(
user: 'myuser',
group: 'myuser',
recursive: true,
)
end