// Copyright 2019 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hugolib
import (
"fmt"
"math/rand"
"os"
"path/filepath"
"strings"
"testing"
"time"
"github.com/gohugoio/hugo/common/loggers"
"github.com/spf13/afero"
"github.com/gohugoio/hugo/hugofs/files"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/htesting"
"github.com/gohugoio/hugo/hugofs"
qt "github.com/frankban/quicktest"
"github.com/gohugoio/testmodBuilder/mods"
"github.com/spf13/viper"
)
// https://github.com/gohugoio/hugo/issues/6730
func TestHugoModulesTargetInSubFolder(t *testing.T) {
if !isCI() {
// TODO(bep) investigate why this fails when running in LiteIDE (it works from the shell).
t.Skip("skip (relative) long running modules test when running locally")
}
config := `
baseURL="https://example.org"
workingDir = %q
[module]
[[module.imports]]
path="github.com/gohugoio/hugoTestModule2"
[[module.imports.mounts]]
source = "templates/hooks"
target = "layouts/_default/_markup"
`
b := newTestSitesBuilder(t)
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-target-in-subfolder-test")
b.Assert(err, qt.IsNil)
defer clean()
b.Fs = hugofs.NewDefault(viper.New())
b.WithWorkingDir(workingDir).WithConfigFile("toml", fmt.Sprintf(config, workingDir))
b.WithTemplates("_default/single.html", `{{ .Content }}`)
b.WithContent("p1.md", `---
title: "Page"
---
[A link](https://bep.is)
`)
b.WithSourceFile("go.mod", `
module github.com/gohugoio/tests/testHugoModules
`)
b.WithSourceFile("go.sum", `
github.com/gohugoio/hugoTestModule2 v0.0.0-20200131160637-9657d7697877 h1:WLM2bQCKIWo04T6NsIWsX/Vtirhf0TnpY66xyqGlgVY=
github.com/gohugoio/hugoTestModule2 v0.0.0-20200131160637-9657d7697877/go.mod h1:CBFZS3khIAXKxReMwq0le8sEl/D8hcXmixlOHVv+Gd0=
`)
b.Build(BuildCfg{})
b.AssertFileContent("public/p1/index.html", `<p>Page|https://bep.is|Title: |Text: A link|END</p>`)
}
// TODO(bep) this fails when testmodBuilder is also building ...
func TestHugoModules(t *testing.T) {
if !isCI() {
t.Skip("skip (relative) long running modules test when running locally")
}
t.Parallel()
if !isCI() || hugo.GoMinorVersion() < 12 {
// https://github.com/golang/go/issues/26794
// There were some concurrent issues with Go modules in < Go 12.
t.Skip("skip this on local host and for Go <= 1.11 due to a bug in Go's stdlib")
}
if testing.Short() {
t.Skip()
}
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
gooss := []string{"linux", "darwin", "windows"}
goos := gooss[rnd.Intn(len(gooss))]
ignoreVendor := rnd.Intn(2) == 0
testmods := mods.CreateModules(goos).Collect()
rnd.Shuffle(len(testmods), func(i, j int) { testmods[i], testmods[j] = testmods[j], testmods[i] })
for _, m := range testmods[:2] {
c := qt.New(t)
v := viper.New()
workingDir, clean, err := htesting.CreateTempDir(hugofs.