summaryrefslogtreecommitdiff
path: root/features/steps/recipe.rb
blob: 7c5c96327cac83aedf00e5fc8dd5b4cec29a2613 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Given /^the cookbook has a '(.+)' named '(.+)' in the '(.+)' specific directory$/ do |file_type, filename, specificity|
  cookbook_name, recipe_name = @recipe.split('::')
  type_dir = file_type == 'file' ? 'files' : 'templates'
  specific_dir = nil
  case specificity
  when "host"
    specific_dir = "host-#{@client.node[:fqdn]}"
  when "platform-version"
    specific_dir = "#{@client.node[:platform]}-#{@client.node[:platform_version]}"
  when "platform"
    specific_dir = @client.node[:platform]
  when "default"
    specific_dir = "default"
  end
  new_file_dir = File.expand_path(
    File.join(
      File.dirname(__FILE__), 
      "..", 
      "data", 
      "cookbooks", 
      cookbook_name, 
      type_dir, 
      specific_dir
    )
  )
  @cleanup_dirs << new_file_dir unless new_file_dir =~ /default$/
  system("mkdir -p #{new_file_dir}")
  new_file_name = File.join(new_file_dir, filename)
  @cleanup_files << new_file_name
  new_file = File.open(new_file_name, "w")
  new_file.puts(specificity)
  new_file.close
end