From 27c8c552a27d67406fc62ddba96b50a3c4a72652 Mon Sep 17 00:00:00 2001 From: Elouan Martinet Date: Sun, 15 Nov 2020 18:47:28 +0100 Subject: [PATCH] Add tests for certificate expiration --- core/condition_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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) + } +}