aboutsummaryrefslogtreecommitdiffstats
path: root/modules/markup/markdown/meta_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/markup/markdown/meta_test.go')
-rw-r--r--modules/markup/markdown/meta_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/markup/markdown/meta_test.go b/modules/markup/markdown/meta_test.go
index 939646f8fd..9332b35b42 100644
--- a/modules/markup/markdown/meta_test.go
+++ b/modules/markup/markdown/meta_test.go
@@ -56,6 +56,38 @@ func TestExtractMetadata(t *testing.T) {
})
}
+func TestExtractMetadataBytes(t *testing.T) {
+ t.Run("ValidFrontAndBody", func(t *testing.T) {
+ var meta structs.IssueTemplate
+ body, err := ExtractMetadataBytes([]byte(fmt.Sprintf("%s\n%s\n%s\n%s", sepTest, frontTest, sepTest, bodyTest)), &meta)
+ assert.NoError(t, err)
+ assert.Equal(t, bodyTest, body)
+ assert.Equal(t, metaTest, meta)
+ assert.True(t, validateMetadata(meta))
+ })
+
+ t.Run("NoFirstSeparator", func(t *testing.T) {
+ var meta structs.IssueTemplate
+ _, err := ExtractMetadataBytes([]byte(fmt.Sprintf("%s\n%s\n%s", frontTest, sepTest, bodyTest)), &meta)
+ assert.Error(t, err)
+ })
+
+ t.Run("NoLastSeparator", func(t *testing.T) {
+ var meta structs.IssueTemplate
+ _, err := ExtractMetadataBytes([]byte(fmt.Sprintf("%s\n%s\n%s", sepTest, frontTest, bodyTest)), &meta)
+ assert.Error(t, err)
+ })
+
+ t.Run("NoBody", func(t *testing.T) {
+ var meta structs.IssueTemplate
+ body, err := ExtractMetadataBytes([]byte(fmt.Sprintf("%s\n%s\n%s", sepTest, frontTest, sepTest)), &meta)
+ assert.NoError(t, err)
+ assert.Equal(t, "", body)
+ assert.Equal(t, metaTest, meta)
+ assert.True(t, validateMetadata(meta))
+ })
+}
+
var (
sepTest = "-----"
frontTest = `name: Test