mirror of
https://github.com/gohugoio/hugo.git
synced 2025-02-18 12:42:10 +00:00
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
|
package hugolib
|
||
|
|
||
|
import (
|
||
|
"path/filepath"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/spf13/hugo/deps"
|
||
|
"github.com/spf13/hugo/helpers"
|
||
|
"github.com/spf13/hugo/hugofs"
|
||
|
"github.com/spf13/hugo/source"
|
||
|
"github.com/spf13/hugo/tplapi"
|
||
|
"github.com/spf13/viper"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func newTestDepsConfig() deps.DepsCfg {
|
||
|
return deps.DepsCfg{Fs: hugofs.NewMem()}
|
||
|
}
|
||
|
|
||
|
func newTestPathSpec() *helpers.PathSpec {
|
||
|
return helpers.NewPathSpec(hugofs.NewMem(), viper.GetViper())
|
||
|
}
|
||
|
|
||
|
func createWithTemplateFromNameValues(additionalTemplates ...string) func(templ tplapi.Template) error {
|
||
|
|
||
|
return func(templ tplapi.Template) error {
|
||
|
for i := 0; i < len(additionalTemplates); i += 2 {
|
||
|
err := templ.AddTemplate(additionalTemplates[i], additionalTemplates[i+1])
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func buildSingleSite(t *testing.T, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site {
|
||
|
h, err := NewHugoSitesFromConfiguration(depsCfg)
|
||
|
|
||
|
require.NoError(t, err)
|
||
|
require.Len(t, h.Sites, 1)
|
||
|
|
||
|
require.NoError(t, h.Build(buildCfg))
|
||
|
|
||
|
return h.Sites[0]
|
||
|
}
|
||
|
|
||
|
func writeSourcesToSource(t *testing.T, base string, fs *hugofs.Fs, sources ...source.ByteSource) {
|
||
|
for _, src := range sources {
|
||
|
writeSource(t, fs, filepath.Join(base, src.Name), string(src.Content))
|
||
|
}
|
||
|
}
|