github.com/neohugo/neohugo@v0.123.8/config/allconfig/load_test.go (about)

     1  package allconfig
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/spf13/afero"
     9  )
    10  
    11  func BenchmarkLoad(b *testing.B) {
    12  	tempDir := b.TempDir()
    13  	configFilename := filepath.Join(tempDir, "hugo.toml")
    14  	config := `
    15  baseURL = "https://example.com"
    16  defaultContentLanguage = 'en'
    17  
    18  [module]
    19  [[module.mounts]]
    20  source = 'content/en'
    21  target = 'content/en'
    22  lang = 'en'
    23  [[module.mounts]]
    24  source = 'content/nn'
    25  target = 'content/nn'
    26  lang = 'nn'
    27  [[module.mounts]]
    28  source = 'content/no'
    29  target = 'content/no'
    30  lang = 'no'
    31  [[module.mounts]]
    32  source = 'content/sv'
    33  target = 'content/sv'
    34  lang = 'sv'
    35  [[module.mounts]]
    36  source = 'layouts'
    37  target = 'layouts'
    38  
    39  [languages]
    40  [languages.en]
    41  title = "English"
    42  weight = 1
    43  [languages.nn]
    44  title = "Nynorsk"
    45  weight = 2
    46  [languages.no]
    47  title = "Norsk"
    48  weight = 3
    49  [languages.sv]
    50  title = "Svenska"
    51  weight = 4
    52  `
    53  	if err := os.WriteFile(configFilename, []byte(config), 0o666); err != nil {
    54  		b.Fatal(err)
    55  	}
    56  	d := ConfigSourceDescriptor{
    57  		Fs:       afero.NewOsFs(),
    58  		Filename: configFilename,
    59  	}
    60  
    61  	for i := 0; i < b.N; i++ {
    62  		_, err := LoadConfig(d)
    63  		if err != nil {
    64  			b.Fatal(err)
    65  		}
    66  	}
    67  }