Add tests for certificate expiration
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)
+ }
+}
