Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / deprecation_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper_acceptance'
3
4 describe 'deprecation function' do
5
6   if fact('operatingsystem') == 'windows'
7     test_file = 'C:/deprecation'
8     else
9     test_file = "/tmp/deprecation"
10   end
11
12   # It seems that Windows needs everything to be on one line when using puppet apply -e, otherwise the manifests would be in an easier format
13   add_file_manifest = "\"deprecation('key', 'message') file { '#{test_file}': ensure => present, content => 'test', }\""
14   remove_file_manifest = "file { '#{test_file}': ensure => absent }"
15
16   before :all do
17     apply_manifest(remove_file_manifest)
18   end
19
20   context 'with --strict=error', if: get_puppet_version =~ /^4/ do
21     before :all do
22       @result = on(default, puppet('apply', '--strict=error', '-e', add_file_manifest), acceptable_exit_codes: (0...256))
23     end
24
25     after :all do
26       apply_manifest(remove_file_manifest)
27     end
28
29     it "should return an error" do
30       expect(@result.exit_code).to eq(1)
31     end
32
33     it "should show the error message" do
34       expect(@result.stderr).to match(/deprecation. key. message/)
35     end
36
37     describe file("#{test_file}") do
38       it { is_expected.not_to be_file }
39     end
40   end
41
42   context 'with --strict=warning', if: get_puppet_version =~ /^4/ do
43     before :all do
44       @result = on(default, puppet('apply', '--strict=warning', '-e', add_file_manifest), acceptable_exit_codes: (0...256))
45     end
46
47     after :all do
48       apply_manifest(remove_file_manifest)
49     end
50
51     it "should not return an error" do
52       expect(@result.exit_code).to eq(0)
53     end
54
55     it "should show the error message" do
56       expect(@result.stderr).to match(/Warning: message/)
57     end
58
59     describe file("#{test_file}") do
60       it { is_expected.to be_file }
61     end
62   end
63
64   context 'with --strict=off', if: get_puppet_version =~ /^4/ do
65     before :all do
66       @result = on(default, puppet('apply', '--strict=off', '-e', add_file_manifest), acceptable_exit_codes: (0...256))
67     end
68
69     after :all do
70       apply_manifest(remove_file_manifest)
71     end
72
73     it "should not return an error" do
74       expect(@result.exit_code).to eq(0)
75     end
76
77     it "should not show the error message" do
78       expect(@result.stderr).not_to match(/Warning: message/)
79     end
80
81     describe file("#{test_file}") do
82       it { is_expected.to be_file }
83     end
84   end
85
86   context 'puppet 3 test', if: get_puppet_version =~ /^3/ do
87     before :all do
88       @result = on(default, puppet('apply', '--parser=future', '-e', add_file_manifest), acceptable_exit_codes: (0...256))
89     end
90     after :all do
91       apply_manifest(remove_file_manifest)
92     end
93
94     it "should return a deprecation error" do
95       expect(@result.stderr).to match(/Warning: message/)
96     end
97     it "should pass without error" do
98       expect(@result.exit_code).to eq(0)
99     end
100   end
101
102 end