diff --git a/core/condition_test.go b/core/condition_test.go index 5ec95e25..d4e929df 100644 --- a/core/condition_test.go +++ b/core/condition_test.go @@ -1,6 +1,7 @@ package core import ( + "strconv" "testing" "time" ) @@ -309,3 +310,32 @@ func TestCondition_evaluateWithConnectedFailure(t *testing.T) { t.Errorf("Condition '%s' should have been a failure", condition) } } + +func TestCondition_evaluateWithUnsetCertificateExpiration(t *testing.T) { + condition := Condition("[CERTIFICATE_EXPIRATION] == 0") + result := &Result{} + condition.evaluate(result) + if !result.ConditionResults[0].Success { + t.Errorf("Condition '%s' should have been a success", condition) + } +} + +func TestCondition_evaluateWithCertificateExpirationGreaterThan(t *testing.T) { + acceptable := (time.Hour * 24 * 28).Milliseconds() + condition := Condition("[CERTIFICATE_EXPIRATION] > " + strconv.FormatInt(acceptable, 10)) + result := &Result{CertificateExpiration: time.Hour * 24 * 60} + condition.evaluate(result) + if !result.ConditionResults[0].Success { + t.Errorf("Condition '%s' should have been a success", condition) + } +} + +func TestCondition_evaluateWithCertificateExpirationGreaterThanFailure(t *testing.T) { + acceptable := (time.Hour * 24 * 28).Milliseconds() + condition := Condition("[CERTIFICATE_EXPIRATION] > " + strconv.FormatInt(acceptable, 10)) + result := &Result{CertificateExpiration: time.Hour * 24 * 14} + condition.evaluate(result) + if result.ConditionResults[0].Success { + t.Errorf("Condition '%s' should have been a failure", condition) + } +}