github.com/SDLMoe/hugo@v0.47.1/helpers/testhelpers_test.go (about)

     1  package helpers
     2  
     3  import (
     4  	"github.com/spf13/viper"
     5  
     6  	"github.com/gohugoio/hugo/hugofs"
     7  	"github.com/gohugoio/hugo/langs"
     8  )
     9  
    10  func newTestPathSpec(fs *hugofs.Fs, v *viper.Viper) *PathSpec {
    11  	l := langs.NewDefaultLanguage(v)
    12  	ps, _ := NewPathSpec(fs, l)
    13  	return ps
    14  }
    15  
    16  func newTestDefaultPathSpec(configKeyValues ...interface{}) *PathSpec {
    17  	v := viper.New()
    18  	fs := hugofs.NewMem(v)
    19  	cfg := newTestCfgFor(fs)
    20  
    21  	for i := 0; i < len(configKeyValues); i += 2 {
    22  		cfg.Set(configKeyValues[i].(string), configKeyValues[i+1])
    23  	}
    24  	return newTestPathSpec(fs, cfg)
    25  }
    26  
    27  func newTestCfgFor(fs *hugofs.Fs) *viper.Viper {
    28  	v := newTestCfg()
    29  	v.SetFs(fs.Source)
    30  
    31  	return v
    32  
    33  }
    34  
    35  func newTestCfg() *viper.Viper {
    36  	v := viper.New()
    37  	v.Set("contentDir", "content")
    38  	v.Set("dataDir", "data")
    39  	v.Set("i18nDir", "i18n")
    40  	v.Set("layoutDir", "layouts")
    41  	v.Set("assetDir", "assets")
    42  	v.Set("resourceDir", "resources")
    43  	v.Set("publishDir", "public")
    44  	v.Set("archetypeDir", "archetypes")
    45  	return v
    46  }
    47  
    48  func newTestContentSpec() *ContentSpec {
    49  	v := viper.New()
    50  	spec, err := NewContentSpec(v)
    51  	if err != nil {
    52  		panic(err)
    53  	}
    54  	return spec
    55  }