forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add More Template Strings for Email Notifications (#24)
* Add more template strings for email notifications
- Loading branch information
1 parent
6a7b144
commit a72fb01
Showing
4 changed files
with
203 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,38 +4,127 @@ import ( | |
"fmt" | ||
"testing" | ||
|
||
"strings" | ||
|
||
"github.com/gogo/protobuf/proto" | ||
"github.com/lyft/flyteadmin/pkg/repositories/models" | ||
runtimeInterfaces "github.com/lyft/flyteadmin/pkg/runtime/interfaces" | ||
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin" | ||
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/core" | ||
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/event" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const executionProjectValue = "proj" | ||
const executionDomainValue = "prod" | ||
const executionNameValue = "e124" | ||
const launchPlanProjectValue = "lp_proj" | ||
const launchPlanDomainValue = "lp_domain" | ||
const launchPlanNameValue = "lp_name" | ||
const launchPlanVersionValue = "lp_version" | ||
const workflowProjectValue = "wf_proj" | ||
const workflowDomainValue = "wf_domain" | ||
const workflowNameValue = "wf_name" | ||
const workflowVersionValue = "wf_version" | ||
|
||
var workflowExecution = &admin.Execution{ | ||
Id: &core.WorkflowExecutionIdentifier{ | ||
Project: executionProjectValue, | ||
Domain: executionDomainValue, | ||
Name: executionNameValue, | ||
}, | ||
Spec: &admin.ExecutionSpec{ | ||
LaunchPlan: &core.Identifier{ | ||
Project: launchPlanProjectValue, | ||
Domain: launchPlanDomainValue, | ||
Name: launchPlanNameValue, | ||
Version: launchPlanVersionValue, | ||
}, | ||
}, | ||
Closure: &admin.ExecutionClosure{ | ||
WorkflowId: &core.Identifier{ | ||
Project: workflowProjectValue, | ||
Domain: workflowDomainValue, | ||
Name: workflowNameValue, | ||
Version: workflowVersionValue, | ||
}, | ||
Phase: core.WorkflowExecution_SUCCEEDED, | ||
}, | ||
} | ||
|
||
func TestSubstituteEmailParameters(t *testing.T) { | ||
message := "{{ unused }}. {{project }} and {{ domain }} and {{ name }} ended up in {{ phase }}.{{ error }}" | ||
request := admin.WorkflowExecutionEventRequest{ | ||
Event: &event.WorkflowExecutionEvent{ | ||
Phase: core.WorkflowExecution_SUCCEEDED, | ||
}, | ||
} | ||
model := models.Execution{ | ||
ExecutionKey: models.ExecutionKey{ | ||
Project: "proj", | ||
Domain: "prod", | ||
Name: "e124", | ||
}, | ||
} | ||
assert.Equal(t, "{{ unused }}. {{project }} and prod and e124 ended up in succeeded.", | ||
substituteEmailParameters(message, request, model)) | ||
substituteEmailParameters(message, request, workflowExecution)) | ||
request.Event.OutputResult = &event.WorkflowExecutionEvent_Error{ | ||
Error: &core.ExecutionError{ | ||
Message: "uh-oh", | ||
}, | ||
} | ||
assert.Equal(t, "{{ unused }}. {{project }} and prod and e124 ended up in succeeded. The execution failed with error: [uh-oh].", | ||
substituteEmailParameters(message, request, model)) | ||
substituteEmailParameters(message, request, workflowExecution)) | ||
} | ||
|
||
func TestSubstituteAllTemplates(t *testing.T) { | ||
templateVars := map[string]string{ | ||
fmt.Sprintf(substitutionParam, project): executionProjectValue, | ||
fmt.Sprintf(substitutionParam, domain): executionDomainValue, | ||
fmt.Sprintf(substitutionParam, name): executionNameValue, | ||
fmt.Sprintf(substitutionParam, launchPlanProject): launchPlanProjectValue, | ||
fmt.Sprintf(substitutionParam, launchPlanDomain): launchPlanDomainValue, | ||
fmt.Sprintf(substitutionParam, launchPlanName): launchPlanNameValue, | ||
fmt.Sprintf(substitutionParam, launchPlanVersion): launchPlanVersionValue, | ||
fmt.Sprintf(substitutionParam, workflowProject): workflowProjectValue, | ||
fmt.Sprintf(substitutionParam, workflowDomain): workflowDomainValue, | ||
fmt.Sprintf(substitutionParam, workflowName): workflowNameValue, | ||
fmt.Sprintf(substitutionParam, workflowVersion): workflowVersionValue, | ||
fmt.Sprintf(substitutionParam, phase): strings.ToLower(core.WorkflowExecution_SUCCEEDED.String()), | ||
} | ||
var messageTemplate, desiredResult []string | ||
for template, result := range templateVars { | ||
messageTemplate = append(messageTemplate, template) | ||
desiredResult = append(desiredResult, result) | ||
} | ||
request := admin.WorkflowExecutionEventRequest{ | ||
Event: &event.WorkflowExecutionEvent{ | ||
Phase: core.WorkflowExecution_SUCCEEDED, | ||
}, | ||
} | ||
assert.Equal(t, strings.Join(desiredResult, ","), | ||
substituteEmailParameters(strings.Join(messageTemplate, ","), request, workflowExecution)) | ||
} | ||
|
||
func TestSubstituteAllTemplatesNoSpaces(t *testing.T) { | ||
templateVars := map[string]string{ | ||
fmt.Sprintf(substitutionParamNoSpaces, project): executionProjectValue, | ||
fmt.Sprintf(substitutionParamNoSpaces, domain): executionDomainValue, | ||
fmt.Sprintf(substitutionParamNoSpaces, name): executionNameValue, | ||
fmt.Sprintf(substitutionParamNoSpaces, launchPlanProject): launchPlanProjectValue, | ||
fmt.Sprintf(substitutionParamNoSpaces, launchPlanDomain): launchPlanDomainValue, | ||
fmt.Sprintf(substitutionParamNoSpaces, launchPlanName): launchPlanNameValue, | ||
fmt.Sprintf(substitutionParamNoSpaces, launchPlanVersion): launchPlanVersionValue, | ||
fmt.Sprintf(substitutionParamNoSpaces, workflowProject): workflowProjectValue, | ||
fmt.Sprintf(substitutionParamNoSpaces, workflowDomain): workflowDomainValue, | ||
fmt.Sprintf(substitutionParamNoSpaces, workflowName): workflowNameValue, | ||
fmt.Sprintf(substitutionParamNoSpaces, workflowVersion): workflowVersionValue, | ||
fmt.Sprintf(substitutionParamNoSpaces, phase): strings.ToLower(core.WorkflowExecution_SUCCEEDED.String()), | ||
} | ||
var messageTemplate, desiredResult []string | ||
for template, result := range templateVars { | ||
messageTemplate = append(messageTemplate, template) | ||
desiredResult = append(desiredResult, result) | ||
} | ||
request := admin.WorkflowExecutionEventRequest{ | ||
Event: &event.WorkflowExecutionEvent{ | ||
Phase: core.WorkflowExecution_SUCCEEDED, | ||
}, | ||
} | ||
assert.Equal(t, strings.Join(desiredResult, ","), | ||
substituteEmailParameters(strings.Join(messageTemplate, ","), request, workflowExecution)) | ||
} | ||
|
||
func TestToEmailMessageFromWorkflowExecutionEvent(t *testing.T) { | ||
|
@@ -58,14 +147,7 @@ func TestToEmailMessageFromWorkflowExecutionEvent(t *testing.T) { | |
Phase: core.WorkflowExecution_ABORTED, | ||
}, | ||
} | ||
model := models.Execution{ | ||
ExecutionKey: models.ExecutionKey{ | ||
Project: "proj", | ||
Domain: "prod", | ||
Name: "e124", | ||
}, | ||
} | ||
emailMessage := ToEmailMessageFromWorkflowExecutionEvent(notificationsConfig, emailNotification, request, model) | ||
emailMessage := ToEmailMessageFromWorkflowExecutionEvent(notificationsConfig, emailNotification, request, workflowExecution) | ||
assert.True(t, proto.Equal(emailMessage, &admin.EmailMessage{ | ||
RecipientsEmail: []string{ | ||
"[email protected]", "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters