mirror of https://github.com/jlelse/GoBlog
Add default pagination (Fixes #48)
This commit is contained in:
parent
032d994b80
commit
57cc3dd94d
|
@ -386,7 +386,6 @@ func (a *goBlog) initConfig(logging bool) error {
|
|||
if err := a.initDatabase(logging); err != nil {
|
||||
return err
|
||||
}
|
||||
// Check config
|
||||
// Parse addresses and hostnames
|
||||
if a.cfg.Server.PublicAddress == "" {
|
||||
return errors.New("no public address configured")
|
||||
|
@ -505,6 +504,10 @@ func (a *goBlog) initConfig(logging bool) error {
|
|||
}
|
||||
// Check config for each blog
|
||||
for blog, bc := range a.cfg.Blogs {
|
||||
// Check pagination
|
||||
if bc.Pagination == 0 {
|
||||
bc.Pagination = 10
|
||||
}
|
||||
// Check sections and add section if none exists
|
||||
if len(bc.Sections) == 0 {
|
||||
bc.Sections = createDefaultSections()
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func createDefaultTestConfig(t *testing.T) *config {
|
||||
|
@ -138,3 +139,16 @@ func Test_configHttps(t *testing.T) {
|
|||
})
|
||||
|
||||
}
|
||||
|
||||
func Test_configDefaults(t *testing.T) {
|
||||
t.Run("Pagination", func(t *testing.T) {
|
||||
app := &goBlog{}
|
||||
err := app.initConfig(false)
|
||||
require.NoError(t, err)
|
||||
if assert.Len(t, app.cfg.Blogs, 1) {
|
||||
for _, bc := range app.cfg.Blogs {
|
||||
assert.Equal(t, 10, bc.Pagination)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue