forked from jlelse/GoBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_test.go
48 lines (39 loc) · 1.09 KB
/
export_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_export(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
_ = app.initConfig(false)
app.initMarkdown()
err := app.db.savePost(&post{
Path: "/test/abc",
Content: "ABC",
Blog: "en",
Section: "test",
Status: statusDraft,
Parameters: map[string][]string{
"title": {"Title"},
},
}, &postCreationOptions{new: true})
require.NoError(t, err)
exportPath := filepath.Join(t.TempDir(), "export")
err = app.exportMarkdownFiles(exportPath)
require.NoError(t, err)
exportFilePath := filepath.Join(exportPath, "/test/abc.md")
require.FileExists(t, exportFilePath)
fileContentBytes, err := os.ReadFile(exportFilePath)
require.NoError(t, err)
fileContent := string(fileContentBytes)
assert.Contains(t, fileContent, `path: /test/abc`)
assert.Contains(t, fileContent, `title: Title`)
assert.Contains(t, fileContent, `updated: ""`)
assert.Contains(t, fileContent, `published: ""`)
assert.Contains(t, fileContent, `ABC`)
}