fix(unit_test): frontmatter parse test
This commit is contained in:
parent
a2a6c2743c
commit
d4c922ba53
2 changed files with 35 additions and 2 deletions
4
makefile
4
makefile
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
test: test-unit test-integration
|
test: test-unit test-integration
|
||||||
|
|
||||||
#test-unit:
|
test-unit:
|
||||||
#go test ./test/test_unit/...
|
go test ./test/test_unit/...
|
||||||
|
|
||||||
test-integration:
|
test-integration:
|
||||||
go test ./test/test_integration/...
|
go test ./test/test_integration/...
|
||||||
|
|
|
||||||
33
test/test_unit/frontmatter_test.go
Normal file
33
test/test_unit/frontmatter_test.go
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
package filehandling
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
filehandling "github.com/KristianJBorgwarth/dendrite.daemon/core/file_handling"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseTags_ValidFrontMatter_ReturnsTags(t *testing.T) {
|
||||||
|
input := `---
|
||||||
|
title: My Note
|
||||||
|
tags: ["test", "note"]
|
||||||
|
---
|
||||||
|
This is the content of the note.`
|
||||||
|
|
||||||
|
result, err := filehandling.ParseFrontMatter([]byte(input))
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "My Note", result.Title)
|
||||||
|
assert.Equal(t, []string{"test", "note"}, result.Tags)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseTags_MissingDelimiter_ReturnsError(t *testing.T) {
|
||||||
|
input := `title: My Note
|
||||||
|
tags: ["test", "note"]
|
||||||
|
This is the content of the note.`
|
||||||
|
|
||||||
|
_, err := filehandling.ParseFrontMatter([]byte(input))
|
||||||
|
|
||||||
|
assert.ErrorContains(t, err, "missing front matter delimiter")
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue