Skip to content

Commit

Permalink
test enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Nov 12, 2023
1 parent de3db55 commit e0fdb7f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ func TestBlogsync(t *testing.T) {
t.Skip("BLOGSYNC_TEST_BLOG not set")
}

pwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
dir := t.TempDir()
dir, err := filepath.EvalSymlinks(dir)
dir, err = filepath.EvalSymlinks(dir)
if err != nil {
t.Fatal(err)
}
Expand All @@ -49,9 +53,16 @@ func TestBlogsync(t *testing.T) {
os.Setenv("BLOGSYNC_WORKDIR", dir)
defer func() {
if ok {
os.Setenv("BLOGSYNC_WORKDIR", orig)
if err := os.Setenv("BLOGSYNC_WORKDIR", orig); err != nil {
t.Fatal(err)
}
} else {
os.Unsetenv("BLOGSYNC_WORKDIR")
if err := os.Unsetenv("BLOGSYNC_WORKDIR"); err != nil {
t.Fatal(err)
}
}
if err := os.Chdir(pwd); err != nil {
t.Fatal(err)
}
}()

Expand Down Expand Up @@ -156,6 +167,10 @@ func TestBlogsync(t *testing.T) {
entryFile = draftFile

t.Log("Check if the draft is fetched and saved in the proper location")
oldTime := time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)
if err := os.Chtimes(entryFile, oldTime, oldTime); err != nil {
t.Fatal(err)
}
if _, err := blogsync("fetch", entryFile); err != nil {
t.Error(err)
}
Expand Down

0 comments on commit e0fdb7f

Please sign in to comment.