rspec-puppet-augeas 0.1.0 → 0.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.
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# RSpec tests for Augeas resources inside Puppet manifests
|
2
2
|
|
3
|
-
## Summary
|
4
|
-
|
5
3
|
rspec-puppet-augeas is an extension of rodjek's popular rspec-puppet tool. It
|
6
4
|
adds to your RSpec tests for a single class or define (or anything resulting in
|
7
5
|
a catalog) and allows you to run and test individual Augeas resources within it.
|
@@ -109,6 +107,19 @@ the resource. Some require certain options, which can be supplied in the
|
|
109
107
|
`:target` and `:lens`), returns the value of the node
|
110
108
|
* `aug_match(path)` runs `Augeas#match(path)` against the target file (expects
|
111
109
|
`:target` and `:lens`), returns an array of matches
|
110
|
+
* `augparse(result)` runs the augparse utility against the target file (expects
|
111
|
+
`:target` and `:lens`) and verifies the file matches the `{ "key" = "value"
|
112
|
+
}` augparse tree notation. Call without an argument to get the current tree
|
113
|
+
back.
|
114
|
+
* `augparse()` raises error containing `{ "key" = "value" }` tree for the
|
115
|
+
whole file
|
116
|
+
* `augparse('{ "key" = "value" }')` verifies the target matches supplied tree
|
117
|
+
* `augparse_filter(filter, result)` takes the target file and all nodes matching
|
118
|
+
the given filter, then runs the resulting file through augparse as above.
|
119
|
+
* `augparse_filter('*[label()!="#comment"]')` raises error containing tree for
|
120
|
+
the filtered file (all non-comment entries)
|
121
|
+
* `augparse_filter('*[label()!="#comment"]', '{ "key" = "value" }')` verifies
|
122
|
+
the filtered file (all non-comment entries) matches supplied tree
|
112
123
|
|
113
124
|
### RSpec configuration
|
114
125
|
|
@@ -14,9 +14,10 @@ module RSpec::Puppet::Augeas
|
|
14
14
|
# :lens => lens used for opening target
|
15
15
|
def run_augeas(*args, &block)
|
16
16
|
options = args.last.is_a?(::Hash) ? args.pop : {}
|
17
|
+
args << { :type => :augeas }
|
17
18
|
|
18
19
|
title = "Augeas[#{args.shift}]"
|
19
|
-
describe(title, *args
|
20
|
+
describe(title, *args) do
|
20
21
|
# inside here (the type augeas block), subject will be initialised
|
21
22
|
# to the augeas resource object
|
22
23
|
|
@@ -30,8 +30,9 @@ module RSpec::Puppet::Augeas
|
|
30
30
|
file = "/#{file}" unless file.start_with? '/'
|
31
31
|
lens = opts[:lens] || self.lens or raise ArgumentError, ":lens must be supplied"
|
32
32
|
lens = "#{lens}.lns" unless lens.include? '.'
|
33
|
+
root = opts[:root] || self.output_root
|
33
34
|
|
34
|
-
aug = Augeas.open(
|
35
|
+
aug = Augeas.open(root, nil, Augeas::NO_MODL_AUTOLOAD)
|
35
36
|
begin
|
36
37
|
aug.transform(
|
37
38
|
:lens => lens,
|
@@ -57,15 +58,14 @@ module RSpec::Puppet::Augeas
|
|
57
58
|
end
|
58
59
|
|
59
60
|
# Creates a simple test file, reads in a fixture (that's been modified by
|
60
|
-
# the
|
61
|
-
def augparse(opts = {})
|
61
|
+
# the resource) and runs augparse against the expected tree.
|
62
|
+
def augparse(result = "?", opts = {})
|
62
63
|
file = opts[:target] || self.target or raise ArgumentError, ":target must be supplied"
|
63
|
-
file = File.join(self.
|
64
|
+
file = File.join(self.output_root, file) unless file.start_with? '/'
|
64
65
|
lens = opts[:lens] || self.lens or raise ArgumentError, ":lens must be supplied"
|
65
66
|
lens = "#{lens}.lns" unless lens.include? '.'
|
66
|
-
result = opts[:result] || "?"
|
67
67
|
|
68
|
-
Dir.mktmpdir
|
68
|
+
Dir.mktmpdir("rpa-augparse") do |dir|
|
69
69
|
# Augeas always starts with a blank line when creating new files, so
|
70
70
|
# reprocess file and remove it to make writing tests easier
|
71
71
|
File.open("#{dir}/input", "w") do |finput|
|
@@ -77,18 +77,18 @@ module RSpec::Puppet::Augeas
|
|
77
77
|
end
|
78
78
|
|
79
79
|
# Test module, Augeas reads back in the input file
|
80
|
-
testaug = "#{dir}/
|
81
|
-
File.open(testaug, "w")
|
80
|
+
testaug = "#{dir}/test_rspec_puppet_augeas.aug"
|
81
|
+
File.open(testaug, "w") do |tf|
|
82
82
|
tf.write(<<eos)
|
83
|
-
module
|
83
|
+
module Test_Rspec_Puppet_Augeas =
|
84
84
|
test #{lens} get Sys.read_file "#{dir}/input" =
|
85
85
|
#{result}
|
86
86
|
eos
|
87
|
-
|
87
|
+
end
|
88
88
|
|
89
89
|
output = %x(augparse #{testaug} 2>&1)
|
90
90
|
raise RSpec::Puppet::Augeas::Error, "augparse failed:\n#{output}" unless $? == 0 && output.empty?
|
91
|
-
|
91
|
+
end
|
92
92
|
end
|
93
93
|
|
94
94
|
# Takes a full fixture file, loads it in Augeas, uses the relative path
|
@@ -98,23 +98,21 @@ eos
|
|
98
98
|
#
|
99
99
|
# Because the filtered fragment is saved in a new file, seq labels will reset
|
100
100
|
# too, so it'll be "1" rather than what it was in the original fixture.
|
101
|
-
def augparse_filter(opts = {})
|
101
|
+
def augparse_filter(filter = "*[label()!='#comment']", result = "?", opts = {})
|
102
102
|
file = opts[:target] || self.target or raise ArgumentError, ":target must be supplied"
|
103
|
-
file = File.join(self.
|
103
|
+
file = File.join(self.output_root, file) unless file.start_with? '/'
|
104
104
|
lens = opts[:lens] || self.lens or raise ArgumentError, ":lens must be supplied"
|
105
105
|
lens = "#{lens}.lns" unless lens.include? '.'
|
106
|
-
filter = opts[:filter] or raise ArgumentError, ":filter must be supplied"
|
107
|
-
result = opts[:result] || "?"
|
108
106
|
|
109
107
|
# duplicate the original since we use aug.mv
|
110
|
-
tmpin = Tempfile.new("original")
|
108
|
+
tmpin = Tempfile.new("rpa-original")
|
111
109
|
tmpin.write(File.read(file))
|
112
110
|
tmpin.close
|
113
111
|
|
114
|
-
tmpout = Tempfile.new("filtered")
|
112
|
+
tmpout = Tempfile.new("rpa-filtered")
|
115
113
|
tmpout.close
|
116
114
|
|
117
|
-
aug_open(tmpin.path
|
115
|
+
aug_open(opts.merge(:root => '/', :target => tmpin.path)) do |aug|
|
118
116
|
# Load a transform of the target, so Augeas can write into it
|
119
117
|
aug.transform(
|
120
118
|
:lens => lens,
|
@@ -139,10 +137,10 @@ eos
|
|
139
137
|
aug.save!
|
140
138
|
end
|
141
139
|
|
142
|
-
augparse(
|
140
|
+
augparse(result, opts.merge(:root => '/', :target => tmpout.path))
|
143
141
|
ensure
|
144
|
-
tmpin.unlink
|
145
|
-
tmpout.unlink
|
142
|
+
tmpin.unlink if tmpin
|
143
|
+
tmpout.unlink if tmpout
|
146
144
|
end
|
147
145
|
end
|
148
146
|
end
|
data/rspec-puppet-augeas.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'rspec-puppet-augeas'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.2.0'
|
4
4
|
s.homepage = 'https://github.com/domcleal/rspec-puppet-augeas/'
|
5
5
|
s.summary = 'RSpec tests for Augeas resources in Puppet manifests'
|
6
6
|
s.description = 'RSpec tests for Augeas resources in Puppet manifests'
|
@@ -55,4 +55,27 @@ describe 'sshd' do
|
|
55
55
|
should_not execute.idempotently
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
describe 'augparse' do
|
60
|
+
describe_augeas 'root login', :lens => 'Sshd', :target => 'etc/ssh/sshd_config', :fixture => 'etc/ssh/sshd_config_2' do
|
61
|
+
it 'should run augparse against the whole file' do
|
62
|
+
should execute.with_change
|
63
|
+
augparse('
|
64
|
+
{ "#comment" = "Fixture 2" }
|
65
|
+
{ "PermitRootLogin" = "yes" }
|
66
|
+
')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'augparse_filter' do
|
72
|
+
describe_augeas 'root login', :lens => 'Sshd', :target => 'etc/ssh/sshd_config', :fixture => 'etc/ssh/sshd_config_2' do
|
73
|
+
it 'should filter non-comments' do
|
74
|
+
should execute.with_change
|
75
|
+
augparse_filter('*[label() != "#comment"]', '
|
76
|
+
{ "PermitRootLogin" = "yes" }
|
77
|
+
')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
58
81
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-puppet-augeas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-puppet
|