summaryrefslogtreecommitdiff
path: root/tests/server-tests/helpers/files_helper.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-08-29 16:35:14 -0700
committerelijah <elijah@riseup.net>2016-09-01 10:13:31 -0700
commit07c0e60e6bdc5b8bfe1f42f76dae9f0a79e7abb0 (patch)
tree9f79f8fbb207896dcfe38f24831d9b2b857199a4 /tests/server-tests/helpers/files_helper.rb
parentd5bac5850e4a895da5f9cfacb641fab15de1cf7b (diff)
moved infrastructure tests run by `leap run` to tests/server-tests
Diffstat (limited to 'tests/server-tests/helpers/files_helper.rb')
-rw-r--r--tests/server-tests/helpers/files_helper.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/server-tests/helpers/files_helper.rb b/tests/server-tests/helpers/files_helper.rb
new file mode 100644
index 00000000..d6795889
--- /dev/null
+++ b/tests/server-tests/helpers/files_helper.rb
@@ -0,0 +1,54 @@
+class LeapTest
+
+ #
+ # Matches the regexp in the file, and returns the first matched string (or fails if no match).
+ #
+ def file_match(filename, regexp)
+ if match = File.read(filename).match(regexp)
+ match.captures.first
+ else
+ fail "Regexp #{regexp.inspect} not found in file #{filename.inspect}."
+ end
+ end
+
+ #
+ # Matches the regexp in the file, and returns array of matched strings (or fails if no match).
+ #
+ def file_matches(filename, regexp)
+ if match = File.read(filename).match(regexp)
+ match.captures
+ else
+ fail "Regexp #{regexp.inspect} not found in file #{filename.inspect}."
+ end
+ end
+
+ #
+ # checks to make sure the given property path exists in $node (e.g. hiera.yaml)
+ # and returns the value
+ #
+ def assert_property(property)
+ latest = $node
+ property.split('.').each do |segment|
+ latest = latest[segment]
+ fail "Required node property `#{property}` is missing." if latest.nil?
+ end
+ return latest
+ end
+
+ #
+ # a handy function to get the value of a long property path
+ # without needing to test the existance individually of each part
+ # in the tree.
+ #
+ # e.g. property("stunnel.clients.couch_client")
+ #
+ def property(property)
+ latest = $node
+ property.split('.').each do |segment|
+ latest = latest[segment]
+ return nil if latest.nil?
+ end
+ return latest
+ end
+
+end \ No newline at end of file