aboutsummaryrefslogtreecommitdiffstats
path: root/modules/structs/issue_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/structs/issue_test.go')
-rw-r--r--modules/structs/issue_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/modules/structs/issue_test.go b/modules/structs/issue_test.go
index 5312585d0f..72b40f7cf2 100644
--- a/modules/structs/issue_test.go
+++ b/modules/structs/issue_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
+ "gopkg.in/yaml.v3"
)
func TestIssueTemplate_Type(t *testing.T) {
@@ -41,3 +42,65 @@ func TestIssueTemplate_Type(t *testing.T) {
})
}
}
+
+func TestIssueTemplateLabels_UnmarshalYAML(t *testing.T) {
+ tests := []struct {
+ name string
+ content string
+ tmpl *IssueTemplate
+ want *IssueTemplate
+ wantErr string
+ }{
+ {
+ name: "array",
+ content: `labels: ["a", "b", "c"]`,
+ tmpl: &IssueTemplate{
+ Labels: []string{"should_be_overwrote"},
+ },
+ want: &IssueTemplate{
+ Labels: []string{"a", "b", "c"},
+ },
+ },
+ {
+ name: "string",
+ content: `labels: "a,b,c"`,
+ tmpl: &IssueTemplate{
+ Labels: []string{"should_be_overwrote"},
+ },
+ want: &IssueTemplate{
+ Labels: []string{"a", "b", "c"},
+ },
+ },
+ {
+ name: "empty",
+ content: `labels:`,
+ tmpl: &IssueTemplate{
+ Labels: []string{"should_be_overwrote"},
+ },
+ want: &IssueTemplate{
+ Labels: nil,
+ },
+ },
+ {
+ name: "error",
+ content: `
+labels:
+ a: aa
+ b: bb
+`,
+ tmpl: &IssueTemplate{},
+ wantErr: "line 3: cannot unmarshal !!map into IssueTemplateLabels",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := yaml.Unmarshal([]byte(tt.content), tt.tmpl)
+ if tt.wantErr != "" {
+ assert.EqualError(t, err, tt.wantErr)
+ } else {
+ assert.NoError(t, err)
+ assert.Equal(t, tt.want, tt.tmpl)
+ }
+ })
+ }
+}