From 8d97779be86177f3e15ba8edf43fb6831c843528 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Tue, 19 Feb 2013 11:27:33 +0000 Subject: Period definitions for tests. For example: example.vm must run ping between 09-17 otherwise 'daytime ping failed'. --- lib/custodian/parser.rb | 26 ++++++++++++++++++++++++++ t/test-custodian-parser.rb | 7 +++++++ 2 files changed, 33 insertions(+) diff --git a/lib/custodian/parser.rb b/lib/custodian/parser.rb index 7ed0725..764a03b 100644 --- a/lib/custodian/parser.rb +++ b/lib/custodian/parser.rb @@ -253,6 +253,32 @@ module Custodian # return nil if ( ( line.nil? ) || ( line =~ /^#/ ) || ( line.length < 1 ) ) + # + # Look for a time period. + # + if ( line =~ /between\s+([0-9]+)-([0-9]+)/i ) + p_start = $1.dup.to_i + p_end = $2.dup.to_i + + # + # Get the current hour. + # + hour = Time.now.hour + + # + # Should we exclude the test? + # + if ( line =~ /except\s+between/i ) + if ( hour > p_start && hour < p_end ) + return nil + end + else + if ( hour < p_start || hour > p_end ) + return nil + end + end + end + # # Look for macro definitions, inline # diff --git a/t/test-custodian-parser.rb b/t/test-custodian-parser.rb index 5676d5b..811cbb5 100755 --- a/t/test-custodian-parser.rb +++ b/t/test-custodian-parser.rb @@ -49,6 +49,13 @@ class TestCustodianParser < Test::Unit::TestCase end + def test_period + parser = Custodian::Parser.new() + result = parser.parse_line( "example.vm.bytemark.co.uk must run ping except between 00-24" ) + assert( result.nil? ) + end + + # # Test the different kinds of parsing: -- cgit v1.2.1