mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
tests: Convert from testify to quicktest
This commit is contained in:
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
qt "github.com/frankban/quicktest"
|
||||
)
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
@@ -40,10 +40,10 @@ func TestClient(t *testing.T) {
|
||||
modConfig := DefaultModuleConfig
|
||||
modConfig.Imports = []Import{Import{Path: "github.com/gohugoio/hugoTestModules1_darwin/modh2_2"}}
|
||||
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, modName)
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
defer clean()
|
||||
|
||||
client := NewClient(ClientConfig{
|
||||
@@ -53,36 +53,36 @@ func TestClient(t *testing.T) {
|
||||
})
|
||||
|
||||
// Test Init
|
||||
assert.NoError(client.Init(modPath))
|
||||
c.Assert(client.Init(modPath), qt.IsNil)
|
||||
|
||||
// Test Collect
|
||||
mc, err := client.Collect()
|
||||
assert.NoError(err)
|
||||
assert.Equal(4, len(mc.AllModules))
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(len(mc.AllModules), qt.Equals, 4)
|
||||
for _, m := range mc.AllModules {
|
||||
assert.NotNil(m)
|
||||
c.Assert(m, qt.Not(qt.IsNil))
|
||||
}
|
||||
|
||||
// Test Graph
|
||||
var graphb bytes.Buffer
|
||||
assert.NoError(client.Graph(&graphb))
|
||||
c.Assert(client.Graph(&graphb), qt.IsNil)
|
||||
|
||||
expect := `github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0
|
||||
github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/hugoTestModules1_darwin/modh2_2_1v@v1.3.0
|
||||
github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0
|
||||
`
|
||||
|
||||
assert.Equal(expect, graphb.String())
|
||||
c.Assert(graphb.String(), qt.Equals, expect)
|
||||
|
||||
// Test Vendor
|
||||
assert.NoError(client.Vendor())
|
||||
c.Assert(client.Vendor(), qt.IsNil)
|
||||
graphb.Reset()
|
||||
assert.NoError(client.Graph(&graphb))
|
||||
c.Assert(client.Graph(&graphb), qt.IsNil)
|
||||
expectVendored := `github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0+vendor
|
||||
github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/modh2_2_1v@v1.3.0+vendor
|
||||
github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
|
||||
`
|
||||
assert.Equal(expectVendored, graphb.String())
|
||||
c.Assert(graphb.String(), qt.Equals, expectVendored)
|
||||
|
||||
// Test the ignoreVendor setting
|
||||
clientIgnoreVendor := NewClient(ClientConfig{
|
||||
@@ -93,25 +93,25 @@ github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestMo
|
||||
})
|
||||
|
||||
graphb.Reset()
|
||||
assert.NoError(clientIgnoreVendor.Graph(&graphb))
|
||||
assert.Equal(expect, graphb.String())
|
||||
c.Assert(clientIgnoreVendor.Graph(&graphb), qt.IsNil)
|
||||
c.Assert(graphb.String(), qt.Equals, expect)
|
||||
|
||||
// Test Tidy
|
||||
assert.NoError(client.Tidy())
|
||||
c.Assert(client.Tidy(), qt.IsNil)
|
||||
|
||||
}
|
||||
|
||||
func TestGetModlineSplitter(t *testing.T) {
|
||||
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
gomodSplitter := getModlineSplitter(true)
|
||||
|
||||
assert.Equal([]string{"github.com/BurntSushi/toml", "v0.3.1"}, gomodSplitter("\tgithub.com/BurntSushi/toml v0.3.1"))
|
||||
assert.Equal([]string{"github.com/cpuguy83/go-md2man", "v1.0.8"}, gomodSplitter("\tgithub.com/cpuguy83/go-md2man v1.0.8 // indirect"))
|
||||
assert.Nil(gomodSplitter("require ("))
|
||||
c.Assert(gomodSplitter("\tgithub.com/BurntSushi/toml v0.3.1"), qt.DeepEquals, []string{"github.com/BurntSushi/toml", "v0.3.1"})
|
||||
c.Assert(gomodSplitter("\tgithub.com/cpuguy83/go-md2man v1.0.8 // indirect"), qt.DeepEquals, []string{"github.com/cpuguy83/go-md2man", "v1.0.8"})
|
||||
c.Assert(gomodSplitter("require ("), qt.IsNil)
|
||||
|
||||
gosumSplitter := getModlineSplitter(false)
|
||||
assert.Equal([]string{"github.com/BurntSushi/toml", "v0.3.1"}, gosumSplitter("github.com/BurntSushi/toml v0.3.1"))
|
||||
c.Assert(gosumSplitter("github.com/BurntSushi/toml v0.3.1"), qt.DeepEquals, []string{"github.com/BurntSushi/toml", "v0.3.1"})
|
||||
|
||||
}
|
||||
|
@@ -16,11 +16,11 @@ package modules
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
qt "github.com/frankban/quicktest"
|
||||
)
|
||||
|
||||
func TestPathKey(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
for _, test := range []struct {
|
||||
in string
|
||||
@@ -32,7 +32,7 @@ func TestPathKey(t *testing.T) {
|
||||
{"github.com/foo/v3d", "github.com/foo/v3d"},
|
||||
{"MyTheme", "mytheme"},
|
||||
} {
|
||||
assert.Equal(test.expect, pathKey(test.in))
|
||||
c.Assert(pathKey(test.in), qt.Equals, test.expect)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,8 +47,8 @@ func TestFilterUnwantedMounts(t *testing.T) {
|
||||
|
||||
filtered := filterUnwantedMounts(mounts)
|
||||
|
||||
assert := require.New(t)
|
||||
assert.Len(filtered, 2)
|
||||
assert.Equal([]Mount{Mount{Source: "a", Target: "b", Lang: "en"}, Mount{Source: "b", Target: "c", Lang: "en"}}, filtered)
|
||||
c := qt.New(t)
|
||||
c.Assert(len(filtered), qt.Equals, 2)
|
||||
c.Assert(filtered, qt.DeepEquals, []Mount{Mount{Source: "a", Target: "b", Lang: "en"}, Mount{Source: "b", Target: "c", Lang: "en"}})
|
||||
|
||||
}
|
||||
|
@@ -14,20 +14,19 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/gohugoio/hugo/common/hugo"
|
||||
|
||||
"github.com/gohugoio/hugo/config"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
qt "github.com/frankban/quicktest"
|
||||
)
|
||||
|
||||
func TestConfigHugoVersionIsValid(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
for i, test := range []struct {
|
||||
for _, test := range []struct {
|
||||
in HugoVersion
|
||||
expect bool
|
||||
}{
|
||||
@@ -36,12 +35,12 @@ func TestConfigHugoVersionIsValid(t *testing.T) {
|
||||
{HugoVersion{Min: "0.33.0", Max: "0.55.0"}, false},
|
||||
{HugoVersion{Min: "0.33.0", Max: "0.99.0"}, true},
|
||||
} {
|
||||
assert.Equal(test.expect, test.in.IsValid(), fmt.Sprintf("test %d", i))
|
||||
c.Assert(test.in.IsValid(), qt.Equals, test.expect)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeConfig(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
tomlConfig := `
|
||||
[module]
|
||||
|
||||
@@ -65,35 +64,35 @@ target="content/blog"
|
||||
lang="en"
|
||||
`
|
||||
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
mcfg, err := DecodeConfig(cfg)
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
v056 := hugo.VersionString("0.56.0")
|
||||
|
||||
hv := mcfg.HugoVersion
|
||||
|
||||
assert.Equal(-1, v056.Compare(hv.Min))
|
||||
assert.Equal(1, v056.Compare(hv.Max))
|
||||
assert.True(hv.Extended)
|
||||
c.Assert(v056.Compare(hv.Min), qt.Equals, -1)
|
||||
c.Assert(v056.Compare(hv.Max), qt.Equals, 1)
|
||||
c.Assert(hv.Extended, qt.Equals, true)
|
||||
|
||||
if hugo.IsExtended {
|
||||
assert.True(hv.IsValid())
|
||||
c.Assert(hv.IsValid(), qt.Equals, true)
|
||||
}
|
||||
|
||||
assert.Len(mcfg.Mounts, 1)
|
||||
assert.Len(mcfg.Imports, 1)
|
||||
c.Assert(len(mcfg.Mounts), qt.Equals, 1)
|
||||
c.Assert(len(mcfg.Imports), qt.Equals, 1)
|
||||
imp := mcfg.Imports[0]
|
||||
imp.Path = "github.com/bep/mycomponent"
|
||||
assert.Equal("src/markdown/blog", imp.Mounts[1].Source)
|
||||
assert.Equal("content/blog", imp.Mounts[1].Target)
|
||||
assert.Equal("en", imp.Mounts[1].Lang)
|
||||
c.Assert(imp.Mounts[1].Source, qt.Equals, "src/markdown/blog")
|
||||
c.Assert(imp.Mounts[1].Target, qt.Equals, "content/blog")
|
||||
c.Assert(imp.Mounts[1].Lang, qt.Equals, "en")
|
||||
|
||||
}
|
||||
|
||||
func TestDecodeConfigBothOldAndNewProvided(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
tomlConfig := `
|
||||
|
||||
theme = ["b", "c"]
|
||||
@@ -104,29 +103,29 @@ path="a"
|
||||
|
||||
`
|
||||
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
modCfg, err := DecodeConfig(cfg)
|
||||
assert.NoError(err)
|
||||
assert.Len(modCfg.Imports, 3)
|
||||
assert.Equal("a", modCfg.Imports[0].Path)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(len(modCfg.Imports), qt.Equals, 3)
|
||||
c.Assert(modCfg.Imports[0].Path, qt.Equals, "a")
|
||||
|
||||
}
|
||||
|
||||
// Test old style theme import.
|
||||
func TestDecodeConfigTheme(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
tomlConfig := `
|
||||
|
||||
theme = ["a", "b"]
|
||||
`
|
||||
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
mcfg, err := DecodeConfig(cfg)
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
assert.Len(mcfg.Imports, 2)
|
||||
assert.Equal("a", mcfg.Imports[0].Path)
|
||||
assert.Equal("b", mcfg.Imports[1].Path)
|
||||
c.Assert(len(mcfg.Imports), qt.Equals, 2)
|
||||
c.Assert(mcfg.Imports[0].Path, qt.Equals, "a")
|
||||
c.Assert(mcfg.Imports[1].Path, qt.Equals, "b")
|
||||
}
|
||||
|
Reference in New Issue
Block a user