diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-10 21:05:17 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-12 13:26:32 +0200 |
commit | 9e571827055dedb46b78c5db3d17d6913f14870b (patch) | |
tree | f5f0108afe0c9385ff6dc27664943d9f719f57ad /hugolib | |
parent | 6027ee11082d0b9d72de1d4d1980a702be294ad2 (diff) |
tests: Convert from testify to quicktest
Diffstat (limited to 'hugolib')
43 files changed, 1051 insertions, 1021 deletions
diff --git a/hugolib/alias_test.go b/hugolib/alias_test.go index 095ae1be2..b0491c13e 100644 --- a/hugolib/alias_test.go +++ b/hugolib/alias_test.go @@ -20,7 +20,7 @@ import ( "github.com/gohugoio/hugo/common/loggers" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) const pageWithAlias = `--- @@ -43,14 +43,14 @@ const aliasTemplate = "<html><body>ALIASTEMPLATE</body></html>" func TestAlias(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) b := newTestSitesBuilder(t) b.WithSimpleConfigFile().WithContent("blog/page.md", pageWithAlias) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - require.Len(t, b.H.Sites[0].RegularPages(), 1) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 1) // the real page b.AssertFileContent("public/blog/page/index.html", "For some moments the old man") @@ -62,7 +62,7 @@ func TestAlias(t *testing.T) { func TestAliasMultipleOutputFormats(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) b := newTestSitesBuilder(t) b.WithSimpleConfigFile().WithContent("blog/page.md", pageWithAliasMultipleOutputs) @@ -82,7 +82,7 @@ func TestAliasMultipleOutputFormats(t *testing.T) { // the alias redirectors b.AssertFileContent("public/foo/bar/index.html", "<meta http-equiv=\"refresh\" content=\"0; ") b.AssertFileContent("public/amp/foo/bar/index.html", "<meta http-equiv=\"refresh\" content=\"0; ") - assert.False(b.CheckExists("public/foo/bar/index.json")) + c.Assert(b.CheckExists("public/foo/bar/index.json"), qt.Equals, false) } func TestAliasTemplate(t *testing.T) { diff --git a/hugolib/cascade_test.go b/hugolib/cascade_test.go index aebd7a825..d6701cf28 100644 --- a/hugolib/cascade_test.go +++ b/hugolib/cascade_test.go @@ -19,10 +19,9 @@ import ( "path" "testing" - "github.com/alecthomas/assert" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/parser" "github.com/gohugoio/hugo/parser/metadecoders" - "github.com/stretchr/testify/require" ) func BenchmarkCascade(b *testing.B) { @@ -31,7 +30,7 @@ func BenchmarkCascade(b *testing.B) { for i := 1; i <= len(allLangs); i += 2 { langs := allLangs[0:i] b.Run(fmt.Sprintf("langs-%d", len(langs)), func(b *testing.B) { - assert := require.New(b) + c := qt.New(b) b.StopTimer() builders := make([]*sitesBuilder, b.N) for i := 0; i < b.N; i++ { @@ -42,16 +41,15 @@ func BenchmarkCascade(b *testing.B) { for i := 0; i < b.N; i++ { builder := builders[i] err := builder.BuildE(BuildCfg{}) - assert.NoError(err) + c.Assert(err, qt.IsNil) first := builder.H.Sites[0] - assert.NotNil(first) + c.Assert(first, qt.Not(qt.IsNil)) } }) } } func TestCascade(t *testing.T) { - assert := assert.New(t) allLangs := []string{"en", "nn", "nb", "sv"} @@ -93,7 +91,7 @@ func TestCascade(t *testing.T) { // Check output formats set in cascade b.AssertFileContent("public/sect4/index.xml", `<link>https://example.org/sect4/index.xml</link>`) b.AssertFileContent("public/sect4/p1/index.xml", `<link>https://example.org/sect4/p1/index.xml</link>`) - assert.False(b.CheckExists("public/sect2/index.xml")) + b.C.Assert(b.CheckExists("public/sect2/index.xml"), qt.Equals, false) // Check cascade into bundled page b.AssertFileContent("public/bundle1/index.html", `Resources: bp1.md|home.png|`) diff --git a/hugolib/case_insensitive_test.go b/hugolib/case_insensitive_test.go index 8c94bf5db..bffffb6be 100644 --- a/hugolib/case_insensitive_test.go +++ b/hugolib/case_insensitive_test.go @@ -21,9 +21,9 @@ import ( "github.com/gohugoio/hugo/hugofs" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/spf13/afero" - "github.com/stretchr/testify/require" ) var ( @@ -135,6 +135,8 @@ Partial Site Global: {{ site.Params.COLOR }}|{{ site.Params.COLORS.YELLOW }} func TestCaseInsensitiveConfigurationVariations(t *testing.T) { t.Parallel() + c := qt.New(t) + // See issues 2615, 1129, 2590 and maybe some others // Also see 2598 // @@ -152,11 +154,11 @@ func TestCaseInsensitiveConfigurationVariations(t *testing.T) { caseMixingTestsWriteCommonSources(t, mm) cfg, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Filename: "config.toml"}) - require.NoError(t, err) + c.Assert(err, qt.IsNil) fs := hugofs.NewFrom(mm, cfg) - th := testHelper{cfg, fs, t} + th := newTestHelper(cfg, fs, t) writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), ` Block Page Colors: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }} @@ -258,17 +260,17 @@ func TestCaseInsensitiveConfigurationForAllTemplateEngines(t *testing.T) { } func doTestCaseInsensitiveConfigurationForTemplateEngine(t *testing.T, suffix string, templateFixer func(s string) string) { - + c := qt.New(t) mm := afero.NewMemMapFs() caseMixingTestsWriteCommonSources(t, mm) cfg, err := LoadConfigDefault(mm) - require.NoError(t, err) + c.Assert(err, qt.IsNil) fs := hugofs.NewFrom(mm, cfg) - th := testHelper{cfg, fs, t} + th := newTestHelper(cfg, fs, t) t.Log("Testing", suffix) diff --git a/hugolib/collections_test.go b/hugolib/collections_test.go index 804c0cae1..6925d41cd 100644 --- a/hugolib/collections_test.go +++ b/hugolib/collections_test.go @@ -17,11 +17,11 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestGroupFunc(t *testing.T) { - assert := require.New(t) + c := qt.New(t) pageContent := ` --- @@ -39,14 +39,14 @@ title: "Page" `) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - require.Len(t, b.H.Sites[0].RegularPages(), 2) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 2) b.AssertFileContent("public/index.html", "cool: 2") } func TestSliceFunc(t *testing.T) { - assert := require.New(t) + c := qt.New(t) pageContent := ` --- @@ -78,8 +78,8 @@ tags_weight: %d `) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - require.Len(t, b.H.Sites[0].RegularPages(), 2) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 2) b.AssertFileContent("public/index.html", "pages:2:page.Pages:Page(/page1.md)/Page(/page2.md)", @@ -88,7 +88,7 @@ tags_weight: %d } func TestUnionFunc(t *testing.T) { - assert := require.New(t) + c := qt.New(t) pageContent := ` --- @@ -110,8 +110,8 @@ tags_weight: %d `) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - require.Len(t, b.H.Sites[0].RegularPages(), 3) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 3) b.AssertFileContent("public/index.html", "unionPages: page.Pages 3", @@ -119,7 +119,7 @@ tags_weight: %d } func TestCollectionsFuncs(t *testing.T) { - assert := require.New(t) + c := qt.New(t) pageContent := ` --- @@ -151,8 +151,8 @@ Symdiff: {{ range $symdiff }}{{ .RelPermalink }}|{{ end }} `) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - require.Len(t, b.H.Sites[0].RegularPages(), 3) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 3) b.AssertFileContent("public/index.html", "uniqPages: page.Pages 3", @@ -164,7 +164,7 @@ Symdiff: {{ range $symdiff }}{{ .RelPermalink }}|{{ end }} } func TestAppendFunc(t *testing.T) { - assert := require.New(t) + c := qt.New(t) pageContent := ` --- @@ -203,8 +203,8 @@ tags_weight: %d `) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - assert.Len(b.H.Sites[0].RegularPages(), 2) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 2) b.AssertFileContent("public/index.html", "pages:2:page.Pages:Page(/page2.md)/Page(/page1.md)", diff --git a/hugolib/config_test.go b/hugolib/config_test.go index bd980235f..a52e3f061 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -19,15 +19,15 @@ import ( "path/filepath" "testing" + qt "github.com/frankban/quicktest" "github.com/spf13/afero" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) func TestLoadConfig(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) // Add a random config variable for testing. // side = page in Norwegian. @@ -40,16 +40,16 @@ func TestLoadConfig(t *testing.T) { writeToFs(t, mm, "hugo.toml", configContent) cfg, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Filename: "hugo.toml"}) - require.NoError(t, err) + c.Assert(err, qt.IsNil) - assert.Equal("side", cfg.GetString("paginatePath")) + c.Assert(cfg.GetString("paginatePath"), qt.Equals, "side") } func TestLoadMultiConfig(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) // Add a random config variable for testing. // side = page in Norwegian. @@ -67,16 +67,16 @@ func TestLoadMultiConfig(t *testing.T) { writeToFs(t, mm, "override.toml", configContentSub) cfg, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Filename: "base.toml,override.toml"}) - require.NoError(t, err) + c.Assert(err, qt.IsNil) - assert.Equal("top", cfg.GetString("paginatePath")) - assert.Equal("same", cfg.GetString("DontChange")) + c.Assert(cfg.GetString("paginatePath"), qt.Equals, "top") + c.Assert(cfg.GetString("DontChange"), qt.Equals, "same") } func TestLoadConfigFromTheme(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) mainConfigBasic := ` theme = "test-theme" @@ -291,7 +291,7 @@ map[string]interface {}{ } `, got["menus"]) - assert.Equal("https://example.com/", got["baseurl"]) + c.Assert(got["baseurl"], qt.Equals, "https://example.com/") if true { return @@ -314,7 +314,7 @@ map[string]interface {}{ }, }`, got["params"]) - assert.Nil(got["languages"]) + c.Assert(got["languages"], qt.IsNil) b.AssertObject(` map[string]interface {}{ "text/m1": map[string]interface {}{ @@ -365,7 +365,7 @@ map[string]interface {}{ func TestPrivacyConfig(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) tomlConfig := ` @@ -380,14 +380,14 @@ privacyEnhanced = true b.WithConfigFile("toml", tomlConfig) b.Build(BuildCfg{SkipRender: true}) - assert.True(b.H.Sites[0].Info.Config().Privacy.YouTube.PrivacyEnhanced) + c.Assert(b.H.Sites[0].Info.Config().Privacy.YouTube.PrivacyEnhanced, qt.Equals, true) } func TestLoadConfigModules(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) // https://github.com/gohugoio/hugoThemes#themetoml @@ -469,18 +469,20 @@ path="n4" var graphb bytes.Buffer modulesClient.Graph(&graphb) - assert.Equal(`project n1 + expected := `project n1 n1 o1 o1 n2 n1 n3 project n4 -`, graphb.String()) +` + + c.Assert(graphb.String(), qt.Equals, expected) } func TestLoadConfigWithOsEnvOverrides(t *testing.T) { - assert := require.New(t) + c := qt.New(t) baseConfig := ` @@ -512,13 +514,13 @@ resamplefilter = "CatmullRom" cfg := b.H.Cfg - assert.Equal("test", cfg.Get("environment")) - assert.Equal(false, cfg.GetBool("enablegitinfo")) - assert.Equal("new", cfg.Get("new")) - assert.Equal("top", cfg.Get("imaging.anchor")) - assert.Equal(int64(75), cfg.Get("imaging.quality")) - assert.Equal([]interface{}{"c", "d"}, cfg.Get("stringSlice")) - assert.Equal([]interface{}{5.32}, cfg.Get("floatSlice")) - assert.Equal([]interface{}{5, 8, 9}, cfg.Get("intSlice")) + c.Assert(cfg.Get("environment"), qt.Equals, "test") + c.Assert(cfg.GetBool("enablegitinfo"), qt.Equals, false) + c.Assert(cfg.Get("new"), qt.Equals, "new") + c.Assert(cfg.Get("imaging.anchor"), qt.Equals, "top") + c.Assert(cfg.Get("imaging.quality"), qt.Equals, int64(75)) + c.Assert(cfg.Get("stringSlice"), qt.DeepEquals, []interface{}{"c", "d"}) + c.Assert(cfg.Get("floatSlice"), qt.DeepEquals, []interface{}{5.32}) + c.Assert(cfg.Get("intSlice"), qt.DeepEquals, []interface{}{5, 8, 9}) } diff --git a/hugolib/configdir_test.go b/hugolib/configdir_test.go index c1afbb14e..bc1732fb2 100644 --- a/hugolib/configdir_test.go +++ b/hugolib/configdir_test.go @@ -19,15 +19,15 @@ import ( "github.com/gohugoio/hugo/common/herrors" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/htesting" "github.com/spf13/afero" - "github.com/stretchr/testify/require" ) func TestLoadConfigDir(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) configContent := ` baseURL = "https://example.org" @@ -107,29 +107,29 @@ p3 = "p3params_no_production" fb.Build() cfg, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Environment: "development", Filename: "hugo.toml", AbsConfigDir: "config"}) - assert.NoError(err) + c.Assert(err, qt.IsNil) - assert.Equal("pag_development", cfg.GetString("paginatePath")) // /config/development/config.toml + c.Assert(cfg.GetString("paginatePath"), qt.Equals, "pag_development") // /config/development/config.toml - assert.Equal(10, cfg.GetInt("languages.no.weight")) // /config.toml - assert.Equal("Norsk_no_default", cfg.GetString("languages.no.languageName")) // /config/_default/languages.no.toml + c.Assert(cfg.GetInt("languages.no.weight"), qt.Equals, 10) // /config.toml + c.Assert(cfg.GetString("languages.no.languageName"), qt.Equals, "Norsk_no_default") // /config/_default/languages.no.toml - assert.Equal("p1_base", cfg.GetString("params.p1")) - assert.Equal("p2params_default", cfg.GetString("params.p2")) // Is in both _default and production - assert.Equal("p3params_development", cfg.GetString("params.p3")) - assert.Equal("p3params_no_development", cfg.GetString("languages.no.params.p3")) + c.Assert(cfg.GetString("params.p1"), qt.Equals, "p1_base") + c.Assert(cfg.GetString("params.p2"), qt.Equals, "p2params_default") // Is in both _default and production + c.Assert(cfg.GetString("params.p3"), qt.Equals, "p3params_development") + c.Assert(cfg.GetString("languages.no.params.p3"), qt.Equals, "p3params_no_development") - assert.Equal(2, len(cfg.Get("menus.docs").(([]map[string]interface{})))) + c.Assert(len(cfg.Get("menus.docs").(([]map[string]interface{}))), qt.Equals, 2) noMenus := cfg.Get("languages.no.menus.docs") - assert.NotNil(noMenus) - assert.Equal(1, len(noMenus.(([]map[string]interface{})))) + c.Assert(noMenus, qt.Not(qt.IsNil)) + c.Assert(len(noMenus.(([]map[string]interface{}))), qt.Equals, 1) } func TestLoadConfigDirError(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) configContent := ` baseURL = "https://example.org" @@ -145,10 +145,10 @@ baseURL = "https://example.org" fb.Add("config.toml", `invalid & syntax`).Build() _, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Environment: "development", Filename: "hugo.toml", AbsConfigDir: "config"}) - assert.Error(err) + c.Assert(err, qt.Not(qt.IsNil)) fe := herrors.UnwrapErrorWithFileContext(err) - assert.NotNil(fe) - assert.Equal(filepath.FromSlash("config/development/config.toml"), fe.Position().Filename) + c.Assert(fe, qt.Not(qt.IsNil)) + c.Assert(fe.Position().Filename, qt.Equals, filepath.FromSlash("config/development/config.toml")) } diff --git a/hugolib/datafiles_test.go b/hugolib/datafiles_test.go index b65183a8a..699cf9cd8 100644 --- a/hugolib/datafiles_test.go +++ b/hugolib/datafiles_test.go @@ -16,7 +16,6 @@ package hugolib import ( "path/filepath" "reflect" - "strings" "testing" "github.com/gohugoio/hugo/common/loggers" @@ -26,7 +25,7 @@ import ( "fmt" "runtime" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestDataDir(t *testing.T) { @@ -377,6 +376,7 @@ func TestDataFromShortcode(t *testing.T) { var ( cfg, fs = newTestCfg() + c = qt.New(t) ) writeSource(t, fs, "data/hugo.toml", "slogan = \"Hugo Rocks!\"") @@ -392,7 +392,7 @@ Slogan from shortcode: {{< d >}} buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) content := readSource(t, fs, "public/c/index.html") - require.True(t, strings.Contains(content, "Slogan from template: Hugo Rocks!"), content) - require.True(t, strings.Contains(content, "Slogan from shortcode: Hugo Rocks!"), content) + c.Assert(content, qt.Contains, "Slogan from template: Hugo Rocks!") + c.Assert(content, qt.Contains, "Slogan from shortcode: Hugo Rocks!") } diff --git a/hugolib/disableKinds_test.go b/hugolib/disableKinds_test.go index c191dfef1..b26385cc3 100644 --- a/hugolib/disableKinds_test.go +++ b/hugolib/disableKinds_test.go @@ -18,10 +18,10 @@ import ( "fmt" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/helpers" - "github.com/stretchr/testify/require" ) func TestDisableKindsNoneDisabled(t *testing.T) { @@ -104,8 +104,6 @@ categories: b.Build(BuildCfg{}) h := b.H - req |