summaryrefslogtreecommitdiff
path: root/spec/integration/recipes/use_partial_spec.rb
blob: 0a9fb06612dd8e411e8136d93265856d3bb4aafe (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "spec_helper"
require "support/shared/integration/integration_helper"
require "chef/mixin/shell_out"

describe "notifying_block" do
  include IntegrationSupport
  include Chef::Mixin::ShellOut

  let(:chef_dir) { File.expand_path("../../..", __dir__) }
  let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" }

  when_the_repository "has a cookbook with partial resources" do
    before do
      ::Chef::HTTP::Authenticator.get_cert_password if windows?
      directory "cookbooks/x" do
        file "resources/_shared_properties.rb", <<-EOM
          property :content, String
        EOM
        file "resources/_action_helpers.rb", <<-EOM
          def printit(string)
            puts "DIDIT: \#{string}"
          end
        EOM
        file "resources/thing.rb", <<-EOM
          unified_mode true
          provides :thing
          use "shared_properties"
          action_class do
            use "action_helpers"
          end
          action :run do
            printit(new_resource.content)
          end
        EOM
        file "recipes/default.rb", <<~EOM
          thing "whatever" do
            content "stuff"
          end
        EOM
      end
      file "config/client.rb", <<-EOM
        local_mode true
        cookbook_path "#{path_to("cookbooks")}"
        log_level :warn
        always_dump_stacktrace true
      EOM
    end

    it "should run cleanly and print the output" do
      result = shell_out("#{chef_client} -c \"#{path_to("config/client.rb")}\" --no-color -F doc -o 'x::default'", cwd: chef_dir)
      expect(result.stdout).to match(/DIDIT: stuff/)
      result.error!
    end
  end

  when_the_repository "has a cookbook with partial resources done differently" do
    before do
      directory "cookbooks/x" do
        file "partials/_shared_properties.rb", <<-EOM
          property :content, String
        EOM
        file "partials/_action_partials.rb", <<-EOM
          def printit(string)
            puts "DIDIT: \#{string}"
          end
        EOM
        # this tests relative pathing, including the underscore and including the trailing .rb all work
        file "resources/thing.rb", <<-EOM
          unified_mode true

          provides :thing
          use "../partials/_shared_properties.rb"
          action_class do
            use "../partials/_action_partials.rb"
          end
          action :run do
            printit(new_resource.content)
          end
        EOM
        file "recipes/default.rb", <<~EOM
          thing "whatever" do
            content "stuff"
          end
        EOM
      end
      file "config/client.rb", <<-EOM
        local_mode true
        cookbook_path "#{path_to("cookbooks")}"
        log_level :warn
        always_dump_stacktrace true
      EOM
    end

    it "should run cleanly and print the output" do
      result = shell_out("#{chef_client} -c \"#{path_to("config/client.rb")}\" --no-color -F doc -o 'x::default'", cwd: chef_dir)
      expect(result.stdout).to match(/DIDIT: stuff/)
      result.error!
    end
  end
end