mirror of https://github.com/jlelse/GoBlog
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_postsScheduler(t *testing.T) {
|
|
|
|
updateHook, postHook := 0, 0
|
|
|
|
app := &goBlog{
|
|
cfg: createDefaultTestConfig(t),
|
|
}
|
|
app.cfg.Blogs = map[string]*configBlog{
|
|
"en": {
|
|
Sections: map[string]*configSection{
|
|
"test": {},
|
|
},
|
|
Lang: "en",
|
|
},
|
|
}
|
|
app.pPostHooks = append(app.pPostHooks, func(p *post) {
|
|
postHook++
|
|
})
|
|
app.pUpdateHooks = append(app.pUpdateHooks, func(p *post) {
|
|
updateHook++
|
|
})
|
|
|
|
_ = app.initConfig(false)
|
|
_ = app.initCache()
|
|
|
|
err := app.db.savePost(&post{
|
|
Path: "/test/abc",
|
|
Content: "ABC",
|
|
Published: toLocalSafe(time.Now().Add(-1 * time.Hour).String()),
|
|
Blog: "en",
|
|
Section: "test",
|
|
Status: statusScheduled,
|
|
Visibility: visibilityPublic,
|
|
}, &postCreationOptions{new: true})
|
|
require.NoError(t, err)
|
|
|
|
count, err := app.db.countPosts(&postsRequestConfig{status: []postStatus{statusScheduled}})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 1, count)
|
|
|
|
assert.Equal(t, 0, postHook)
|
|
assert.Equal(t, 0, updateHook)
|
|
|
|
app.checkScheduledPosts()
|
|
|
|
count, err = app.db.countPosts(&postsRequestConfig{status: []postStatus{statusScheduled}})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 0, count)
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
assert.Equal(t, 1, postHook)
|
|
assert.Equal(t, 0, updateHook)
|
|
|
|
}
|