コード例 #1
0
func TestHourlyCondition(t *testing.T) {
	d := new(conditions.Hourly)

	when := new(api.RuleWhen)
	facts := new(api.RuleFacts)
	rule := new(api.Rule)

	if !d.Evaluate(when, facts, rule) {
		t.Errorf("Hourly Condition: Evaluation failed")
	}

	rule.LastRun = tests.NewTime("now")
	if d.Evaluate(when, facts, rule) {
		t.Errorf("Hourly Condition: Evaluation failed")
	}

	rule.LastRun = tests.NewTime("a_minute_Ago")
	if d.Evaluate(when, facts, rule) {
		t.Errorf("Hourly Condition: Evaluation failed")
	}

	rule.LastRun = tests.NewTime("hour_ago")
	if !d.Evaluate(when, facts, rule) {
		t.Errorf("Hourly Condition: Evaluation failed")
	}

	rule.LastRun = tests.NewTime("2hours_ago")
	if !d.Evaluate(when, facts, rule) {
		t.Errorf("Hourly Condition: Evaluation failed")
	}
}
コード例 #2
0
func TestDailyCondition(t *testing.T) {
	d := new(conditions.Daily)

	when := new(api.RuleWhen)
	facts := new(api.RuleFacts)
	rule := new(api.Rule)

	if !d.Evaluate(when, facts, rule) {
		t.Errorf("Daily Condition: Evaluation failed")
	}

	rule.LastRun = tests.NewTime("now")
	if d.Evaluate(when, facts, rule) {
		t.Errorf("Daily Condition: Evaluation failed")
	}

	rule.LastRun = tests.NewTime("yesterday")
	if !d.Evaluate(when, facts, rule) {
		t.Errorf("Daily Condition: Evaluation failed")
	}
}