From 98eede77f5ea72e3970c91b4efe0e50c3671d82d Mon Sep 17 00:00:00 2001 From: rick Date: Wed, 21 Jun 2023 16:46:10 +0800 Subject: [PATCH] add more unit tests for the md template --- cmd/argoworkflow/template/comment.go | 2 +- cmd/argoworkflow/template/comment_test.go | 7 +++++++ cmd/argoworkflow/template/workflow-output.go | 2 ++ cmd/argoworkflow/workflow_output.go | 2 +- cmd/argoworkflow/workflow_output_test.go | 12 ++++++++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cmd/argoworkflow/template/comment.go b/cmd/argoworkflow/template/comment.go index 9ae134d..4fa1a4d 100644 --- a/cmd/argoworkflow/template/comment.go +++ b/cmd/argoworkflow/template/comment.go @@ -24,7 +24,7 @@ Please feel free to check the following outputs: {{- end}} {{- end}} -{{- range $name, $output := .}} +{{ range $name, $output := .}} {{- if eq "markdown" (toString $output.Kind)}} {{$output.Value}} {{- end}} diff --git a/cmd/argoworkflow/template/comment_test.go b/cmd/argoworkflow/template/comment_test.go index f3cd42b..8f682b0 100644 --- a/cmd/argoworkflow/template/comment_test.go +++ b/cmd/argoworkflow/template/comment_test.go @@ -86,6 +86,10 @@ func TestOutput(t *testing.T) { Kind: template.ValueOutput, Value: "ghcr.io/linuxsuren/gogit", } + objects["report_md"] = template.OutputObject{ + Kind: template.MarkdownOutput, + Value: "## title", + } result, err := template.RenderTemplate(template.OutputsTemplate, objects) assert.Nil(t, err) @@ -96,5 +100,8 @@ Please feel free to check the following outputs: |---| | string: ghcr.io/linuxsuren/gogit | | [install.yaml](https://github.com) | + + +## title `, result, result) } diff --git a/cmd/argoworkflow/template/workflow-output.go b/cmd/argoworkflow/template/workflow-output.go index 336b04c..0f80a02 100644 --- a/cmd/argoworkflow/template/workflow-output.go +++ b/cmd/argoworkflow/template/workflow-output.go @@ -17,4 +17,6 @@ const ( FileOutput OutputObjectKind = "file" // ValueOutput represents a string value ValueOutput OutputObjectKind = "string" + // MarkdownOutput represents a markdown format string value + MarkdownOutput OutputObjectKind = "markdown" ) diff --git a/cmd/argoworkflow/workflow_output.go b/cmd/argoworkflow/workflow_output.go index eb9c7a5..fbf22df 100644 --- a/cmd/argoworkflow/workflow_output.go +++ b/cmd/argoworkflow/workflow_output.go @@ -58,7 +58,7 @@ func GetOutputsWithTarget(wf *wfv1.Workflow, target string) map[string]template. if output.File != "" { output.File = target + output.File } else if strings.HasSuffix(i, "_md") { - output.Kind = "markdown" + output.Kind = template.MarkdownOutput } outputs[i] = output } diff --git a/cmd/argoworkflow/workflow_output_test.go b/cmd/argoworkflow/workflow_output_test.go index 949de4a..63d0fed 100644 --- a/cmd/argoworkflow/workflow_output_test.go +++ b/cmd/argoworkflow/workflow_output_test.go @@ -5,6 +5,7 @@ import ( "testing" wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" + "github.com/linuxsuren/gogit/argoworkflow/template" "github.com/stretchr/testify/assert" ) @@ -51,4 +52,15 @@ func TestGetOutputsWithTarget(t *testing.T) { assert.Equal(t, "## Report\n", output.Value) } } + assert.Equal(t, map[string]template.OutputObject{ + "test-test": { + Kind: template.FileOutput, + File: "https://github.com/artifact-files//workflows///outputs/test", + FileName: "test/install.yaml", + }, + "report_md-report_md": { + Kind: template.MarkdownOutput, + Value: "## Report\n", + }, + }, outputs) }