mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
tests: Convert from testify to quicktest
This commit is contained in:
@@ -17,18 +17,18 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
qt "github.com/frankban/quicktest"
|
||||
)
|
||||
|
||||
func TestIsValidConfigFileName(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
for _, ext := range ValidConfigFileExtensions {
|
||||
filename := "config." + ext
|
||||
assert.True(IsValidConfigFilename(filename), ext)
|
||||
assert.True(IsValidConfigFilename(strings.ToUpper(filename)))
|
||||
c.Assert(IsValidConfigFilename(filename), qt.Equals, true)
|
||||
c.Assert(IsValidConfigFilename(strings.ToUpper(filename)), qt.Equals, true)
|
||||
}
|
||||
|
||||
assert.False(IsValidConfigFilename(""))
|
||||
assert.False(IsValidConfigFilename("config.toml.swp"))
|
||||
c.Assert(IsValidConfigFilename(""), qt.Equals, false)
|
||||
c.Assert(IsValidConfigFilename("config.toml.swp"), qt.Equals, false)
|
||||
}
|
||||
|
@@ -16,12 +16,12 @@ package config
|
||||
import (
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetStringSlicePreserveString(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
cfg := viper.New()
|
||||
|
||||
s := "This is a string"
|
||||
@@ -30,7 +30,7 @@ func TestGetStringSlicePreserveString(t *testing.T) {
|
||||
cfg.Set("s1", s)
|
||||
cfg.Set("s2", sSlice)
|
||||
|
||||
assert.Equal([]string{s}, GetStringSlicePreserveString(cfg, "s1"))
|
||||
assert.Equal(sSlice, GetStringSlicePreserveString(cfg, "s2"))
|
||||
assert.Nil(GetStringSlicePreserveString(cfg, "s3"))
|
||||
c.Assert(GetStringSlicePreserveString(cfg, "s1"), qt.DeepEquals, []string{s})
|
||||
c.Assert(GetStringSlicePreserveString(cfg, "s2"), qt.DeepEquals, sSlice)
|
||||
c.Assert(GetStringSlicePreserveString(cfg, "s3"), qt.IsNil)
|
||||
}
|
||||
|
@@ -16,17 +16,17 @@ package config
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
qt "github.com/frankban/quicktest"
|
||||
)
|
||||
|
||||
func TestSetEnvVars(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
vars := []string{"FOO=bar", "HUGO=cool", "BAR=foo"}
|
||||
SetEnvVars(&vars, "HUGO", "rocking!", "NEW", "bar")
|
||||
assert.Equal([]string{"FOO=bar", "HUGO=rocking!", "BAR=foo", "NEW=bar"}, vars)
|
||||
c.Assert(vars, qt.DeepEquals, []string{"FOO=bar", "HUGO=rocking!", "BAR=foo", "NEW=bar"})
|
||||
|
||||
key, val := SplitEnvVar("HUGO=rocks")
|
||||
assert.Equal("HUGO", key)
|
||||
assert.Equal("rocks", val)
|
||||
c.Assert(key, qt.Equals, "HUGO")
|
||||
c.Assert(val, qt.Equals, "rocks")
|
||||
}
|
||||
|
@@ -16,13 +16,13 @@ package privacy
|
||||
import (
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDecodeConfigFromTOML(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
tomlConfig := `
|
||||
|
||||
@@ -52,30 +52,27 @@ privacyEnhanced = true
|
||||
simple = true
|
||||
`
|
||||
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
pc, err := DecodeConfig(cfg)
|
||||
assert.NoError(err)
|
||||
assert.NotNil(pc)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(pc, qt.Not(qt.IsNil))
|
||||
|
||||
got := []bool{
|
||||
pc.Disqus.Disable, pc.GoogleAnalytics.Disable,
|
||||
pc.GoogleAnalytics.RespectDoNotTrack, pc.GoogleAnalytics.AnonymizeIP,
|
||||
pc.GoogleAnalytics.UseSessionStorage, pc.Instagram.Disable,
|
||||
pc.Instagram.Simple, pc.Twitter.Disable, pc.Twitter.EnableDNT,
|
||||
pc.Twitter.Simple, pc.Vimeo.Disable, pc.Vimeo.Simple,
|
||||
pc.YouTube.PrivacyEnhanced, pc.YouTube.Disable,
|
||||
}
|
||||
|
||||
c.Assert(got, qt.All(qt.Equals), true)
|
||||
|
||||
assert.True(pc.Disqus.Disable)
|
||||
assert.True(pc.GoogleAnalytics.Disable)
|
||||
assert.True(pc.GoogleAnalytics.RespectDoNotTrack)
|
||||
assert.True(pc.GoogleAnalytics.AnonymizeIP)
|
||||
assert.True(pc.GoogleAnalytics.UseSessionStorage)
|
||||
assert.True(pc.Instagram.Disable)
|
||||
assert.True(pc.Instagram.Simple)
|
||||
assert.True(pc.Twitter.Disable)
|
||||
assert.True(pc.Twitter.EnableDNT)
|
||||
assert.True(pc.Twitter.Simple)
|
||||
assert.True(pc.Vimeo.Disable)
|
||||
assert.True(pc.Vimeo.Simple)
|
||||
assert.True(pc.YouTube.PrivacyEnhanced)
|
||||
assert.True(pc.YouTube.Disable)
|
||||
}
|
||||
|
||||
func TestDecodeConfigFromTOMLCaseInsensitive(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
tomlConfig := `
|
||||
|
||||
@@ -86,19 +83,19 @@ someOtherValue = "foo"
|
||||
PrivacyENhanced = true
|
||||
`
|
||||
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
pc, err := DecodeConfig(cfg)
|
||||
assert.NoError(err)
|
||||
assert.NotNil(pc)
|
||||
assert.True(pc.YouTube.PrivacyEnhanced)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(pc, qt.Not(qt.IsNil))
|
||||
c.Assert(pc.YouTube.PrivacyEnhanced, qt.Equals, true)
|
||||
}
|
||||
|
||||
func TestDecodeConfigDefault(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
pc, err := DecodeConfig(viper.New())
|
||||
assert.NoError(err)
|
||||
assert.NotNil(pc)
|
||||
assert.False(pc.YouTube.PrivacyEnhanced)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(pc, qt.Not(qt.IsNil))
|
||||
c.Assert(pc.YouTube.PrivacyEnhanced, qt.Equals, false)
|
||||
}
|
||||
|
@@ -16,13 +16,13 @@ package services
|
||||
import (
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDecodeConfigFromTOML(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
tomlConfig := `
|
||||
|
||||
@@ -39,31 +39,31 @@ disableInlineCSS = true
|
||||
disableInlineCSS = true
|
||||
`
|
||||
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
config, err := DecodeConfig(cfg)
|
||||
assert.NoError(err)
|
||||
assert.NotNil(config)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(config, qt.Not(qt.IsNil))
|
||||
|
||||
assert.Equal("DS", config.Disqus.Shortname)
|
||||
assert.Equal("ga_id", config.GoogleAnalytics.ID)
|
||||
c.Assert(config.Disqus.Shortname, qt.Equals, "DS")
|
||||
c.Assert(config.GoogleAnalytics.ID, qt.Equals, "ga_id")
|
||||
|
||||
assert.True(config.Instagram.DisableInlineCSS)
|
||||
c.Assert(config.Instagram.DisableInlineCSS, qt.Equals, true)
|
||||
}
|
||||
|
||||
// Support old root-level GA settings etc.
|
||||
func TestUseSettingsFromRootIfSet(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
cfg := viper.New()
|
||||
cfg.Set("disqusShortname", "root_short")
|
||||
cfg.Set("googleAnalytics", "ga_root")
|
||||
|
||||
config, err := DecodeConfig(cfg)
|
||||
assert.NoError(err)
|
||||
assert.NotNil(config)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(config, qt.Not(qt.IsNil))
|
||||
|
||||
assert.Equal("root_short", config.Disqus.Shortname)
|
||||
assert.Equal("ga_root", config.GoogleAnalytics.ID)
|
||||
c.Assert(config.Disqus.Shortname, qt.Equals, "root_short")
|
||||
c.Assert(config.GoogleAnalytics.ID, qt.Equals, "ga_root")
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user