From de053a093c8029aabd1e1dae8ee9f192acc9775d Mon Sep 17 00:00:00 2001 From: weafscast Date: Thu, 26 Sep 2024 03:45:09 +0530 Subject: [PATCH 1/2] test: add test for expression template Signed-off-by: weafscast --- util/template/expression_template_test.go | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/util/template/expression_template_test.go b/util/template/expression_template_test.go index c5f5027502b9..4310babae2d4 100644 --- a/util/template/expression_template_test.go +++ b/util/template/expression_template_test.go @@ -34,3 +34,50 @@ func Test_hasWorkflowParameters(t *testing.T) { assert.False(t, hasWorkflowFailures("workflow .failures")) }) } + +func Test_hasVarInEnv(t *testing.T) { + t.Run("parameterExistsInEnv", func(t *testing.T) { + env := map[string]interface{}{ + "workflow": map[string]interface{}{ + "status": "Succeeded", + }, + } + assert.True(t, hasVarInEnv(env, "workflow.status")) + }) + + t.Run("parameterDoesNotExistInEnv", func(t *testing.T) { + env := map[string]interface{}{ + "workflow": map[string]interface{}{ + "status": "Succeeded", + }, + } + assert.False(t, hasVarInEnv(env, "workflow.failures")) + }) + + t.Run("emptyEnv", func(t *testing.T) { + env := map[string]interface{}{} + assert.False(t, hasVarInEnv(env, "workflow.status")) + }) + + t.Run("nestedParameterExistsInEnv", func(t *testing.T) { + env := map[string]interface{}{ + "workflow": map[string]interface{}{ + "details": map[string]interface{}{ + "status": "Succeeded", + }, + }, + } + assert.True(t, hasVarInEnv(env, "workflow.details.status")) + }) + + t.Run("nestedParameterDoesNotExistInEnv", func(t *testing.T) { + env := map[string]interface{}{ + "workflow": map[string]interface{}{ + "details": map[string]interface{}{ + "status": "Succeeded", + }, + }, + } + assert.False(t, hasVarInEnv(env, "workflow.details.failures")) + }) +} From b8a67f7bba74d8a3b20f48b8b26d2a3adf1ab81b Mon Sep 17 00:00:00 2001 From: weafscast Date: Fri, 4 Oct 2024 11:45:10 +0530 Subject: [PATCH 2/2] Update util/template/expression_template_test.go Signed-off-by: weafscast --- util/template/expression_template_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/template/expression_template_test.go b/util/template/expression_template_test.go index 4310babae2d4..697b405871bb 100644 --- a/util/template/expression_template_test.go +++ b/util/template/expression_template_test.go @@ -35,7 +35,7 @@ func Test_hasWorkflowParameters(t *testing.T) { }) } -func Test_hasVarInEnv(t *testing.T) { +func TestHasVarInEnv(t *testing.T) { t.Run("parameterExistsInEnv", func(t *testing.T) { env := map[string]interface{}{ "workflow": map[string]interface{}{