Skip to content

Commit

Permalink
add more unit tests for the md template (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Jun 21, 2023
1 parent bdc0bb2 commit 2560be5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/argoworkflow/template/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
7 changes: 7 additions & 0 deletions cmd/argoworkflow/template/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
2 changes: 2 additions & 0 deletions cmd/argoworkflow/template/workflow-output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
2 changes: 1 addition & 1 deletion cmd/argoworkflow/workflow_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions cmd/argoworkflow/workflow_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}

0 comments on commit 2560be5

Please sign in to comment.