puppet-spec 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfe83006bafdc547d6c9273c69557da9e14c997b
4
- data.tar.gz: d96e02b801e4f3ceb54cef275a0b91a68dec29f5
3
+ metadata.gz: 235b2bbf4bd9e7d42aff30c8ec7ff5cf64d87189
4
+ data.tar.gz: 7aebec24c0d8276c6be27af2b746d8884495801a
5
5
  SHA512:
6
- metadata.gz: f2c2b240d52d96c39bad354306d011fccdc82e002fccb7a34730f12fdca12ce2cc8cd7395464fbd49ef60ad6d4c093074ffef804307f10c60d9ef3ea796ec848
7
- data.tar.gz: 6b0cc48d798e60fca66f146c59e59be7b1b6770cf1949e0036a6fc11ca04870ab097c430d70ba646396bc677836380f95f7cc5e0af66026bc078eef74230762b
6
+ metadata.gz: bdf5de9148748ea6594c57aed746293e0b191233cd4b19a353200aa039ed20316029760927cf6a04e1dd25f311b259f4ec15aac481e3ba23a33a5d6232da443f
7
+ data.tar.gz: 4da0b54e7ff2e0a58b1a7888857abb315c874adca3227f716b7b6a527ec2c7240487a7788f8e1933a18f31a38bb175d8c049f589ba72a51c77be820563c5d9f0
@@ -45,14 +45,9 @@ class Puppet::Application::Spec < Puppet::Application
45
45
  # reference provided from the parser. The reference's resource
46
46
  # object does not contain any parameters for whatever reason.
47
47
  catalog_subject = catalog.resource(res[:subject].to_s)
48
+ res[:subject] = catalog_subject if catalog_subject
48
49
 
49
- if catalog_subject
50
- res[:subject] = catalog_subject
51
- reporter << res.to_ral
52
- else
53
- reporter.missing_subject(res)
54
- end
55
-
50
+ reporter << res.to_ral
56
51
  end
57
52
  end
58
53
 
@@ -0,0 +1,6 @@
1
+ Puppet::Parser::Functions.newfunction(:fixture, :arity => 1, :type => :rvalue) do |values|
2
+ modulepath = compiler.environment.full_modulepath[0]
3
+ file = Dir.glob("#{modulepath}/*/spec/fixtures/#{values[0]}")[0]
4
+
5
+ return File.read(file)
6
+ end
@@ -4,6 +4,8 @@ Puppet::Type.newtype(:assertion) do
4
4
 
5
5
  validate do
6
6
  fail Puppet::Error, "a subject is required" unless @parameters[:subject]
7
+ fail Puppet::Error, "an assertion on the absence of a resource cannot have an attribute" if @parameters[:attribute] and @parameters[:ensure].value == 'absent'
8
+ fail Puppet::Error, "an assertion on the absence of a resource cannot have an expectation" if @parameters[:expectation] and @parameters[:ensure].value == 'absent'
7
9
  fail Puppet::Error, "an attribute is required when an expectation is given" if @parameters[:expectation] and not @parameters[:attribute]
8
10
  fail Puppet::Error, "an expectation is required when an attribute is given" if @parameters[:attribute] and not @parameters[:expectation]
9
11
  end
@@ -35,4 +37,23 @@ Puppet::Type.newtype(:assertion) do
35
37
  desc "The expected value of the subject's attribute"
36
38
  end
37
39
 
40
+ newparam(:ensure) do
41
+ desc "If ensure is set to absent, the resource will assert for the absence of the subject in the catalog.
42
+
43
+ Defaults to present.
44
+ "
45
+
46
+ defaultto "present"
47
+
48
+ validate do |value|
49
+ fail Puppet::Error, "Ensure only accepts values 'present' or 'absent'" unless value == 'present' or value == 'absent'
50
+ end
51
+
52
+ # Stub out the retrieve method since
53
+ # the Puppet internals require any param
54
+ # named ensure to have it. Grr.
55
+ def retrieve
56
+ end
57
+ end
58
+
38
59
  end
@@ -12,15 +12,31 @@ module Puppet::Util
12
12
  @failed = 0
13
13
  end
14
14
 
15
- # Given an assertion resource, evaluate it for success
16
- # and send it to .report on failure. Increment the counter
17
- # for each resource, and the failed counter for failed resources.
15
+ # Given an assertion resource, evaluate it for success,
16
+ # and on failure, call the appropriate method responsible to render the
17
+ # message, and increment the counter(s).
18
18
  def <<(assertion)
19
19
  count
20
+
21
+ # If ensure is present, and the resource is not in the catalog
22
+ if assertion[:ensure] == 'present' and not assertion[:subject].catalog
23
+ fail
24
+ expected_present(assertion)
25
+ return
26
+
27
+ # If ensure is absent, and the resource is in the catalog
28
+ elsif assertion[:ensure] == 'absent' and assertion[:subject].catalog
29
+ fail
30
+ expected_absent(assertion)
31
+ return
32
+ end
33
+
20
34
  if assertion.provider.failed?
21
35
  fail
22
- report(assertion)
36
+ inequal_value(assertion)
37
+ return
23
38
  end
39
+
24
40
  end
25
41
 
26
42
  # Print the summary of evaluated assertions
@@ -48,12 +64,26 @@ module Puppet::Util
48
64
  end
49
65
 
50
66
  # Print the appropriate error message when an assertion's
51
- # subject is not found in the catalog. Called by the application
52
- # because the resource must be evaluated prior to calling
53
- # .to_ral to avoid the validation raising an error.
54
- def missing_subject(assertion)
55
- fail
67
+ # subject is found in the catalog but was intended to be
68
+ # absent.
69
+ def expected_absent(assertion)
70
+ # Shim the value of failed into the
71
+ # local scope in order to access it
72
+ # from the style proc.
73
+ failed = @failed
74
+
75
+ style do
76
+ red "#{failed}) Assertion #{assertion[:name]} failed on #{assertion[:subject].to_s}"
77
+ newline
78
+ blue " Subject was expected to be absent from the catalog, but was present"
79
+ newline
80
+ newline
81
+ end
82
+ end
56
83
 
84
+ # Print the appropriate error message when an assertion's
85
+ # subject is not found in the catalog.
86
+ def expected_present(assertion)
57
87
  # Shim the value of failed into the
58
88
  # local scope in order to access it
59
89
  # from the style proc.
@@ -62,14 +92,14 @@ module Puppet::Util
62
92
  style do
63
93
  red "#{failed}) Assertion #{assertion[:name]} failed on #{assertion[:subject].to_s}"
64
94
  newline
65
- blue " Subject was not in the catalog"
95
+ blue " Subject was expected to be present in the catalog, but was absent"
66
96
  newline
67
97
  newline
68
98
  end
69
99
  end
70
100
 
71
101
  # Pretty print the results of an assertion to the console
72
- def report(assertion)
102
+ def inequal_value(assertion)
73
103
  # Shim the value of failed into the
74
104
  # local scope in order to access it
75
105
  # from the style proc.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Olshevski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-09 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -47,6 +47,7 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - lib/puppet-spec/tasks.rb
49
49
  - lib/puppet/application/spec.rb
50
+ - lib/puppet/parser/functions/fixture.rb
50
51
  - lib/puppet/parser/functions/stub_class.rb
51
52
  - lib/puppet/parser/functions/stub_facts.rb
52
53
  - lib/puppet/parser/functions/stub_type.rb
@@ -80,3 +81,4 @@ signing_key:
80
81
  specification_version: 4
81
82
  summary: Test Puppet code with Puppet code
82
83
  test_files: []
84
+ has_rdoc: