Skip to content

Commit

Permalink
Merge pull request #147 from x-motemen/blogsync_workdir
Browse files Browse the repository at this point in the history
test enhancement
  • Loading branch information
Songmu committed Nov 12, 2023
2 parents b28b7fe + e0fdb7f commit 4c44f07
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,28 @@ func TestBlogsync(t *testing.T) {
t.Fatal(err)
}
dir := t.TempDir()
if err := os.Chdir(dir); err != nil {
dir, err = filepath.EvalSymlinks(dir)
if err != nil {
t.Fatal(err)
}

orig, ok := os.LookupEnv("BLOGSYNC_WORKDIR")
os.Setenv("BLOGSYNC_WORKDIR", dir)
defer func() {
if ok {
if err := os.Setenv("BLOGSYNC_WORKDIR", orig); err != nil {
t.Fatal(err)
}
} else {
if err := os.Unsetenv("BLOGSYNC_WORKDIR"); err != nil {
t.Fatal(err)
}
}
if err := os.Chdir(pwd); err != nil {
t.Fatal(err)
}
}()

dir, err = filepath.EvalSymlinks(dir)
if err != nil {
t.Fatal(err)
}

confYAML := fmt.Sprintf(`%s:
local_root: .
omit_domain: true
Expand Down Expand Up @@ -159,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 4c44f07

Please sign in to comment.