diff --git a/makefile b/makefile index c2eff9a..66a61a1 100644 --- a/makefile +++ b/makefile @@ -2,8 +2,8 @@ test: test-unit test-integration -#test-unit: - #go test ./test/test_unit/... +test-unit: + go test ./test/test_unit/... test-integration: go test ./test/test_integration/... diff --git a/test/test_unit/frontmatter_test.go b/test/test_unit/frontmatter_test.go new file mode 100644 index 0000000..5056cc6 --- /dev/null +++ b/test/test_unit/frontmatter_test.go @@ -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") +}