Skip to content

Commit

Permalink
add test for static pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Nov 12, 2023
1 parent 526aaa1 commit 92934d4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,34 @@ test`), 0644); err != nil {
t.Errorf("unexpected published file: %s", publishedFile)
}
})

t.Run("post static pages", func(t *testing.T) {
t.Log("Posting a static page without a custom path results in an error")
app.Reader = strings.NewReader("static\n")
if _, err := blogsync("post", "--page", blogID); err == nil {
t.Error("expected error did not occur")
}

t.Log("Posting a static page with a custom path saves the file in the specified location")
customPath := fmt.Sprintf("static-%s", time.Now().Format("20060102150405"))
app.Reader = strings.NewReader("static\n")
entryFile, err := blogsync("post", "--page", "--custom-path", customPath, blogID)
app.Reader = os.Stdin
if err != nil {
t.Fatal(err)
}
if entryFile != filepath.Join(dir, customPath+".md") {
t.Errorf("unexpected published file: %s", entryFile)
}

defer func() {
t.Log("remove the published entry")
if _, err := blogsync("remove", entryFile); err != nil {
t.Fatal(err)
}
}()
})

}

func appendFile(path string, content string) error {
Expand Down

0 comments on commit 92934d4

Please sign in to comment.