Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-10 22:05:17 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-12 14:26:32 +0300
commit9e571827055dedb46b78c5db3d17d6913f14870b (patch)
treef5f0108afe0c9385ff6dc27664943d9f719f57ad /resources
parent6027ee11082d0b9d72de1d4d1980a702be294ad2 (diff)
tests: Convert from testify to quicktest
Diffstat (limited to 'resources')
-rw-r--r--resources/image_test.go268
-rw-r--r--resources/page/page_data_test.go16
-rw-r--r--resources/page/page_kinds_test.go23
-rw-r--r--resources/page/pagegroup_test.go8
-rw-r--r--resources/page/pagemeta/page_frontmatter_test.go124
-rw-r--r--resources/page/pages_cache_test.go21
-rw-r--r--resources/page/pages_prev_next_test.go30
-rw-r--r--resources/page/pages_related_test.go36
-rw-r--r--resources/page/pages_sort_test.go86
-rw-r--r--resources/page/pages_test.go36
-rw-r--r--resources/page/pagination_test.go149
-rw-r--r--resources/page/permalinks_test.go35
-rw-r--r--resources/resource_metadata_test.go110
-rw-r--r--resources/resource_test.go152
-rw-r--r--resources/resource_transformers/integrity/integrity_test.go12
-rw-r--r--resources/resource_transformers/postcss/postcss_test.go12
-rw-r--r--resources/testhelpers_test.go64
-rw-r--r--resources/transform_test.go6
18 files changed, 605 insertions, 583 deletions
diff --git a/resources/image_test.go b/resources/image_test.go
index 061ae7710..96a66d999 100644
--- a/resources/image_test.go
+++ b/resources/image_test.go
@@ -20,11 +20,13 @@ import (
"strconv"
"testing"
+ "github.com/gohugoio/hugo/htesting/hqt"
+
"github.com/disintegration/imaging"
"sync"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestParseImageConfig(t *testing.T) {
@@ -59,107 +61,107 @@ func TestParseImageConfig(t *testing.T) {
func TestImageTransformBasic(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
- image := fetchSunset(assert)
+ image := fetchSunset(c)
fileCache := image.spec.FileCaches.ImageCache().Fs
- assert.Equal("/a/sunset.jpg", image.RelPermalink())
- assert.Equal("image", image.ResourceType())
+ c.Assert(image.RelPermalink(), qt.Equals, "/a/sunset.jpg")
+ c.Assert(image.ResourceType(), qt.Equals, "image")
resized, err := image.Resize("300x200")
- assert.NoError(err)
- assert.True(image != resized)
- assert.True(image.genericResource != resized.genericResource)
- assert.True(image.sourceFilename != resized.sourceFilename)
+ c.Assert(err, qt.IsNil)
+ c.Assert(image != resized, qt.Equals, true)
+ c.Assert(image.genericResource != resized.genericResource, qt.Equals, true)
+ c.Assert(image.sourceFilename != resized.sourceFilename, qt.Equals, true)
resized0x, err := image.Resize("x200")
- assert.NoError(err)
- assert.Equal(320, resized0x.Width())
- assert.Equal(200, resized0x.Height())
+ c.Assert(err, qt.IsNil)
+ c.Assert(resized0x.Width(), qt.Equals, 320)
+ c.Assert(resized0x.Height(), qt.Equals, 200)
- assertFileCache(assert, fileCache, resized0x.RelPermalink(), 320, 200)
+ assertFileCache(c, fileCache, resized0x.RelPermalink(), 320, 200)
resizedx0, err := image.Resize("200x")
- assert.NoError(err)
- assert.Equal(200, resizedx0.Width())
- assert.Equal(125, resizedx0.Height())
- assertFileCache(assert, fileCache, resizedx0.RelPermalink(), 200, 125)
+ c.Assert(err, qt.IsNil)
+ c.Assert(resizedx0.Width(), qt.Equals, 200)
+ c.Assert(resizedx0.Height(), qt.Equals, 125)
+ assertFileCache(c, fileCache, resizedx0.RelPermalink(), 200, 125)
resizedAndRotated, err := image.Resize("x200 r90")
- assert.NoError(err)
- assert.Equal(125, resizedAndRotated.Width())
- assert.Equal(200, resizedAndRotated.Height())
- assertFileCache(assert, fileCache, resizedAndRotated.RelPermalink(), 125, 200)
+ c.Assert(err, qt.IsNil)
+ c.Assert(resizedAndRotated.Width(), qt.Equals, 125)
+ c.Assert(resizedAndRotated.Height(), qt.Equals, 200)
+ assertFileCache(c, fileCache, resizedAndRotated.RelPermalink(), 125, 200)
- assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_300x200_resize_q68_linear.jpg", resized.RelPermalink())
- assert.Equal(300, resized.Width())
- assert.Equal(200, resized.Height())
+ c.Assert(resized.RelPermalink(), qt.Equals, "/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_300x200_resize_q68_linear.jpg")
+ c.Assert(resized.Width(), qt.Equals, 300)
+ c.Assert(resized.Height(), qt.Equals, 200)
fitted, err := resized.Fit("50x50")
- assert.NoError(err)
- assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_625708021e2bb281c9f1002f88e4753f.jpg", fitted.RelPermalink())
- assert.Equal(50, fitted.Width())
- assert.Equal(33, fitted.Height())
+ c.Assert(err, qt.IsNil)
+ c.Assert(fitted.RelPermalink(), qt.Equals, "/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_625708021e2bb281c9f1002f88e4753f.jpg")
+ c.Assert(fitted.Width(), qt.Equals, 50)
+ c.Assert(fitted.Height(), qt.Equals, 33)
// Check the MD5 key threshold
fittedAgain, _ := fitted.Fit("10x20")
fittedAgain, err = fittedAgain.Fit("10x20")
- assert.NoError(err)
- assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_3f65ba24dc2b7fba0f56d7f104519157.jpg", fittedAgain.RelPermalink())
- assert.Equal(10, fittedAgain.Width())
- assert.Equal(6, fittedAgain.Height())
+ c.Assert(err, qt.IsNil)
+ c.Assert(fittedAgain.RelPermalink(), qt.Equals, "/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_3f65ba24dc2b7fba0f56d7f104519157.jpg")
+ c.Assert(fittedAgain.Width(), qt.Equals, 10)
+ c.Assert(fittedAgain.Height(), qt.Equals, 6)
filled, err := image.Fill("200x100 bottomLeft")
- assert.NoError(err)
- assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_200x100_fill_q68_linear_bottomleft.jpg", filled.RelPermalink())
- assert.Equal(200, filled.Width())
- assert.Equal(100, filled.Height())
- assertFileCache(assert, fileCache, filled.RelPermalink(), 200, 100)
+ c.Assert(err, qt.IsNil)
+ c.Assert(filled.RelPermalink(), qt.Equals, "/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_200x100_fill_q68_linear_bottomleft.jpg")
+ c.Assert(filled.Width(), qt.Equals, 200)
+ c.Assert(filled.Height(), qt.Equals, 100)
+ assertFileCache(c, fileCache, filled.RelPermalink(), 200, 100)
smart, err := image.Fill("200x100 smart")
- assert.NoError(err)
- assert.Equal(fmt.Sprintf("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_200x100_fill_q68_linear_smart%d.jpg", smartCropVersionNumber), smart.RelPermalink())
- assert.Equal(200, smart.Width())
- assert.Equal(100, smart.Height())
- assertFileCache(assert, fileCache, smart.RelPermalink(), 200, 100)
+ c.Assert(err, qt.IsNil)
+ c.Assert(smart.RelPermalink(), qt.Equals, fmt.Sprintf("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_200x100_fill_q68_linear_smart%d.jpg", smartCropVersionNumber))
+ c.Assert(smart.Width(), qt.Equals, 200)
+ c.Assert(smart.Height(), qt.Equals, 100)
+ assertFileCache(c, fileCache, smart.RelPermalink(), 200, 100)
// Check cache
filledAgain, err := image.Fill("200x100 bottomLeft")
- assert.NoError(err)
- assert.True(filled == filledAgain)
- assert.True(filled.sourceFilename == filledAgain.sourceFilename)
- assertFileCache(assert, fileCache, filledAgain.RelPermalink(), 200, 100)
+ c.Assert(err, qt.IsNil)
+ c.Assert(filled == filledAgain, qt.Equals, true)
+ c.Assert(filled.sourceFilename == filledAgain.sourceFilename, qt.Equals, true)
+ assertFileCache(c, fileCache, filledAgain.RelPermalink(), 200, 100)
}
// https://github.com/gohugoio/hugo/issues/4261
func TestImageTransformLongFilename(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
- image := fetchImage(assert, "1234567890qwertyuiopasdfghjklzxcvbnm5to6eeeeee7via8eleph.jpg")
- assert.NotNil(image)
+ image := fetchImage(c, "1234567890qwertyuiopasdfghjklzxcvbnm5to6eeeeee7via8eleph.jpg")
+ c.Assert(image, qt.Not(qt.IsNil))
resized, err := image.Resize("200x")
- assert.NoError(err)
- assert.NotNil(resized)
- assert.Equal(200, resized.Width())
- assert.Equal("/a/_hu59e56ffff1bc1d8d122b1403d34e039f_90587_65b757a6e14debeae720fe8831f0a9bc.jpg", resized.RelPermalink())
+ c.Assert(err, qt.IsNil)
+ c.Assert(resized, qt.Not(qt.IsNil))
+ c.Assert(resized.Width(), qt.Equals, 200)
+ c.Assert(resized.RelPermalink(), qt.Equals, "/a/_hu59e56ffff1bc1d8d122b1403d34e039f_90587_65b757a6e14debeae720fe8831f0a9bc.jpg")
resized, err = resized.Resize("100x")
- assert.NoError(err)
- assert.NotNil(resized)
- assert.Equal(100, resized.Width())
- assert.Equal("/a/_hu59e56ffff1bc1d8d122b1403d34e039f_90587_c876768085288f41211f768147ba2647.jpg", resized.RelPermalink())
+ c.Assert(err, qt.IsNil)
+ c.Assert(resized, qt.Not(qt.IsNil))
+ c.Assert(resized.Width(), qt.Equals, 100)
+ c.Assert(resized.RelPermalink(), qt.Equals, "/a/_hu59e56ffff1bc1d8d122b1403d34e039f_90587_c876768085288f41211f768147ba2647.jpg")
}
// Issue 6137
func TestImageTransformUppercaseExt(t *testing.T) {
- assert := require.New(t)
- image := fetchImage(assert, "sunrise.JPG")
+ c := qt.New(t)
+ image := fetchImage(c, "sunrise.JPG")
resized, err := image.Resize("200x")
- assert.NoError(err)
- assert.NotNil(resized)
- assert.Equal(200, resized.Width())
+ c.Assert(err, qt.IsNil)
+ c.Assert(resized, qt.Not(qt.IsNil))
+ c.Assert(resized.Width(), qt.Equals, 200)
}
// https://github.com/gohugoio/hugo/issues/5730
@@ -172,29 +174,29 @@ func TestImagePermalinkPublishOrder(t *testing.T) {
t.Run(name, func(t *testing.T) {
- assert := require.New(t)
- spec := newTestResourceOsFs(assert)
+ c := qt.New(t)
+ spec := newTestResourceOsFs(c)
check1 := func(img *Image) {
resizedLink := "/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_100x50_resize_q75_box.jpg"
- assert.Equal(resizedLink, img.RelPermalink())
- assertImageFile(assert, spec.PublishFs, resizedLink, 100, 50)
+ c.Assert(img.RelPermalink(), qt.Equals, resizedLink)
+ assertImageFile(c, spec.PublishFs, resizedLink, 100, 50)
}
check2 := func(img *Image) {
- assert.Equal("/a/sunset.jpg", img.RelPermalink())
- assertImageFile(assert, spec.PublishFs, "a/sunset.jpg", 900, 562)
+ c.Assert(img.RelPermalink(), qt.Equals, "/a/sunset.jpg")
+ assertImageFile(c, spec.PublishFs, "a/sunset.jpg", 900, 562)
}
- orignal := fetchImageForSpec(spec, assert, "sunset.jpg")
- assert.NotNil(orignal)
+ orignal := fetchImageForSpec(spec, c, "sunset.jpg")
+ c.Assert(orignal, qt.Not(qt.IsNil))
if checkOriginalFirst {
check2(orignal)
}
resized, err := orignal.Resize("100x50")
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
check1(resized)
@@ -210,11 +212,11 @@ func TestImageTransformConcurrent(t *testing.T) {
var wg sync.WaitGroup
- assert := require.New(t)
+ c := qt.New(t)
- spec := newTestResourceOsFs(assert)
+ spec := newTestResourceOsFs(c)
- image := fetchImageForSpec(spec, assert, "sunset.jpg")
+ image := fetchImageForSpec(spec, c, "sunset.jpg")
for i := 0; i < 4; i++ {
wg.Add(1)
@@ -252,7 +254,7 @@ func TestImageTransformConcurrent(t *testing.T) {
}
func TestDecodeImaging(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
m := map[string]interface{}{
"quality": 42,
"resampleFilter": "NearestNeighbor",
@@ -261,46 +263,46 @@ func TestDecodeImaging(t *testing.T) {
imaging, err := decodeImaging(m)
- assert.NoError(err)
- assert.Equal(42, imaging.Quality)
- assert.Equal("nearestneighbor", imaging.ResampleFilter)
- assert.Equal("topleft", imaging.Anchor)
+ c.Assert(err, qt.IsNil)
+ c.Assert(imaging.Quality, qt.Equals, 42)
+ c.Assert(imaging.ResampleFilter, qt.Equals, "nearestneighbor")
+ c.Assert(imaging.Anchor, qt.Equals, "topleft")
m = map[string]interface{}{}
imaging, err = decodeImaging(m)
- assert.NoError(err)
- assert.Equal(defaultJPEGQuality, imaging.Quality)
- assert.Equal("box", imaging.ResampleFilter)
- assert.Equal("smart", imaging.Anchor)
+ c.Assert(err, qt.IsNil)
+ c.Assert(imaging.Quality, qt.Equals, defaultJPEGQuality)
+ c.Assert(imaging.ResampleFilter, qt.Equals, "box")
+ c.Assert(imaging.Anchor, qt.Equals, "smart")
_, err = decodeImaging(map[string]interface{}{
"quality": 123,
})
- assert.Error(err)
+ c.Assert(err, qt.Not(qt.IsNil))
_, err = decodeImaging(map[string]interface{}{
"resampleFilter": "asdf",
})
- assert.Error(err)
+ c.Assert(err, qt.Not(qt.IsNil))
_, err = decodeImaging(map[string]interface{}{
"anchor": "asdf",
})
- assert.Error(err)
+ c.Assert(err, qt.Not(qt.IsNil))
imaging, err = decodeImaging(map[string]interface{}{
"anchor": "Smart",
})
- assert.NoError(err)
- assert.Equal("smart", imaging.Anchor)
+ c.Assert(err, qt.IsNil)
+ c.Assert(imaging.Anchor, qt.Equals, "smart")
}
func TestImageWithMetadata(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
- image := fetchSunset(assert)
+ image := fetchSunset(c)
var meta = []map[string]interface{}{
{
@@ -310,89 +312,89 @@ func TestImageWithMetadata(t *testing.T) {
},
}
- assert.NoError(AssignMetadata(meta, image))
- assert.Equal("Sunset #1", image.Name())
+ c.Assert(AssignMetadata(meta, image), qt.IsNil)
+ c.Assert(image.Name(), qt.Equals, "Sunset #1")
resized, err := image.Resize("200x")
- assert.NoError(err)
- assert.Equal("Sunset #1", resized.Name())
+ c.Assert(err, qt.IsNil)
+ c.Assert(resized.Name(), qt.Equals, "Sunset #1")
}
func TestImageResize8BitPNG(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
- image := fetchImage(assert, "gohugoio.png")
+ image := fetchImage(c, "gohugoio.png")
- assert.Equal(imaging.PNG, image.format)
- assert.Equal("/a/gohugoio.png", image.RelPermalink())
- assert.Equal("image", image.ResourceType())
+ c.Assert(image.format, qt.Equals, imaging.PNG)
+ c.Assert(image.RelPermalink(), qt.Equals, "/a/gohugoio.png")
+ c.Assert(image.ResourceType(), qt.Equals, "image")
resized, err := image.Resize("800x")
- assert.NoError(err)
- assert.Equal(imaging.PNG, resized.format)
- assert.Equal("/a/gohugoio_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_800x0_resize_linear_2.png", resized.RelPermalink())
- assert.Equal(800, resized.Width())
+ c.Assert(err, qt.IsNil)
+ c.Assert(resized.format, qt.Equals, imaging.PNG)
+ c.Assert(resized.RelPermalink(), qt.Equals, "/a/gohugoio_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_800x0_resize_linear_2.png")
+ c.Assert(resized.Width(), qt.Equals, 800)
}
func TestImageResizeInSubPath(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
- image := fetchImage(assert, "sub/gohugoio2.png")
+ image := fetchImage(c, "sub/gohugoio2.png")
fileCache := image.spec.FileCaches.ImageCache().Fs
- assert.Equal(imaging.PNG, image.format)
- assert.Equal("/a/sub/gohugoio2.png", image.RelPermalink())
- assert.Equal("image", image.ResourceType())
+ c.Assert(image.format, qt.Equals, imaging.PNG)
+ c.Assert(image.RelPermalink(), qt.Equals, "/a/sub/gohugoio2.png")
+ c.Assert(image.ResourceType(), qt.Equals, "image")
resized, err := image.Resize("101x101")
- assert.NoError(err)
- assert.Equal(imaging.PNG, resized.format)
- assert.Equal("/a/sub/gohugoio2_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_101x101_resize_linear_2.png", resized.RelPermalink())
- assert.Equal(101, resized.Width())
+ c.Assert(err, qt.IsNil)
+ c.Assert(resized.format, qt.Equals, imaging.PNG)
+ c.Assert(resized.RelPermalink(), qt.Equals, "/a/sub/gohugoio2_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_101x101_resize_linear_2.png")
+ c.Assert(resized.Width(), qt.Equals, 101)
- assertFileCache(assert, fileCache, resized.RelPermalink(), 101, 101)
+ assertFileCache(c, fileCache, resized.RelPermalink(), 101, 101)
publishedImageFilename := filepath.Clean(resized.RelPermalink())
- assertImageFile(assert, image.spec.BaseFs.PublishFs, publishedImageFilename, 101, 101)
- assert.NoError(image.spec.BaseFs.PublishFs.Remove(publishedImageFilename))
+ assertImageFile(c, image.spec.BaseFs.PublishFs, publishedImageFilename, 101, 101)
+ c.Assert(image.spec.BaseFs.PublishFs.Remove(publishedImageFilename), qt.IsNil)
// Cleare mem cache to simulate reading from the file cache.
resized.spec.imageCache.clear()
resizedAgain, err := image.Resize("101x101")
- assert.NoError(err)
- assert.Equal("/a/sub/gohugoio2_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_101x101_resize_linear_2.png", resizedAgain.RelPermalink())
- assert.Equal(101, resizedAgain.Width())
- assertFileCache(assert, fileCache, resizedAgain.RelPermalink(), 101, 101)
- assertImageFile(assert, image.spec.BaseFs.PublishFs, publishedImageFilename, 101, 101)
+ c.Assert(err, qt.IsNil)
+ c.Assert(resizedAgain.RelPermalink(), qt.Equals, "/a/sub/gohugoio2_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_101x101_resize_linear_2.png")
+ c.Assert(resizedAgain.Width(), qt.Equals, 101)
+ assertFileCache(c, fileCache, resizedAgain.RelPermalink(), 101, 101)
+ assertImageFile(c, image.spec.BaseFs.PublishFs, publishedImageFilename, 101, 101)
}
func TestSVGImage(t *testing.T) {
- assert := require.New(t)
- spec := newTestResourceSpec(assert)
- svg := fetchResourceForSpec(spec, assert, "circle.svg")
- assert.NotNil(svg)
+ c := qt.New(t)
+ spec := newTestResourceSpec(c)
+ svg := fetchResourceForSpec(spec, c, "circle.svg")
+ c.Assert(svg, qt.Not(qt.IsNil))
}
func TestSVGImageContent(t *testing.T) {
- assert := require.New(t)
- spec := newTestResourceSpec(assert)
- svg := fetchResourceForSpec(spec, assert, "circle.svg")
- assert.NotNil(svg)
+ c := qt.New(t)
+ spec := newTestResourceSpec(c)
+ svg := fetchResourceForSpec(spec, c, "circle.svg")
+ c.Assert(svg, qt.Not(qt.IsNil))
content, err := svg.Content()
- assert.NoError(err)
- assert.IsType("", content)
- assert.Contains(content.(string), `<svg height="100" width="100">`)
+ c.Assert(err, qt.IsNil)
+ c.Assert(content, hqt.IsSameType, "")
+ c.Assert(content.(string), qt.Contains, `<svg height="100" width="100">`)
}
func BenchmarkResizeParallel(b *testing.B) {
- assert := require.New(b)
- img := fetchSunset(assert)
+ c := qt.New(b)
+ img := fetchSunset(c)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
diff --git a/resources/page/page_data_test.go b/resources/page/page_data_test.go
index b6641bcd7..f161fad3c 100644
--- a/resources/page/page_data_test.go
+++ b/resources/page/page_data_test.go
@@ -19,15 +19,15 @@ import (
"text/template"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestPageData(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
data := make(Data)
- assert.Nil(data.Pages())
+ c.Assert(data.Pages(), qt.IsNil)
pages := Pages{
&testPage{title: "a1"},
@@ -36,22 +36,22 @@ func TestPageData(t *testing.T) {
data["pages"] = pages
- assert.Equal(pages, data.Pages())
+ c.Assert(data.Pages(), eq, pages)
data["pages"] = func() Pages {
return pages
}
- assert.Equal(pages, data.Pages())
+ c.Assert(data.Pages(), eq, pages)
templ, err := template.New("").Parse(`Pages: {{ .Pages }}`)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
var buff bytes.Buffer
- assert.NoError(templ.Execute(&buff, data))
+ c.Assert(templ.Execute(&buff, data), qt.IsNil)
- assert.Contains(buff.String(), "Pages(2)")
+ c.Assert(buff.String(), qt.Contains, "Pages(2)")
}
diff --git a/resources/page/page_kinds_test.go b/resources/page/page_kinds_test.go
index 12f1c598e..7fba7e1d2 100644
--- a/resources/page/page_kinds_test.go
+++ b/resources/page/page_kinds_test.go
@@ -16,22 +16,23 @@ package page
import (
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestKind(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
// Add tests for these constants to make sure they don't change
- require.Equal(t, "page", KindPage)
- require.Equal(t, "home", KindHome)
- require.Equal(t, "section", KindSection)
- require.Equal(t, "taxonomy", KindTaxonomy)
- require.Equal(t, "taxonomyTerm", KindTaxonomyTerm)
+ c.Assert(KindPage, qt.Equals, "page")
+ c.Assert(KindHome, qt.Equals, "home")
+ c.Assert(KindSection, qt.Equals, "section")
+ c.Assert(KindTaxonomy, qt.Equals, "taxonomy")
+ c.Assert(KindTaxonomyTerm, qt.Equals, "taxonomyTerm")
- require.Equal(t, KindTaxonomyTerm, GetKind("TAXONOMYTERM"))
- require.Equal(t, KindTaxonomy, GetKind("Taxonomy"))
- require.Equal(t, KindPage, GetKind("Page"))
- require.Equal(t, KindHome, GetKind("Home"))
- require.Equal(t, KindSection, GetKind("SEction"))
+ c.Assert(GetKind("TAXONOMYTERM"), qt.Equals, KindTaxonomyTerm)
+ c.Assert(GetKind("Taxonomy"), qt.Equals, KindTaxonomy)
+ c.Assert(GetKind("Page"), qt.Equals, KindPage)
+ c.Assert(GetKind("Home"), qt.Equals, KindHome)
+ c.Assert(GetKind("SEction"), qt.Equals, KindSection)
}
diff --git a/resources/page/pagegroup_test.go b/resources/page/pagegroup_test.go
index 51ac09034..26a25c381 100644
--- a/resources/page/pagegroup_test.go
+++ b/resources/page/pagegroup_test.go
@@ -18,8 +18,8 @@ import (
"strings"
"testing"
+ qt "github.com/frankban/quicktest"
"github.com/spf13/cast"
- "github.com/stretchr/testify/require"
)
type pageGroupTestObject struct {
@@ -204,7 +204,7 @@ func TestGroupByParamInReverseOrder(t *testing.T) {
}
func TestGroupByParamCalledWithCapitalLetterString(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
testStr := "TestString"
p := newTestPage()
p.params["custom_param"] = testStr
@@ -212,8 +212,8 @@ func TestGroupByParamCalledWithCapitalLetterString(t *testing.T) {
groups, err := pages.GroupByParam("custom_param")
- assert.NoError(err)
- assert.Equal(testStr, groups[0].Key)
+ c.Assert(err, qt.IsNil)
+ c.Assert(groups[0].Key, qt.Equals, testStr)
}
diff --git a/resources/page/pagemeta/page_frontmatter_test.go b/resources/page/pagemeta/page_frontmatter_test.go
index 313f704d9..f96d186da 100644
--- a/resources/page/pagemeta/page_frontmatter_test.go
+++ b/resources/page/pagemeta/page_frontmatter_test.go
@@ -14,7 +14,6 @@
package pagemeta
import (
- "fmt"
"strings"
"testing"
"time"
@@ -22,14 +21,14 @@ import (
"github.com/gohugoio/hugo/resources/resource"
"github.com/spf13/viper"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestDateAndSlugFromBaseFilename(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
tests := []struct {
name string
@@ -50,15 +49,14 @@ func TestDateAndSlugFromBaseFilename(t *testing.T) {
{"asdfasdf.md", "0001-01-01", ""},
}
- for i, test := range tests {
+ for _, test := range tests {
expecteFDate, err := time.Parse("2006-01-02", test.date)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
- errMsg := fmt.Sprintf("Test %d", i)
gotDate, gotSlug := dateAndSlugFromBaseFilename(test.name)
- assert.Equal(expecteFDate, gotDate, errMsg)
- assert.Equal(test.slug, gotSlug, errMsg)
+ c.Assert(gotDate, qt.Equals, expecteFDate)
+ c.Assert(gotSlug, qt.Equals, test.slug)
}
}
@@ -73,7 +71,7 @@ func newTestFd() *FrontMatterDescriptor {
}
func TestFrontMatterNewConfig(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
cfg := viper.New()
@@ -85,20 +83,20 @@ func TestFrontMatterNewConfig(t *testing.T) {
})
fc, err := newFrontmatterConfig(cfg)
- assert.NoError(err)
- assert.Equal([]string{"publishdate", "pubdate", "published", "lastmod", "modified"}, fc.date)
- assert.Equal([]string{"publishdate", "pubdate", "published"}, fc.lastmod)
- assert.Equal([]string{"lastmod", "modified"}, fc.expiryDate)
- assert.Equal([]string{"date"}, fc.publishDate)
+ c.Assert(err, qt.IsNil)
+ c.Assert(fc.date, qt.DeepEquals, []string{"publishdate", "pubdate", "published", "lastmod", "modified"})
+ c.Assert(fc.lastmod, qt.DeepEquals, []string{"publishdate", "pubdate", "published"})
+ c.Assert(fc.expiryDate, qt.DeepEquals, []string{"lastmod", "modified"})
+ c.Assert(fc.publishDate, qt.DeepEquals, []string{"date"})
// Default
cfg = viper.New()
fc, err = newFrontmatterConfig(cfg)
- assert.NoError(err)
- assert.Equal([]string{"date", "publishdate", "pubdate", "published", "lastmod", "modified"}, fc.date)
- assert.Equal([]string{":git", "lastmod", "modified", "date", "publishdate", "pubdate", "published"}, fc.lastmod)
- assert.Equal([]string{"expirydate", "unpublishdate"}, fc.expiryDate)
- assert.Equal([]string{"publishdate", "pubdate", "published", "date"}, fc.publishDate)
+ c.Assert(err, qt.IsNil)
+ c.Assert(fc.date, qt.DeepEquals, []string{"date", "publishdate", "pubdate", "published", "lastmod", "modified"})
+ c.Assert(fc.lastmod, qt.DeepEquals, []string{":git", "lastmod", "modified", "date", "publishdate", "pubdate", "published"})
+ c.Assert(fc.expiryDate, qt.DeepEquals, []string{"expirydate", "unpublishdate"})
+ c.Assert(fc.publishDate, qt.DeepEquals, []string{"publishdate", "pubdate", "published", "date"})
// :default keyword
cfg.Set("frontmatter", map[string]interface{}{
@@ -108,16 +106,16 @@ func TestFrontMatterNewConfig(t *testing.T) {
"publishDate": []string{"d4", ":default"},
})
fc, err = newFrontmatterConfig(cfg)
- assert.NoError(err)
- assert.Equal([]string{"d1", "date", "publishdate", "pubdate", "published", "lastmod", "modified"}, fc.date)
- assert.Equal([]string{"d2", ":git", "lastmod", "modified", "date", "publishdate", "pubdate", "published"}, fc.lastmod)
- assert.Equal([]string{"d3", "expirydate", "unpublishdate"}, fc.expiryDate)
- assert.Equal([]string{"d4", "publishdate", "pubdate", "published", "date"}, fc.publishDate)
+ c.Assert(err, qt.IsNil)
+ c.Assert(fc.date, qt.DeepEquals, []string{"d1", "date", "publishdate", "pubdate", "published", "lastmod", "modified"})
+ c.Assert(fc.lastmod, qt.DeepEquals, []string{"d2", ":git", "lastmod", "modified", "date", "publishdate", "pubdate", "published"})
+ c.Assert(fc.expiryDate, qt.DeepEquals, []string{"d3", "expirydate", "unpublishdate"})
+ c.Assert(fc.publishDate, qt.DeepEquals, []string{"d4", "publishdate", "pubdate", "published", "date"})
}
func TestFrontMatterDatesHandlers(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
for _, handlerID := range []string{":filename", ":fileModTime", ":git"} {
@@ -128,7 +126,7 @@ func TestFrontMatterDatesHandlers(t *testing.T) {
})
handler, err := NewFrontmatterHandler(nil, cfg)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
d1, _ := time.Parse("2006-01-02", "2018-02-01")
d2, _ := time.Parse("2006-01-02", "2018-02-02")
@@ -143,15 +141,15 @@ func TestFrontMatterDatesHandlers(t *testing.T) {
d.GitAuthorDate = d1
}
d.Frontmatter["date"] = d2
- assert.NoError(handler.HandleDates(d))
- assert.Equal(d1, d.Dates.FDate)
- assert.Equal(d2, d.Params["date"])
+ c.Assert(handler.HandleDates(d), qt.IsNil)
+ c.Assert(d.Dates.FDate, qt.Equals, d1)
+ c.Assert(d.Params["date"], qt.Equals, d2)
d = newTestFd()
d.Frontmatter["date"] = d2
- assert.NoError(handler.HandleDates(d))
- assert.Equal(d2, d.Dates.FDate)
- assert.Equal(d2, d.Params["date"])
+ c.Assert(handler.HandleDates(d), qt.IsNil)
+ c.Assert(d.Dates.FDate, qt.Equals, d2)
+ c.Assert(d.Params["date"], qt.Equals, d2)
}
}
@@ -159,7 +157,7 @@ func TestFrontMatterDatesHandlers(t *testing.T) {
func TestFrontMatterDatesCustomConfig(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
cfg := viper.New()
cfg.Set("frontmatter", map[string]interface{}{
@@ -169,10 +167,10 @@ func TestFrontMatterDatesCustomConfig(t *testing.T) {
})
handler, err := NewFrontmatterHandler(nil, cfg)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
testDate, err := time.Parse("2006-01-02", "2018-02-01")
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
d := newTestFd()
d.Frontmatter["mydate"] = testDate
@@ -185,29 +183,29 @@ func TestFrontMatterDatesCustomConfig(t *testing.T) {
testDate = testDate.Add(24 * time.Hour)
d.Frontmatter["expirydate"] = testDate
- assert.NoError(handler.HandleDates(d))
+ c.Assert(handler.HandleDates(d), qt.IsNil)
- assert.Equal(1, d.Dates.FDate.Day())
- assert.Equal(4, d.Dates.FLastmod.Day())
- assert.Equal(4, d.Dates.FPublishDate.Day())
- assert.Equal(5, d.Dates.FExpiryDate.Day())
+ c.Assert(d.Dates.FDate.Day(), qt.Equals, 1)
+ c.Assert(d.Dates.FLastmod.Day(), qt.Equals, 4)
+ c.Assert(d.Dates.FPublishDate.Day(), qt.Equals, 4)
+ c.Assert(d.Dates.FExpiryDate.Day(), qt.Equals, 5)
- assert.Equal(d.Dates.FDate, d.Params["date"])
- assert.Equal(d.Dates.FDate, d.Params["mydate"])
- assert.Equal(d.Dates.FPublishDate, d.Params["publishdate"])
- assert.Equal(d.Dates.FExpiryDate, d.Params["expirydate"])
+ c.Assert(d.Params["date"], qt.Equals, d.Dates.FDate)
+ c.Assert(d.Params["mydate"], qt.Equals, d.Dates.FDate)
+ c.Assert(d.Params["publishdate"], qt.Equals, d.Dates.FPublishDate)
+ c.Assert(d.Params["expirydate"], qt.Equals, d.Dates.FExpiryDate)
- assert.False(handler.IsDateKey("date")) // This looks odd, but is configured like this.
- assert.True(handler.IsDateKey("mydate"))
- assert.True(handler.IsDateKey("publishdate"))
- assert.True(handler.IsDateKey("pubdate"))
+ c.Assert(handler.IsDateKey("date"), qt.Equals, false) // This looks odd, but is configured like this.
+ c.Assert(handler.IsDateKey("mydate"), qt.Equals, true)
+ c.Assert(handler.IsDateKey("publishdate"), qt.Equals, true)
+ c.Assert(handler.IsDateKey("pubdate"), qt.Equals, true)
}
func TestFrontMatterDatesDefaultKeyword(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
cfg := viper.New()
@@ -217,7 +215,7 @@ func TestFrontMatterDatesDefaultKeyword(t *testing.T) {
})
handler, err := NewFrontmatterHandler(nil, cfg)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
testDate, _ := time.Parse("2006-01-02", "2018-02-01")
d := newTestFd()
@@ -226,27 +224,27 @@ func TestFrontMatterDatesDefaultKeyword(t *testing.T) {
d.Frontmatter["mypubdate"] = testDate.Add(2 * 24 * time.Hour)
d.Frontmatter["publishdate"] = testDate.Add(3 * 24 * time.Hour)
- assert.NoError(handler.HandleDates(d))
+ c.Assert(handler.HandleDates(d), qt.IsNil)
- assert.Equal(1, d.Dates.FDate.Day())
- assert.Equal(2, d.Dates.FLastmod.Day())
- assert.Equal(4, d.Dates.FPublishDate.Day())
- assert.True(d.Dates.FExpiryDate.IsZero())
+ c.Assert(d.Dates.FDate.Day(), qt.Equals, 1)
+ c.Assert(d.Dates.FLastmod.Day(), qt.Equals, 2)
+ c.Assert(d.Dates.FPublishDate.Day(), qt.Equals, 4)
+ c.Assert(d.Dates.FExpiryDate.IsZero(), qt.Equals, true)
}
func TestExpandDefaultValues(t *testing.T) {
- assert := require.New(t)
- assert.Equal([]string{"a", "b", "c", "d"}, expandDefaultValues([]string{"a", ":default", "d"}, []string{"b", "c"}))
- assert.Equal([]string{"a", "b", "c"}, expandDefaultValues([]string{"a", "b", "c"}, []string{"a", "b", "c"}))
- assert.Equal([]string{"b", "c", "a", "b", "c", "d"}, expandDefaultValues([]string{":default", "a", ":default", "d"}, []string{"b", "c"}))
+ c := qt.New(t)
+ c.Assert(expandDefaultValues([]string{"a", ":default", "d"}, []string{"b", "c"}), qt.DeepEquals, []string{"a", "b", "c", "d"})
+ c.Assert(expandDefaultValues([]string{"a", "b", "c"}, []string{"a", "b", "c"}), qt.DeepEquals, []string{"a", "b", "c"})
+ c.Assert(expandDefaultValues([]string{":default", "a", ":default", "d"}, []string{"b", "c"}), qt.DeepEquals, []string{"b", "c", "a", "b", "c", "d"})
}
func TestFrontMatterDateFieldHandler(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
handlers := new(frontmatterFieldHandlers)
@@ -256,7 +254,7 @@ func TestFrontMatterDateFieldHandler(t *testing.T) {
h := handlers.newDateFieldHandler("date", func(d *FrontMatterDescriptor, t time.Time) { d.Dates.FDate = t })
handled, err := h(fd)
- assert.True(handled)
- assert.NoError(err)
- assert.Equal(d, fd.Dates.FDate)
+ c.Assert(handled, qt.Equals, true)
+ c.Assert(err, qt.IsNil)
+ c.Assert(fd.Dates.FDate, qt.Equals, d)
}
diff --git a/resources/page/pages_cache_test.go b/resources/page/pages_cache_test.go
index b83283408..825bdc31f 100644
--- a/resources/page/pages_cache_test.go
+++ b/resources/page/pages_cache_test.go
@@ -19,11 +19,12 @@ import (
"sync/atomic"
"testing"
- "github.com/stretchr/testify/assert"
+ qt "github.com/frankban/quicktest"
)
func TestPageCache(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
c1 := newPageCache()
changeFirst := func(p Pages) {
@@ -50,21 +51,21 @@ func TestPageCache(t *testing.T) {
defer wg.Done()
for k, pages := range testPageSets {
l1.Lock()
- p, c := c1.get("k1", nil, pages)
- assert.Equal(t, !atomic.CompareAndSwapUint64(&o1, uint64(k), uint64(k+1)), c)
+ p, ca := c1.get("k1", nil, pages)
+ c.Assert(ca, qt.Equals, !atomic.CompareAndSwapUint64(&o1, uint64(k), uint64(k+1)))
l1.Unlock()
p2, c2 := c1.get("k1", nil, p)
- assert.True(t, c2)
- assert.True(t, pagesEqual(p, p2))
- assert.True(t, pagesEqual(p, pages))
- assert.NotNil(t, p)
+ c.Assert(c2, qt.Equals, true)
+ c.Assert(pagesEqual(p, p2), qt.Equals, true)
+ c.Assert(pagesEqual(p, pages), qt.Equals, true)
+ c.Assert(p, qt.Not(qt.IsNil))
l2.Lock()
p3, c3 := c1.get("k2", changeFirst, pages)
- assert.Equal(t, !atomic.CompareAndSwapUint64(&o2, uint64(k), uint64(k+1)), c3)
+ c.Assert(c3, qt.Equals, !atomic.CompareAndSwapUint64(&o2, uint64(k), uint64(k+1)))
l2.Unlock()
- assert.NotNil(t, p3)
- assert.Equal(t, p3[0].(*testPage).description, "changed")
+ c.Assert(p3, qt.Not(qt.IsNil))
+ c.Assert("changed", qt.Equals, p3[0].(*testPage).description)
}
}()
}
diff --git a/resources/page/pages_prev_next_test.go b/resources/page/pages_prev_next_test.go
index c39ad0603..a75335f00 100644
--- a/resources/page/pages_prev_next_test.go
+++ b/resources/page/pages_prev_next_test.go
@@ -16,8 +16,8 @@ package page
import (
"testing"
+ qt "github.com/frankban/quicktest"
"github.com/spf13/cast"
- "github.com/stretchr/testify/assert"
)
type pagePNTestObject struct {
@@ -36,18 +36,20 @@ var pagePNTestSources = []pagePNTestObject{
func TestPrev(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
pages := preparePageGroupTestPages(t)
- assert.Equal(t, pages.Prev(pages[0]), pages[4])
- assert.Equal(t, pages.Prev(pages[1]), pages[0])
- assert.Equal(t, pages.Prev(pages[4]), pages[3])
+ c.Assert(pages[4], qt.Equals, pages.Prev(pages[0]))
+ c.Assert(pages[0], qt.Equals, pages.Prev(pages[1]))
+ c.Assert(pages[3], qt.Equals, pages.Prev(pages[4]))
}
func TestNext(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
pages := preparePageGroupTestPages(t)
- assert.Equal(t, pages.Next(pages[0]), pages[1])
- assert.Equal(t, pages.Next(pages[1]), pages[2])
- assert.Equal(t, pages.Next(pages[4]), pages[0])
+ c.Assert(pages[1], qt.Equals, pages.Next(pages[0]))
+ c.Assert(pages[2], qt.Equals, pages.Next(pages[1]))
+ c.Assert(pages[0], qt.Equals, pages.Next(pages[4]))
}
func prepareWeightedPagesPrevNext(t *testing.T) WeightedPages {
@@ -68,16 +70,18 @@ func prepareWeightedPagesPrevNext(t *testing.T) WeightedPages {
func TestWeightedPagesPrev(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
w := prepareWeightedPagesPrevNext(t)
- assert.Equal(t, w.Prev(w[0].Page), w[4].Page)
- assert.Equal(t, w.Prev(w[1].Page), w[0].Page)
- assert.Equal(t, w.Prev(w[4].Page), w[3].Page)
+ c.Assert(w[4].Page, qt.Equals, w.Prev(w[0].Page))
+ c.Assert(w[0].Page, qt.Equals, w.Prev(w[1].Page))
+ c.Assert(w[3].Page, qt.Equals, w.Prev(w[4].Page))
}
func TestWeightedPagesNext(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
w := prepareWeightedPagesPrevNext(t)
- assert.Equal(t, w.Next(w[0].Page), w[1].Page)
- assert.Equal(t, w.Next(w[1].Page), w[2].Page)
- assert.Equal(t, w.Next(w[4].Page), w[0].Page)
+ c.Assert(w[1].Page, qt.Equals, w.Next(w[0].Page))
+ c.Assert(w[2].Page, qt.Equals, w.Next(w[1].Page))
+ c.Assert(w[0].Page, qt.Equals, w.Next(w[4].Page))
}
diff --git a/resources/page/pages_related_test.go b/resources/page/pages_related_test.go
index 016b492c8..be75a62cd 100644
--- a/resources/page/pages_related_test.go
+++ b/resources/page/pages_related_test.go
@@ -19,11 +19,11 @@ import (
"github.com/gohugoio/hugo/common/types"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestRelated(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
t.Parallel()
@@ -53,28 +53,28 @@ func TestRelated(t *testing.T) {
result, err := pages.RelatedTo(types.NewKeyValuesStrings("keywords", "hugo", "rocks"))
- assert.NoError(err)
- assert.Len(result, 2)
- assert.Equal("Page 2", result[0].Title())
- assert.Equal("Page 1", result[1].Title())
+ c.Assert(err, qt.IsNil)
+ c.Assert(len(result), qt.Equals, 2)
+ c.Assert(result[0].Title(), qt.Equals, "Page 2")
+ c.Assert(result[1].Title(), qt.Equals, "Page 1")
result, err = pages.Related(pages[0])
- assert.NoError(err)
- assert.Len(result, 2)
- assert.Equal("Page 2", result[0].Title())
- assert.Equal("Page 3", result[1].Title())
+ c.Assert(err, qt.IsNil)
+ c.Assert(len(result), qt.Equals, 2)
+ c.Assert(result[0].Title(), qt.Equals, "Page 2")
+ c.Assert(result[1].Title(), qt.Equals, "Page 3")
result, err = pages.RelatedIndices(pages[0], "keywords")
- assert.NoError(err)
- assert.Len(result, 2)
- assert.Equal("Page 2", result[0].Title())
- assert.Equal("Page 3", result[1].Title())
+ c.Assert(err, qt.IsNil)
+ c.Assert(len(result), qt.Equals, 2)
+ c.Assert(result[0].Title(), qt.Equals, "Page 2")
+ c.Assert(result[1].Title(), qt.Equals, "Page 3")
result, err = pages.RelatedTo(types.NewKeyValuesStrings("keywords", "bep", "rocks"))
- assert.NoError(err)
- assert.Len(result, 2)
- assert.Equal("Page 2", result[0].Title())
- assert.Equal("Page 3", result[1].Title())
+ c.Assert(err, qt.IsNil)
+ c.Assert(len(result), qt.Equals, 2)
+ c.Assert(result[0].Title(), qt.Equals, "Page 2")
+ c.Assert(result[1].Title(), qt.Equals, "Page 3")
}
func mustParseDate(s string) time.Time {
diff --git a/resources/page/pages_sort_test.go b/resources/page/pages_sort_test.go
index c781de2f3..c9eb37c06 100644
--- a/resources/page/pages_sort_test.go
+++ b/resources/page/pages_sort_test.go
@@ -18,14 +18,22 @@ import (
"testing"
"time"
+ "github.com/gohugoio/hugo/htesting/hqt"
+ "github.com/gohugoio/hugo/source"
+
"github.com/gohugoio/hugo/resources/resource"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
+var eq = qt.CmpEquals(hqt.DeepAllowUnexported(
+ &testPage{},
+ &source.FileInfo{},
+))
+
func TestDefaultSort(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
d1 := time.Now()
d2 := d1.Add(-1 * time.Hour)
d3 := d1.Add(-2 * time.Hour)
@@ -37,31 +45,31 @@ func TestDefaultSort(t *testing.T) {
setSortVals([4]time.Time{d1, d2, d3, d4}, [4]string{"b", "a", "c", "d"}, [4]int{4, 3, 2, 1}, p)
SortByDefault(p)
- assert.Equal(t, 1, p[0].Weight())
+ c.Assert(p[0].Weight(), qt.Equals, 1)
// Consider zero weight, issue #2673
setSortVals([4]time.Time{d1, d2, d3, d4}, [4]string{"b", "a", "d", "c"}, [4]int{0, 0, 0, 1}, p)
SortByDefault(p)
- assert.Equal(t, 1, p[0].Weight())
+ c.Assert(p[0].Weight(), qt.Equals, 1)
// next by date
setSortVals([4]time.Time{d3, d4, d1, d2}, [4]string{"a", "b", "c", "d"}, [4]int{1, 1, 1, 1}, p)
SortByDefault(p)
- assert.Equal(t, d1, p[0].Date())
+ c.Assert(p[0].Date(), qt.Equals, d1)
// finally by link title
setSortVals([4]time.Time{d3, d3, d3, d3}, [4]string{"b", "c", "a", "d"}, [4]int{1, 1, 1, 1}, p)
SortByDefault(p)
- assert.Equal(t, "al", p[0].LinkTitle())
- assert.Equal(t, "bl", p[1].LinkTitle())
- assert.Equal(t, "cl", p[2].LinkTitle())
+ c.Assert(p[0].LinkTitle(), qt.Equals, "al")
+ c.Assert(p[1].LinkTitle(), qt.Equals, "bl")
+ c.Assert(p[2].LinkTitle(), qt.Equals, "cl")
}
// https://github.com/gohugoio/hugo/issues/4953
func TestSortByLinkTitle(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
pages := createSortTestPages(6)
for i, p := range pages {
@@ -81,11 +89,10 @@ func TestSortByLinkTitle(t *testing.T) {
bylt := pages.ByLinkTitle()
for i, p := range bylt {
- msg := fmt.Sprintf("test: %d", i)
if i < 3 {
- assert.Equal(fmt.Sprintf("linkTitle%d", i+3), p.LinkTitle(), msg)
+ c.Assert(p.LinkTitle(), qt.Equals, fmt.Sprintf("linkTitle%d", i+3))
} else {
- assert.Equal(fmt.Sprintf("title%d", i-3), p.LinkTitle(), msg)
+ c.Assert(p.LinkTitle(), qt.Equals, fmt.Sprintf("title%d", i-3))
}
}
}
@@ -124,30 +131,33 @@ func TestSortByN(t *testing.T) {
func TestLimit(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
p := createSortTestPages(10)
firstFive := p.Limit(5)
- assert.Equal(t, 5, len(firstFive))
+ c.Assert(len(firstFive), qt.Equals, 5)
for i := 0; i < 5; i++ {
- assert.Equal(t, p[i], firstFive[i])
+ c.Assert(firstFive[i], qt.Equals, p[i])
}
- assert.Equal(t, p, p.Limit(10))
- assert.Equal(t, p, p.Limit(11))
+ c.Assert(p.Limit(10), eq, p)
+ c.Assert(p.Limit(11), eq, p)
}
func TestPageSortReverse(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
p1 := createSortTestPages(10)
- assert.Equal(t, 0, p1[0].(*testPage).fuzzyWordCount)
- assert.Equal(t, 9, p1[9].(*testPage).fuzzyWordCount)
+ c.Assert(p1[0].(*testPage).fuzzyWordCount, qt.Equals, 0)
+ c.Assert(p1[9].(*testPage).fuzzyWordCount, qt.Equals, 9)
p2 := p1.Reverse()
- assert.Equal(t, 9, p2[0].(*testPage).fuzzyWordCount)
- assert.Equal(t, 0, p2[9].(*testPage).fuzzyWordCount)
+ c.Assert(p2[0].(*testPage).fuzzyWordCount, qt.Equals, 9)
+ c.Assert(p2[9].(*testPage).fuzzyWordCount, qt.Equals, 0)
// cached
- assert.True(t, pagesEqual(p2, p1.Reverse()))
+ c.Assert(pagesEqual(p2, p1.Reverse()), qt.Equals, true)
}
func TestPageSortByParam(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
var k interface{} = "arbitrarily.nested"
unsorted := createSortTestPages(10)
@@ -158,10 +168,10 @@ func TestPageSortByParam(t *testing.T) {
lastSetValue, _ := unsorted[8].Param(k)
unsetValue, _ := unsorted[9].Param(k)
- assert.Equal(t, "xyz100", firstSetValue)
- assert.Equal(t, "xyz99", secondSetValue)
- assert.Equal(t, "xyz92", lastSetValue)
- assert.Equal(t, nil, unsetValue)
+ c.Assert(firstSetValue, qt.Equals, "xyz100")
+ c.Assert(secondSetValue, qt.Equals, "xyz99")
+ c.Assert(lastSetValue, qt.Equals, "xyz92")
+ c.Assert(unsetValue, qt.Equals, nil)
sorted := unsorted.ByParam("arbitrarily.nested")
firstSetSortedValue, _ := sorted[0].Param(k)
@@ -169,14 +179,16 @@ func TestPageSortByParam(t *testing.T) {
lastSetSortedValue, _ := sorted[8].Param(k)
unsetSortedValue, _ := sorted[9].Param(k)
- assert.Equal(t, firstSetValue, firstSetSortedValue)
- assert.Equal(t, secondSetValue, lastSetSortedValue)
- assert.Equal(t, lastSetValue, secondSetSortedValue)
- assert.Equal(t, unsetValue, unsetSortedValue)
+ c.Assert(firstSetSortedValue, qt.Equals, firstSetValue)
+ c.Assert(lastSetSortedValue, qt.Equals, secondSetValue)
+ c.Assert(secondSetSortedValue, qt.Equals, lastSetValue)
+ c.Assert(unsetSortedValue, qt.Equals, unsetValue)
}
func TestPageSortByParamNumeric(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
+
var k interface{} = "arbitrarily.nested"
n := 10
@@ -200,10 +212,10 @@ func TestPageSortByParamNumeric(t *testing.T) {
lastSetValue, _ := unsorted[8].Param(k)
unsetValue, _ := unsorted[9].Param(k)
- assert.Equal(t, 100, firstSetValue)
- assert.Equal(t, 99, secondSetValue)
- assert.Equal(t, 92, lastSetValue)
- assert.Equal(t, nil, unsetValue)
+ c.Assert(firstSetValue, qt.Equals, 100)
+ c.Assert(secondSetValue, qt.Equals, 99)
+ c.Assert(lastSetValue, qt.Equals, 92)
+ c.Assert(unsetValue, qt.Equals, nil)
sorted := unsorted.ByParam("arbitrarily.nested")
firstSetSortedValue, _ := sorted[0].Param(k)
@@ -211,10 +223,10 @@ func TestPageSortByParamNumeric(t *testing.T) {
lastSetSortedValue, _ := sorted[8].Param(k)
unsetSortedValue, _ := sorted[9].Param(k)
- assert.Equal(t, 92, firstSetSortedValue)
- assert.Equal(t, 93, secondSetSortedValue)
- assert.Equal(t, 100, lastSetSortedValue)
- assert.Equal(t, unsetValue, unsetSortedValue)
+ c.Assert(firstSetSortedValue, qt.Equals, 92)
+ c.Assert(secondSetSortedValue, qt.Equals, 93)
+ c.Assert(lastSetSortedValue, qt.Equals, 100)
+ c.Assert(unsetSortedValue, qt.Equals, unsetValue)
}
func BenchmarkSortByWeightAndReverse(b *testing.B) {
diff --git a/resources/page/pages_test.go b/resources/page/pages_test.go
index c90d9f5d4..18b10f5bd 100644
--- a/resources/page/pages_test.go
+++ b/resources/page/pages_test.go
@@ -16,7 +16,7 @@ package page
import (
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestProbablyEq(t *testing.T) {
@@ -27,50 +27,50 @@ func TestProbablyEq(t *testing.T) {
pages123 := Pages{p1, p2, p3}
t.Run("Pages", func(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
- assert.True(pages12.ProbablyEq(pages12))
- assert.False(pages123.ProbablyEq(pages12))
- assert.False(pages12.ProbablyEq(pages21))
+ c.Assert(pages12.ProbablyEq(pages12), qt.Equals, true)
+ c.Assert(pages123.ProbablyEq(pages12), qt.Equals, false)
+ c.Assert(pages12.ProbablyEq(pages21), qt.Equals, false)
})
t.Run("PageGroup", func(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
- assert.True(PageGroup{Key: "a", Pages: pages12}.ProbablyEq(PageGroup{Key: "a", Pages: pages12}))
- assert.False(PageGroup{Key: "a", Pages: pages12}.ProbablyEq(PageGroup{Key: "b", Pages: pages12}))
+ c.Assert(PageGroup{Key: "a", Pages: pages12}.ProbablyEq(PageGroup{Key: "a", Pages: pages12}), qt.Equals, true)
+ c.Assert(PageGroup{Key: "a", Pages: pages12}.ProbablyEq(PageGroup{Key: "b", Pages: pages12}), qt.Equals, false)
})
t.Run("PagesGroup", func(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
pg1, pg2 := PageGroup{Key: "a", Pages: pages12}, PageGroup{Key: "b", Pages: pages123}
- assert.True(PagesGroup{pg1, pg2}.ProbablyEq(PagesGroup{pg1, pg2}))
- assert.False(PagesGroup{pg1, pg2}.ProbablyEq(PagesGroup{pg2, pg1}))
+ c.Assert(PagesGroup{pg1, pg2}.ProbablyEq(PagesGroup{pg1, pg2}), qt.Equals, true)
+ c.Assert(PagesGroup{pg1, pg2}.ProbablyEq(PagesGroup{pg2, pg1}), qt.Equals, false)
})
}
func TestToPages(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
p1, p2 := &testPage{title: "p1"}, &testPage{title: "p2"}
pages12 := Pages{p1, p2}
mustToPages := func(in interface{}) Pages {
p, err := ToPages(in)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
return p
}
- assert.Equal(Pages{}, mustToPages(nil))
- assert.Equal(pages12, mustToPages(pages12))
- assert.Equal(pages12, mustToPages([]Page{p1, p2}))
- assert.Equal(pages12, mustToPages([]interface{}{p1, p2}))
+ c.Assert(mustToPages(nil), eq, Pages{})
+ c.Assert(mustToPages(pages12), eq, pages12)
+ c.Assert(mustToPages([]Page{p1, p2}), eq, pages12)
+ c.Assert(mustToPages([]interface{}{p1, p2}), eq, pages12)
_, err := ToPages("not a page")
- assert.Error(err)
+ c.Assert(err, qt.Not(qt.IsNil))
}
diff --git a/resources/page/pagination_test.go b/resources/page/pagination_test.go
index 1308d60d1..f4441a892 100644
--- a/resources/page/pagination_test.go
+++ b/resources/page/pagination_test.go
@@ -20,43 +20,44 @@ import (
"github.com/spf13/viper"
+ qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/output"
- "github.com/stretchr/testify/require"
)
func TestSplitPages(t *testing.T) {
t.Parallel()
-
+ c := qt.New(t)
pages := createTestPages(21)
chunks := splitPages(pages, 5)
- require.Equal(t, 5, len(chunks))
+ c.Assert(len(chunks), qt.Equals, 5)
for i := 0; i < 4; i++ {
- require.Equal(t, 5, chunks[i].Len())
+ c.Assert(chunks[i].Len(), qt.Equals, 5)
}
lastChunk := chunks[4]
- require.Equal(t, 1, lastChunk.Len())
+ c.Assert(lastChunk.Len(), qt.Equals, 1)
}
func TestSplitPageGroups(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
pages := createTestPages(21)
groups, _ := pages.GroupBy("Weight", "desc")
chunks := splitPageGroups(groups, 5)
- require.Equal(t, 5, len(chunks))
+ c.Assert(len(chunks), qt.Equals, 5)
firstChunk := chunks[0]
// alternate weight 5 and 10
if groups, ok := firstChunk.(PagesGroup); ok {
- require.Equal(t, 5, groups.Len())
+ c.Assert(groups.Len(), qt.Equals, 5)
for _, pg := range groups {
// first group 10 in weight
- require.Equal(t, 10, pg.Key)
+ c.Assert(pg.Key, qt.Equals, 10)
for _, p := range pg.Pages {
- require.True(t, p.FuzzyWordCount()%2 == 0) // magic test
+ c.Assert(p.FuzzyWordCount()%2 == 0, qt.Equals, true) // magic test
}
}
} else {
@@ -66,12 +67,12 @@ func TestSplitPageGroups(t *testing.T) {
lastChunk := chunks[4]
if groups, ok := lastChunk.(PagesGroup); ok {
- require.Equal(t, 1, groups.Len())
+ c.Assert(groups.Len(), qt.Equals, 1)
for _, pg := range groups {
// last should have 5 in weight
- require.Equal(t, 5, pg.Key)
+ c.Assert(pg.Key, qt.Equals, 5)
for _, p := range pg.Pages {
- require.True(t, p.FuzzyWordCount()%2 != 0) // magic test
+ c.Assert(p.FuzzyWordCount()%2 != 0, qt.Equals, true) // magic test
}
}
} else {
@@ -82,6 +83,7 @@ func TestSplitPageGroups(t *testing.T) {
func TestPager(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
pages := createTestPages(21)
groups, _ := pages.GroupBy("Weight", "desc")
@@ -90,64 +92,65 @@ func TestPager(t *testing.T) {
}
_, err := newPaginatorFromPages(pages, -1, urlFactory)
- require.NotNil(t, err)
+ c.Assert(err, qt.Not(qt.IsNil))
_, err = newPaginatorFromPageGroups(groups, -1, urlFactory)
- require.NotNil(t, err)
+ c.Assert(err, qt.Not(qt.IsNil))
pag, err := newPaginatorFromPages(pages, 5, urlFactory)
- require.Nil(t, err)
+ c.Assert(err, qt.IsNil)
doTestPages(t, pag)
first := pag.Pagers()[0].First()
- require.Equal(t, "Pager 1", first.String())
- require.NotEmpty(t, first.Pages())
- require.Empty(t, first.PageGroups())
+ c.Assert(first.String(), qt.Equals, "Pager 1")
+ c.Assert(first.Pages(), qt.Not(qt.HasLen), 0)
+ c.Assert(first.PageGroups(), qt.HasLen, 0)
pag, err = newPaginatorFromPageGroups(groups, 5, urlFactory)
- require.Nil(t, err)
+ c.Assert(err, qt.IsNil)
doTestPages(t, pag)
first = pag.Pagers()[0].First()
- require.NotEmpty(t, first.PageGroups())
- require.Empty(t, first.Pages())
+ c.Assert(first.PageGroups(), qt.Not(qt.HasLen), 0)
+ c.Assert(first.Pages(), qt.HasLen, 0)
}
func doTestPages(t *testing.T, paginator *Paginator) {
-
+ c := qt.New(t)
paginatorPages := paginator.Pagers()
- require.Equal(t, 5, len(paginatorPages))
- require.Equal(t, 21, paginator.TotalNumberOfElements())
- require.Equal(t, 5, paginator.PageSize())
- require.Equal(t, 5, paginator.TotalPages())
+ c.Assert(len(paginatorPages), qt.Equals, 5)
+ c.Assert(paginator.TotalNumberOfElements(), qt.Equals, 21)
+ c.Assert(paginator.PageSize(), qt.Equals, 5)
+ c.Assert(paginator.TotalPages(), qt.Equals, 5)
first := paginatorPages[0]
- require.Equal(t, template.HTML("page/1/"), first.URL())
- require.Equal(t, first, first.First())
- require.True(t, first.HasNext())
- require.Equal(t, paginatorPages[1], first.Next())
- require.False(t, first.HasPrev())
- require.Nil(t, first.Prev())
- require.Equal(t, 5, first.NumberOfElements())
- require.Equal(t, 1, first.PageNumber())
+ c.Assert(first.URL(), qt.Equals, template.HTML("page/1/"))
+ c.Assert(first.First(), qt.Equals, first)
+ c.Assert(first.HasNext(), qt.Equals, true)
+ c.Assert(first.Next(), qt.Equals, paginatorPages[1])
+ c.Assert(first.HasPrev(), qt.Equals, false)
+ c.Assert(first.Prev(), qt.IsNil)
+ c.Assert(first.NumberOfElements(), qt.Equals, 5)
+ c.Assert(first.PageNumber(), qt.Equals, 1)
third := paginatorPages[2]
- require.True(t, third.HasNext())
- require.True(t, third.HasPrev())
- require.Equal(t, paginatorPages[1], third.Prev())
+ c.Assert(third.HasNext(), qt.Equals, true)
+ c.Assert(third.HasPrev(), qt.Equals, true)
+ c.Assert(third.Prev(), qt.Equals, paginatorPages[1])
last := paginatorPages[4]
- require.Equal(t, template.HTML("page/5/"), last.URL())
- require.Equal(t, last, last.Last())
- require.False(t, last.HasNext())
- require.Nil(t, last.Next())
- require.True(t, last.HasPrev())
- require.Equal(t, 1, last.NumberOfElements())
- require.Equal(t, 5, last.PageNumber())
+ c.Assert(last.URL(), qt.Equals, template.HTML("page/5/"))
+ c.Assert(last.Last(), qt.Equals, last)
+ c.Assert(last.HasNext(), qt.Equals, false)
+ c.Assert(last.Next(), qt.IsNil)
+ c.Assert(last.HasPrev(), qt.Equals, true)
+ c.Assert(last.NumberOfElements(), qt.Equals, 1)
+ c.Assert(last.PageNumber(), qt.Equals, 5)
}
func TestPagerNoPages(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
pages := createTestPages(0)
groups, _ := pages.GroupBy("Weight", "desc")
@@ -159,49 +162,50 @@ func TestPagerNoPages(t *testing.T) {
doTestPagerNoPages(t, paginator)
first := paginator.Pagers()[0].First()
- require.Empty(t, first.PageGroups())
- require.Empty(t, first.Pages())
+ c.Assert(first.PageGroups(), qt.HasLen, 0)
+ c.Assert(first.Pages(), qt.HasLen, 0)
paginator, _ = newPaginatorFromPageGroups(groups, 5, urlFactory)
doTestPagerNoPages(t, paginator)
first = paginator.Pagers()[0].First()
- require.Empty(t, first.PageGroups())
- require.Empty(t, first.Pages())
+ c.Assert(first.PageGroups(), qt.HasLen, 0)
+ c.Assert(first.Pages(), qt.HasLen, 0)
}
func doTestPagerNoPages(t *testing.T, paginator *Paginator) {
paginatorPages := paginator.Pagers()
-
- require.Equal(t, 1, len(paginatorPages))
- require.Equal(t, 0, paginator.TotalNumberOfElements())
- require.Equal(t, 5, paginator.PageSize())
- require.Equal(t, 0, paginator.TotalPages())
+ c := qt.New(t)
+ c.Assert(len(paginatorPages), qt.Equals, 1)
+ c.Assert(paginator.TotalNumberOfElements(), qt.Equals, 0)
+ c.Assert(paginator.PageSize(), qt.Equals, 5)
+ c.Assert(paginator.TotalPages(), qt.Equals, 0)
// pageOne should be nothing but the first
pageOne := paginatorPages[0]
- require.NotNil(t, pageOne.First())
- require.False(t, pageOne.HasNext())
- require.False(t, pageOne.HasPrev())
- require.Nil(t, pageOne.Next())
- require.Equal(t, 1, len(pageOne.Pagers()))
- require.Equal(t, 0, pageOne.Pages().Len())
- require.Equal(t, 0, pageOne.NumberOfElements())
- require.Equal(t, 0, pageOne.TotalNumberOfElements())
- require.Equal(t, 0, pageOne.TotalPages())
- require.Equal(t, 1, pageOne.PageNumber())
- require.Equal(t, 5, pageOne.PageSize())
+ c.Assert(pageOne.First(), qt.Not(qt.IsNil))
+ c.Assert(pageOne.HasNext(), qt.Equals, false)
+ c.Assert(pageOne.HasPrev(), qt.Equals, false)
+ c.Assert(pageOne.Next(), qt.IsNil)
+ c.Assert(len(pageOne.Pagers()), qt.Equals, 1)
+ c.Assert(pageOne.Pages().Len(), qt.Equals, 0)
+ c.Assert(pageOne.NumberOfElements(), qt.Equals, 0)
+ c.Assert(pageOne.TotalNumberOfElements(), qt.Equals, 0)
+ c.Assert(pageOne.TotalPages(), qt.Equals, 0)
+ c.Assert(pageOne.PageNumber(), qt.Equals, 1)
+ c.Assert(pageOne.PageSize(), qt.Equals, 5)
}
func TestPaginationURLFactory(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
cfg := viper.New()
cfg.Set("paginatePath", "zoo")
for _, uglyURLs := range []bool{false, true} {
- t.Run(fmt.Sprintf("uglyURLs=%t", uglyURLs), func(t *testing.T) {
+ c.Run(fmt.Sprintf("uglyURLs=%t", uglyURLs), func(c *qt.C) {
tests := []struct {
name string
@@ -231,9 +235,9 @@ func TestPaginationURLFactory(t *testing.T) {
got := factory(test.page)
if uglyURLs {
- require.Equal(t, test.expectedUgly, got)
+ c.Assert(got, qt.Equals, test.expectedUgly)
} else {
- require.Equal(t, test.expected, got)
+ c.Assert(got, qt.Equals, test.expected)
}
}
@@ -279,6 +283,7 @@ func TestProbablyEqualPageLists(t *testing.T) {
func TestPaginationPage(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
urlFactory := func(page int) string {
return fmt.Sprintf("page/%d/", page)
}
@@ -298,10 +303,10 @@ func TestPaginationPage(t *testing.T) {
page21, _ := f2.page(1)
page2Nil, _ := f2.page(3)
- require.Equal(t, 3, page11.FuzzyWordCount())
- require.Nil(t, page1Nil)
+ c.Assert(page11.FuzzyWordCount(), qt.Equals, 3)
+ c.Assert(page1Nil, qt.IsNil)
- require.NotNil(t, page21)
- require.Equal(t, 3, page21.FuzzyWordCount())
- require.Nil(t, page2Nil)
+ c.Assert(page21, qt.Not(qt.IsNil))
+ c.Assert(page21.FuzzyWordCount(), qt.Equals, 3)
+ c.Assert(page2Nil, qt.IsNil)
}
diff --git a/resources/page/permalinks_test.go b/resources/page/permalinks_test.go
index d7af7e06d..c9e55e7bd 100644
--- a/resources/page/permalinks_test.go
+++ b/resources/page/permalinks_test.go
@@ -19,7 +19,7 @@ import (
"testing"
"time"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
// testdataPermalinks is used by a couple of tests; the expandsTo content is
@@ -47,7 +47,7 @@ var testdataPermalinks = []struct {
func TestPermalinkExpansion(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
page := newTestPageWithFile("/test-page/index.md")
page.title = "Spf13 Vim 3.0 Release and new website"
@@ -56,10 +56,7 @@ func TestPermalinkExpansion(t *testing.T) {
page.section = "blue"
page.slug = "The Slug"
- for i, item := range testdataPermalinks {
-
- msg := fmt.Sprintf("Test %d", i)
-
+ for _, item := range testdataPermalinks {
if !item.valid {
continue
}
@@ -72,11 +69,11 @@ func TestPermalinkExpansion(t *testing.T) {
ps.Cfg.Set("permalinks", permalinksConfig)
expander, err := NewPermalinkExpander(ps)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
expanded, err := expander.Expand("posts", page)
- assert.NoError(err)
- assert.Equal(item.expandsTo, expanded, msg)
+ c.Assert(err, qt.IsNil)
+ c.Assert(expanded, qt.Equals, item.expandsTo)
}
}
@@ -84,7 +81,7 @@ func TestPermalinkExpansion(t *testing.T) {
func TestPermalinkExpansionMultiSection(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
page := newTestPage()
page.title = "Page Title"
@@ -102,22 +99,22 @@ func TestPermalinkExpansionMultiSection(t *testing.T) {
ps.Cfg.Set("permalinks", permalinksConfig)
expander, err := NewPermalinkExpander(ps)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
expanded, err := expander.Expand("posts", page)
- assert.NoError(err)
- assert.Equal("/the-slug", expanded)
+ c.Assert(err, qt.IsNil)
+ c.Assert(expanded, qt.Equals, "/the-slug")
expanded, err = expander.Expand("blog", page)
- assert.NoError(err)
- assert.Equal("/blue/2012", expanded)
+ c.Assert(err, qt.IsNil)
+ c.Assert(expanded, qt.Equals, "/blue/2012")
}
func TestPermalinkExpansionConcurrent(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
permalinksConfig := map[string]string{
"posts": "/:slug/",
@@ -127,7 +124,7 @@ func TestPermalinkExpansionConcurrent(t *testing.T) {
ps.Cfg.Set("permalinks", permalinksConfig)
expander, err := NewPermalinkExpander(ps)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
var wg sync.WaitGroup
@@ -139,8 +136,8 @@ func TestPermalinkExpansionConcurrent(t *testing.T) {
for j := 1; j < 20; j++ {
page.slug = fmt.Sprintf("slug%d", i+j)
expanded, err := expander.Expand("posts", page)
- assert.NoError(err)
- assert.Equal(fmt.Sprintf("/%s/", page.slug), expanded)
+ c.Assert(err, qt.IsNil)
+ c.Assert(expanded, qt.Equals, fmt.Sprintf("/%s/", page.slug))
}
}(i)
}
diff --git a/resources/resource_metadata_test.go b/resources/resource_metadata_test.go
index 1dd452ebf..bededcd1b 100644
--- a/resources/resource_metadata_test.go
+++ b/resources/resource_metadata_test.go
@@ -19,12 +19,12 @@ import (
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/resources/resource"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestAssignMetadata(t *testing.T) {
- assert := require.New(t)
- spec := newTestResourceSpec(assert)
+ c := qt.New(t)
+ spec := newTestResourceSpec(c)
var foo1, foo2, foo3, logo1, logo2, logo3 resource.Resource
var resources resource.Resources
@@ -40,9 +40,9 @@ func TestAssignMetadata(t *testing.T) {
"src": "*",
},
}, func(err error) {
- assert.Equal("My Resource", logo1.Title())
- assert.Equal("My Name", logo1.Name())
- assert.Equal("My Name", foo2.Name())
+ c.Assert(logo1.Title(), qt.Equals, "My Resource")
+ c.Assert(logo1.Name(), qt.Equals, "My Name")
+ c.Assert(foo2.Name(), qt.Equals, "My Name")
}},
{[]map[string]interface{}{
@@ -56,12 +56,12 @@ func TestAssignMetadata(t *testing.T) {
"src": "*",
},
}, func(err error) {
- assert.Equal("My Logo", logo1.Title())
- assert.Equal("My Logo", logo2.Title())
- assert.Equal("My Name", logo1.Name())
- assert.Equal("My Name", foo2.Name())
- assert.Equal("My Name", foo3.Name())
- assert.Equal("My Resource", foo3.Title())
+ c.Assert(logo1.Title(), qt.Equals, "My Logo")
+ c.Assert(logo2.Title(), qt.Equals, "My Logo")
+ c.Assert(logo1.Name(), qt.Equals, "My Name")
+ c.Assert(foo2.Name(), qt.Equals, "My Name")
+ c.Assert(foo3.Name(), qt.Equals, "My Name")
+ c.Assert(foo3.Title(), qt.Equals, "My Resource")
}},
{[]map[string]interface{}{
@@ -82,9 +82,9 @@ func TestAssignMetadata(t *testing.T) {
},
},
}, func(err error) {
- assert.NoError(err)
- assert.Equal("My Logo", logo1.Title())
- assert.Equal("My Resource", foo3.Title())
+ c.Assert(err, qt.IsNil)
+ c.Assert(logo1.Title(), qt.Equals, "My Logo")
+ c.Assert(foo3.Title(), qt.Equals, "My Resource")
_, p1 := logo2.Params()["param1"]
_, p2 := foo2.Params()["param2"]
_, p1_2 := foo2.Params()["param1"]
@@ -93,15 +93,15 @@ func TestAssignMetadata(t *testing.T) {
icon1 := logo2.Params()["icon"]
icon2 := foo2.Params()["icon"]
- assert.True(p1)
- assert.True(p2)
+ c.Assert(p1, qt.Equals, true)
+ c.Assert(p2, qt.Equals, true)
// Check merge
- assert.True(p2_2)
- assert.False(p1_2)
+ c.Assert(p2_2, qt.Equals, true)
+ c.Assert(p1_2, qt.Equals, false)
- assert.Equal("logo", icon1)
- assert.Equal("resource", icon2)
+ c.Assert(icon1, qt.Equals, "logo")
+ c.Assert(icon2, qt.Equals, "resource")
}},
{[]map[string]interface{}{
@@ -115,17 +115,17 @@ func TestAssignMetadata(t *testing.T) {
"src": "*",
},
}, func(err error) {
- assert.NoError(err)
- assert.Equal("Resource #2", logo2.Title())
- assert.Equal("Logo Name #1", logo2.Name())
- assert.Equal("Resource #4", logo1.Title())
- assert.Equal("Logo Name #2", logo1.Name())
- assert.Equal("Resource #1", foo2.Title())
- assert.Equal("Resource #3", foo1.Title())
- assert.Equal("Name #2", foo1.Name())
- assert.Equal("Resource #5", foo3.Title())
-
- assert.Equal(logo2, resources.GetMatch("logo name #1*"))
+ c.Assert(err, qt.IsNil)
+ c.Assert(logo2.Title(), qt.Equals, "Resource #2")
+ c.Assert(logo2.Name(), qt.Equals, "Logo Name #1")
+ c.Assert(logo1.Title(), qt.Equals, "Resource #4")
+ c.Assert(logo1.Name(), qt.Equals, "Logo Name #2")
+ c.Assert(foo2.Title(), qt.Equals, "Resource #1")
+ c.Assert(foo1.Title(), qt.Equals, "Resource #3")
+ c.Assert(foo1.Name(), qt.Equals, "Name #2")
+ c.Assert(foo3.Title(), qt.Equals, "Resource #5")
+
+ c.Assert(resources.GetMatch("logo name #1*"), qt.Equals, logo2)
}},
{[]map[string]interface{}{
@@ -139,13 +139,13 @@ func TestAssignMetadata(t *testing.T) {
"src": "logo*",
},
}, func(err error) {
- assert.NoError(err)
- assert.Equal("Third Logo #1", logo3.Title())
- assert.Equal("Name #3", logo3.Name())
- assert.Equal("Other Logo #1", logo2.Title())
- assert.Equal("Name #1", logo2.Name())
- assert.Equal("Other Logo #2", logo1.Title())
- assert.Equal("Name #2", logo1.Name())
+ c.Assert(err, qt.IsNil)
+ c.Assert(logo3.Title(), qt.Equals, "Third Logo #1")
+ c.Assert(logo3.Name(), qt.Equals, "Name #3")
+ c.Assert(logo2.Title(), qt.Equals, "Other Logo #1")
+ c.Assert(logo2.Name(), qt.Equals, "Name #1")
+ c.Assert(logo1.Title(), qt.Equals, "Other Logo #2")
+ c.Assert(logo1.Name(), qt.Equals, "Name #2")
}},
{[]map[string]interface{}{
@@ -159,13 +159,13 @@ func TestAssignMetadata(t *testing.T) {
"src": "logo*",
},
}, func(err error) {
- assert.NoError(err)
- assert.Equal("Third Logo", logo3.Title())
- assert.Equal("Name #3", logo3.Name())
- assert.Equal("Other Logo #1", logo2.Title())
- assert.Equal("Name #1", logo2.Name())
- assert.Equal("Other Logo #2", logo1.Title())
- assert.Equal("Name #2", logo1.Name())
+ c.Assert(err, qt.IsNil)
+ c.Assert(logo3.Title(), qt.Equals, "Third Logo")
+ c.Assert(logo3.Name(), qt.Equals, "Name #3")
+ c.Assert(logo2.Title(), qt.Equals, "Other Logo #1")
+ c.Assert(logo2.Name(), qt.Equals, "Name #1")
+ c.Assert(logo1.Title(), qt.Equals, "Other Logo #2")
+ c.Assert(logo1.Name(), qt.Equals, "Name #2")
}},
{[]map[string]interface{}{
@@ -179,13 +179,13 @@ func TestAssignMetadata(t *testing.T) {
"src": "logo*",
},
}, func(err error) {
- assert.NoError(err)
- assert.Equal("Logo #3", logo3.Title())
- assert.Equal("third-logo", logo3.Name())
- assert.Equal("Logo #1", logo2.Title())
- assert.Equal("Name #1", logo2.Name())
- assert.Equal("Logo #2", logo1.Title())
- assert.Equal("Name #2", logo1.Name())
+ c.Assert(err, qt.IsNil)
+ c.Assert(logo3.Title(), qt.Equals, "Logo #3")
+ c.Assert(logo3.Name(), qt.Equals, "third-logo")
+ c.Assert(logo2.Title(), qt.Equals, "Logo #1")
+ c.Assert(logo2.Name(), qt.Equals, "Name #1")
+ c.Assert(logo1.Title(), qt.Equals, "Logo #2")
+ c.Assert(logo1.Name(), qt.Equals, "Name #2")
}},
{[]map[string]interface{}{
@@ -194,7 +194,7 @@ func TestAssignMetadata(t *testing.T) {
},
}, func(err error) {
// Missing src
- assert.Error(err)
+ c.Assert(err, qt.Not(qt.IsNil))
}},
{[]map[string]interface{}{
@@ -204,7 +204,7 @@ func TestAssignMetadata(t *testing.T) {
},
}, func(err error) {
// Invalid pattern
- assert.Error(err)
+ c.Assert(err, qt.Not(qt.IsNil))
}},
} {
diff --git a/resources/resource_test.go b/resources/resource_test.go
index 565ae06c4..b6d93c9a6 100644
--- a/resources/resource_test.go
+++ b/resources/resource_test.go
@@ -27,38 +27,38 @@ import (
"github.com/gohugoio/hugo/media"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestGenericResource(t *testing.T) {
- assert := require.New(t)
- spec := newTestResourceSpec(assert)
+ c := qt.New(t)
+ spec := newTestResourceSpec(c)
r := spec.newGenericResource(nil, nil, nil, "/a/foo.css", "foo.css", media.CSSType)
- assert.Equal("https://example.com/foo.css", r.Permalink())
- assert.Equal("/foo.css", r.RelPermalink())
- assert.Equal("css", r.ResourceType())
+ c.Assert(r.Permalink(), qt.Equals, "https://example.com/foo.css")
+ c.Assert(r.RelPermalink(), qt.Equals, "/foo.css")
+ c.Assert(r.ResourceType(), qt.Equals, "css")
}
func TestGenericResourceWithLinkFacory(t *testing.T) {
- assert := require.New(t)
- spec := newTestResourceSpec(assert)
+ c := qt.New(t)
+ spec := newTestResourceSpec(c)
factory := newTargetPaths("/foo")
r := spec.newGenericResource(nil, factory, nil, "/a/foo.css", "foo.css", media.CSSType)
- assert.Equal("https://example.com/foo/foo.css", r.Permalink())
- assert.Equal("/foo/foo.css", r.RelPermalink())
- assert.Equal("foo.css", r.Key())
- assert.Equal("css", r.ResourceType())
+ c.Assert(r.Permalink(), qt.Equals, "https://example.com/foo/foo.css")
+ c.Assert(r.RelPermalink(), qt.Equals, "/foo/foo.css")
+ c.Assert(r.Key(), qt.Equals, "foo.css")
+ c.Assert(r.ResourceType(), qt.Equals, "css")
}
func TestNewResourceFromFilename(t *testing.T) {
- assert := require.New(t)
- spec := newTestResourceSpec(assert)
+ c := qt.New(t)
+ spec := newTestResourceSpec(c)
writeSource(t, spec.Fs, "content/a/b/logo.png", "image")
writeSource(t, spec.Fs, "content/a/b/data.json", "json")
@@ -67,26 +67,26 @@ func TestNewResourceFromFilename(t *testing.T) {
r, err := spec.New(ResourceSourceDescriptor{Fs: bfs, SourceFilename: "a/b/logo.png"})
- assert.NoError(err)
- assert.NotNil(r)
- assert.Equal("image", r.ResourceType())
- assert.Equal("/a/b/logo.png", r.RelPermalink())
- assert.Equal("https://example.com/a/b/logo.png", r.Permalink())
+ c.Assert(err, qt.IsNil)
+ c.Assert(r, qt.Not(qt.IsNil))
+ c.Assert(r.ResourceType(), qt.Equals, "image")
+ c.Assert(r.RelPermalink(), qt.Equals, "/a/b/logo.png")
+ c.Assert(r.Permalink(), qt.Equals, "https://example.com/a/b/logo.png")
r, err = spec.New(ResourceSourceDescriptor{Fs: bfs, SourceFilename: "a/b/data.json"})
- assert.NoError(err)
- assert.NotNil(r)
- assert.Equal("json", r.ResourceType())
+ c.Assert(err, qt.IsNil)
+ c.Assert(r, qt.Not(qt.IsNil))
+ c.Assert(r.ResourceType(), qt.Equals, "json")
cloned := r.(resource.Cloner).WithNewBase("aceof")
- assert.Equal(r.ResourceType(), cloned.ResourceType())
- assert.Equal("/aceof/a/b/data.json", cloned.RelPermalink())
+ c.Assert(cloned.ResourceType(), qt.Equals, r.ResourceType())
+ c.Assert(cloned.RelPermalink(), qt.Equals, "/aceof/a/b/data.json")
}
func TestNewResourceFromFilenameSubPathInBaseURL(t *testing.T) {
- assert := require.New(t)
- spec := newTestResourceSpecForBaseURL(assert, "https://example.com/docs")
+ c := qt.New(t)
+ spec := newTestResourceSpecForBaseURL(c, "https://example.com/docs")
writeSource(t, spec.Fs, "content/a/b/logo.png", "image")
bfs := afero.NewBasePathFs(spec.Fs.Source, "content")
@@ -94,35 +94,35 @@ func TestNewResourceFromFilenameSubPathInBaseURL(t *testing.T) {
fmt.Println()
r, err := spec.New(ResourceSourceDescriptor{Fs: bfs, SourceFilename: filepath.FromSlash("a/b/logo.png")})
- assert.NoError(err)
- assert.NotNil(r)
- assert.Equal("image", r.ResourceType())
- assert.Equal("/docs/a/b/logo.png", r.RelPermalink())
- assert.Equal("https://example.com/docs/a/b/logo.png", r.Permalink())
+ c.Assert(err, qt.IsNil)
+ c.Assert(r, qt.Not(qt.IsNil))
+ c.Assert(r.ResourceType(), qt.Equals, "image")
+ c.Assert(r.RelPermalink(), qt.Equals, "/docs/a/b/logo.png")
+ c.Assert(r.Permalink(), qt.Equals, "https://example.com/docs/a/b/logo.png")
img := r.(*Image)
- assert.Equal(filepath.FromSlash("/a/b/logo.png"), img.targetFilenames()[0])
+ c.Assert(img.targetFilenames()[0], qt.Equals, filepath.FromSlash("/a/b/logo.png"))
}
var pngType, _ = media.FromStringAndExt("image/png", "png")
func TestResourcesByType(t *testing.T) {
- assert := require.New(t)
- spec := newTestResourceSpec(assert)
+ c := qt.New(t)
+ spec := newTestResourceSpec(c)
resources := resource.Resources{
spec.newGenericResource(nil, nil, nil, "/a/foo1.css", "foo1.css", media.CSSType),
spec.newGenericResource(nil, nil, nil, "/a/logo.png", "logo.css", pngType),
spec.newGenericResource(nil, nil, nil, "/a/foo2.css", "foo2.css", media.CSSType),
spec.newGenericResource(nil, nil, nil, "/a/foo3.css", "foo3.css", media.CSSType)}
- assert.Len(resources.ByType("css"), 3)
- assert.Len(resources.ByType("image"), 1)
+ c.Assert(len(resources.ByType("css")), qt.Equals, 3)
+ c.Assert(len(resources.ByType("image")), qt.Equals, 1)
}
func TestResourcesGetByPrefix(t *testing.T) {
- assert := require.New(t)
- spec := newTestResourceSpec(assert)
+ c := qt.New(t)
+ spec := newTestResourceSpec(c)
resources := resource.Resources{
spec.newGenericResource(nil, nil, nil, "/a/foo1.css", "foo1.css", media.CSSType),
spec.newGenericResource(nil, nil, nil, "/a/logo1.png", "logo1.png", pngType),
@@ -130,28 +130,28 @@ func TestResourcesGetByPrefix(t *testing.T) {
spec.newGenericResource(nil, nil, nil, "/b/foo2.css", "foo2.css", media.CSSType),
spec.newGenericResource(nil, nil, nil, "/b/foo3.css", "foo3.css", media.CSSType)}
- assert.Nil(resources.GetMatch("asdf*"))
- assert.Equal("/logo1.png", resources.GetMatch("logo*").RelPermalink())
- assert.Equal("/logo1.png", resources.GetMatch("loGo*").RelPermalink())
- assert.Equal("/Logo2.png", resources.GetMatch("logo2*").RelPermalink())
- assert.Equal("/foo2.css", resources.GetMatch("foo2*").RelPermalink())
- assert.Equal("/foo1.css", resources.GetMatch("foo1*").RelPermalink())
- assert.Equal("/foo1.css", resources.GetMatch("foo1*").RelPermalink())
- assert.Nil(resources.GetMatch("asdfasdf*"))
+ c.Assert(resources.GetMatch("asdf*"), qt.IsNil)
+ c.Assert(resources.GetMatch("logo*").RelPermalink(), qt.Equals, "/logo1.png")
+ c.Assert(resources.GetMatch("loGo*").RelPermalink(), qt.Equals, "/logo1.png")
+ c.Assert(resources.GetMatch("logo2*").RelPermalink(), qt.Equals, "/Logo2.png")
+ c.Assert(resources.GetMatch("foo2*").RelPermalink(), qt.Equals, "/foo2.css")
+ c.Assert(resources.GetMatch("foo1*").RelPermalink(), qt.Equals, "/foo1.css")
+ c.Assert(resources.GetMatch("foo1*").RelPermalink(), qt.Equals, "/foo1.css")
+ c.Assert(resources.GetMatch("asdfasdf*"), qt.IsNil)
- assert.Equal(2, len(resources.Match("logo*")))
- assert.Equal(1, len(resources.Match("logo2*")))
+ c.Assert(len(resources.Match("logo*")), qt.Equals, 2)
+ c.Assert(len(resources.Match("logo2*")), qt.Equals, 1)
logo := resources.GetMatch("logo*")
- assert.NotNil(logo.Params())
- assert.Equal("logo1.png", logo.Name())
- assert.Equal("logo1.png", logo.Title())
+ c.Assert(logo.Params(), qt.Not(qt.IsNil))
+ c.Assert(logo.Name(), qt.Equals, "logo1.png")
+ c.Assert(logo.Title(), qt.Equals, "logo1.png")
}
func TestResourcesGetMatch(t *testing.T) {
- assert := require.New(t)
- spec := newTestResourceSpec(assert)
+ c := qt.New(t)
+ spec := newTestResourceSpec(c)
resources := resource.Resources{
spec.newGenericResource(nil, nil, nil, "/a/foo1.css", "foo1.css", media.CSSType),
spec.newGenericResource(nil, nil, nil, "/a/logo1.png", "logo1.png", pngType),
@@ -163,35 +163,35 @@ func TestResourcesGetMatch(t *testing.T) {
spec.newGenericResource(nil, nil, nil, "/b/c/d/foo6.css", "c/d/foo6.css", media.CSSType),
}
- assert.Equal("/logo1.png", resources.GetMatch("logo*").RelPermalink())
- assert.Equal("/logo1.png", resources.GetMatch("loGo*").RelPermalink())
- assert.Equal("/Logo2.png", resources.GetMatch("logo2*").RelPermalink())
- assert.Equal("/foo2.css", resources.GetMatch("foo2*").RelPermalink())
- assert.Equal("/foo1.css", resources.GetMatch("foo1*").RelPermalink())
- assert.Equal("/foo1.css", resources.GetMatch("foo1*").RelPermalink())
- assert.Equal("/c/foo4.css", resources.GetMatch("*/foo*").RelPermalink())
+ c.Assert(resources.GetMatch("logo*").RelPermalink(), qt.Equals, "/logo1.png")
+ c.Assert(resources.GetMatch("loGo*").RelPermalink(), qt.Equals, "/logo1.png")
+ c.Assert(resources.GetMatch("logo2*").RelPermalink(), qt.Equals, "/Logo2.png")
+ c.Assert(resources.GetMatch("foo2*").RelPermalink(), qt.Equals, "/foo2.css")
+ c.Assert(resources.GetMatch("foo1*").RelPermalink(), qt.Equals, "/foo1.css")
+ c.Assert(resources.GetMatch("foo1*").RelPermalink(), qt.Equals, "/foo1.css")
+ c.Assert(resources.GetMatch("*/foo*").RelPermalink(), qt.Equals, "/c/foo4.css")
- assert.Nil(resources.GetMatch("asdfasdf"))
+ c.Assert(resources.GetMatch("asdfasdf"), qt.IsNil)
- assert.Equal(2, len(resources.Match("Logo*")))
- assert.Equal(1, len(resources.Match("logo2*")))
- assert.Equal(2, len(resources.Match("c/*")))
+ c.Assert(len(resources.Match("Logo*")), qt.Equals, 2)
+ c.Assert(len(resources.Match("logo2*")), qt.Equals, 1)
+ c.Assert(len(resources.Match("c/*")), qt.Equals, 2)
- assert.Equal(6, len(resources.Match("**.css")))
- assert.Equal(3, len(resources.Match("**/*.css")))
- assert.Equal(1, len(resources.Match("c/**/*.css")))
+ c.Assert(len(resources.Match("**.css")), qt.Equals, 6)
+ c.Assert(len(resources.Match("**/*.css")), qt.Equals, 3)
+ c.Assert(len(resources.Match("c/**/*.css")), qt.Equals, 1)
// Matches only CSS files in c/
- assert.Equal(3, len(resources.Match("c/**.css")))
+ c.Assert(len(resources.Match("c/**.css")), qt.Equals, 3)
// Matches all CSS files below c/ (including in c/d/)
- assert.Equal(3, len(resources.Match("c/**.css")))
+ c.Assert(len(resources.Match("c/**.css")), qt.Equals, 3)
// Patterns beginning with a slash will not match anything.
// We could maybe consider trimming that slash, but let's be explicit about this.
// (it is possible for users to do a rename)
// This is analogous to standing in a directory and doing "ls *.*".
- assert.Equal(0, len(resources.Match("/c/**.css")))
+ c.Assert(len(resources.Match("/c/**.css")), qt.Equals, 0)
}
@@ -212,8 +212,8 @@ func BenchmarkResourcesMatch(b *testing.B) {
// I don't expect Hugo users to "stumble upon" this problem, so this is more to satisfy
// my own curiosity.
func BenchmarkResourcesMatchA100(b *testing.B) {
- assert := require.New(b)
- spec := newTestResourceSpec(assert)
+ c := qt.New(b)
+ spec := newTestResourceSpec(c)
a100 := strings.Repeat("a", 100)
pattern := "a*a*a*a*a*a*a*a*b"
@@ -227,8 +227,8 @@ func BenchmarkResourcesMatchA100(b *testing.B) {
}
func benchResources(b *testing.B) resource.Resources {
- assert := require.New(b)
- spec := newTestResourceSpec(assert)
+ c := qt.New(b)
+ spec := newTestResourceSpec(c)
var resources resource.Resources
for i := 0; i < 30; i++ {
@@ -251,8 +251,8 @@ func benchResources(b *testing.B) resource.Resources {
}
func BenchmarkAssignMetadata(b *testing.B) {
- assert := require.New(b)
- spec := newTestResourceSpec(assert)
+ c := qt.New(b)
+ spec := newTestResourceSpec(c)
for i := 0; i < b.N; i++ {
b.StopTimer()
diff --git a/resources/resource_transformers/integrity/integrity_test.go b/resources/resource_transformers/integrity/integrity_test.go
index 7e32e3275..cb1caa006 100644
--- a/resources/resource_transformers/integrity/integrity_test.go
+++ b/resources/resource_transformers/integrity/integrity_test.go
@@ -16,7 +16,7 @@ package integrity
import (
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestHashFromAlgo(t *testing.T) {
@@ -33,14 +33,14 @@ func TestHashFromAlgo(t *testing.T) {
} {
t.Run(algo.name, func(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
h, err := newHash(algo.name)
if algo.bits > 0 {
- assert.NoError(err)
- assert.Equal(algo.bits/8, h.Size())
+ c.Assert(err, qt.IsNil)
+ c.Assert(h.Size(), qt.Equals, algo.bits/8)
} else {
- assert.Error(err)
- assert.Contains(err.Error(), "use either md5, sha256, sha384 or sha512")
+ c.Assert(err, qt.Not(qt.IsNil))
+ c.Assert(err.Error(), qt.Contains, "use either md5, sha256, sha384 or sha512")
}
})
diff --git a/resources/resource_transformers/postcss/postcss_test.go b/resources/resource_transformers/postcss/postcss_test.go
index b6b365f32..39936d6b4 100644
--- a/resources/resource_transformers/postcss/postcss_test.go
+++ b/resources/resource_transformers/postcss/postcss_test.go
@@ -16,24 +16,24 @@ package postcss
import (
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
// Issue 6166
func TestDecodeOptions(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
opts1, err := DecodeOptions(map[string]interface{}{
"no-map": true,
})
- assert.NoError(err)
- assert.True(opts1.NoMap)
+ c.Assert(err, qt.IsNil)
+ c.Assert(opts1.NoMap, qt.Equals, true)
opts2, err := DecodeOptions(map[string]interface{}{
"noMap": true,
})
- assert.NoError(err)
- assert.True(opts2.NoMap)
+ c.Assert(err, qt.IsNil)
+ c.Assert(opts2.NoMap, qt.Equals, true)
}
diff --git a/resources/testhelpers_test.go b/resources/testhelpers_test.go
index 8aeb1768f..55664535c 100644
--- a/resources/testhelpers_test.go
+++ b/resources/testhelpers_test.go
@@ -4,6 +4,8 @@ import (
"path/filepath"
"testing"
+ "github.com/gohugoio/hugo/htesting/hqt"
+
"image"
"io"
"io/ioutil"
@@ -14,6 +16,7 @@ import (
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/modules"
+ qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/cache/filecache"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
@@ -23,11 +26,10 @@ import (
"github.com/gohugoio/hugo/resources/resource"
"github.com/spf13/afero"
"github.com/spf13/viper"
- "github.com/stretchr/testify/require"
)
-func newTestResourceSpec(assert *require.Assertions) *Spec {
- return newTestResourceSpecForBaseURL(assert, "https://example.com/")
+func newTestResourceSpec(c *qt.C) *Spec {
+ return newTestResourceSpecForBaseURL(c, "https://example.com/")
}
func createTestCfg() *viper.Viper {
@@ -52,7 +54,7 @@ func createTestCfg() *viper.Viper {
}
-func newTestResourceSpecForBaseURL(assert *require.Assertions, baseURL string) *Spec {
+func newTestResourceSpecForBaseURL(c *qt.C, baseURL string) *Spec {
cfg := createTestCfg()
cfg.Set("baseURL", baseURL)
@@ -67,13 +69,13 @@ func newTestResourceSpecForBaseURL(assert *require.Assertions, baseURL string) *
fs := hugofs.NewMem(cfg)
s, err := helpers.NewPathSpec(fs, cfg, nil)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
filecaches, err := filecache.NewCaches(s)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
spec, err := NewSpec(s, filecaches, nil, output.DefaultFormats, media.DefaultTypes)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
return spec
}
@@ -86,7 +88,7 @@ func newTargetPaths(link string) func() page.TargetPaths {
}
}
-func newTestResourceOsFs(assert *require.Assertions) *Spec {
+func newTestResourceOsFs(c *qt.C) *Spec {
cfg := createTestCfg()
cfg.Set("baseURL", "https://example.com")
@@ -104,66 +106,66 @@ func newTestResourceOsFs(assert *require.Assertions) *Spec {
fs.Destination = &afero.MemMapFs{}
s, err := helpers.NewPathSpec(fs, cfg, nil)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
filecaches, err := filecache.NewCaches(s)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
spec, err := NewSpec(s, filecaches, nil, output.DefaultFormats, media.DefaultTypes)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
return spec
}
-func fetchSunset(assert *require.Assertions) *Image {
- return fetchImage(assert, "sunset.jpg")
+func fetchSunset(c *qt.C) *Image {
+ return fetchImage(c, "sunset.jpg")
}
-func fetchImage(assert *require.Assertions, name string) *Image {
- spec := newTestResourceSpec(assert)
- return fetchImageForSpec(spec, assert, name)
+func fetchImage(c *qt.C, name string) *Image {
+ spec := newTestResourceSpec(c)
+ return fetchImageForSpec(spec, c, name)
}
-func fetchImageForSpec(spec *Spec, assert *require.Assertions, name string) *Image {
- r := fetchResourceForSpec(spec, assert, name)
- assert.IsType(&Image{}, r)
+func fetchImageForSpec(spec *Spec, c *qt.C, name string) *Image {
+ r := fetchResourceForSpec(spec, c, name)
+ c.Assert(r, hqt.IsSameType, &Image{})
return r.(*Image)
}
-func fetchResourceForSpec(spec *Spec, assert *require.Assertions, name string) resource.ContentResource {
+func fetchResourceForSpec(spec *Spec, c *qt.C, name string) resource.ContentResource {
src, err := os.Open(filepath.FromSlash("testdata/" + name))
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
out, err := helpers.OpenFileForWriting(spec.Fs.Source, name)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
_, err = io.Copy(out, src)
out.Close()
src.Close()
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
factory := newTargetPaths("/a")
r, err := spec.New(ResourceSourceDescriptor{Fs: spec.Fs.Source, TargetPaths: factory, LazyPublish: true, SourceFilename: name})
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
return r.(resource.ContentResource)
}
-func assertImageFile(assert *require.Assertions, fs afero.Fs, filename string, width, height int) {
+func assertImageFile(c *qt.C, fs afero.Fs, filename string, width, height int) {
filename = filepath.Clean(filename)
f, err := fs.Open(filename)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
defer f.Close()
config, _, err := image.DecodeConfig(f)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
- assert.Equal(width, config.Width)
- assert.Equal(height, config.Height)
+ c.Assert(config.Width, qt.Equals, width)
+ c.Assert(config.Height, qt.Equals, height)
}
-func assertFileCache(assert *require.Assertions, fs afero.Fs, filename string, width, height int) {
- assertImageFile(assert, fs, filepath.Clean(filename), width, height)
+func assertFileCache(c *qt.C, fs afero.Fs, filename string, width, height int) {
+ assertImageFile(c, fs, filepath.Clean(filename), width, height)
}
func writeSource(t testing.TB, fs *hugofs.Fs, filename, content string) {
diff --git a/resources/transform_test.go b/resources/transform_test.go
index ed462cd2a..2019bda39 100644
--- a/resources/transform_test.go
+++ b/resources/transform_test.go
@@ -16,7 +16,7 @@ package resources
import (
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
type testStruct struct {
@@ -31,6 +31,6 @@ func TestResourceTransformationKey(t *testing.T) {
// We really need this key to be portable across OSes.
key := NewResourceTransformationKey("testing",
testStruct{Name: "test", V1: int64(10), V2: int32(20), V3: 30, V4: uint64(40)})
- assert := require.New(t)
- assert.Equal(key.key(), "testing_518996646957295636")
+ c := qt.New(t)
+ c.Assert("testing_518996646957295636", qt.Equals, key.key())
}