diff options
author | Micah Anderson <micah@leap.se> | 2014-12-23 16:47:35 -0500 |
---|---|---|
committer | Micah Anderson <micah@leap.se> | 2014-12-23 16:47:35 -0500 |
commit | 574a0554a95ba74867ebd0ca4a93195bfa104c14 (patch) | |
tree | fd07b5b2ec8b32e82aa665dad117ee6e51791884 /tests/helpers/files_helper.rb | |
parent | 126faf8606f4911ccc3c1f55a9e0f381a46d536a (diff) | |
parent | fc9a8af17d927085486052a53233401c42b0caab (diff) |
Merge branch 'develop'
Conflicts:
platform.rb
Change-Id: Ic2e08e594d29a585691341c8667ac0b64933a505
Diffstat (limited to 'tests/helpers/files_helper.rb')
-rw-r--r-- | tests/helpers/files_helper.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/helpers/files_helper.rb b/tests/helpers/files_helper.rb new file mode 100644 index 00000000..d6795889 --- /dev/null +++ b/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 |