tests: Convert from testify to quicktest

This commit is contained in:
Bjørn Erik Pedersen
2019-08-10 21:05:17 +02:00
parent 6027ee1108
commit 9e57182705
195 changed files with 3919 additions and 3693 deletions

View File

@@ -17,19 +17,19 @@ import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
qt "github.com/frankban/quicktest"
)
func TestHugoInfo(t *testing.T) {
assert := require.New(t)
c := qt.New(t)
hugoInfo := NewInfo("")
assert.Equal(CurrentVersion.Version(), hugoInfo.Version())
assert.IsType(VersionString(""), hugoInfo.Version())
assert.Equal(commitHash, hugoInfo.CommitHash)
assert.Equal(buildDate, hugoInfo.BuildDate)
assert.Equal("production", hugoInfo.Environment)
assert.Contains(hugoInfo.Generator(), fmt.Sprintf("Hugo %s", hugoInfo.Version()))
c.Assert(hugoInfo.Version(), qt.Equals, CurrentVersion.Version())
c.Assert(fmt.Sprintf("%T", VersionString("")), qt.Equals, fmt.Sprintf("%T", hugoInfo.Version()))
c.Assert(hugoInfo.CommitHash, qt.Equals, commitHash)
c.Assert(hugoInfo.BuildDate, qt.Equals, buildDate)
c.Assert(hugoInfo.Environment, qt.Equals, "production")
c.Assert(string(hugoInfo.Generator()), qt.Contains, fmt.Sprintf("Hugo %s", hugoInfo.Version()))
}

View File

@@ -16,70 +16,73 @@ package hugo
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
qt "github.com/frankban/quicktest"
)
func TestHugoVersion(t *testing.T) {
assert.Equal(t, "0.15-DEV", version(0.15, 0, "-DEV"))
assert.Equal(t, "0.15.2-DEV", version(0.15, 2, "-DEV"))
c := qt.New(t)
c.Assert(version(0.15, 0, "-DEV"), qt.Equals, "0.15-DEV")
c.Assert(version(0.15, 2, "-DEV"), qt.Equals, "0.15.2-DEV")
v := Version{Number: 0.21, PatchLevel: 0, Suffix: "-DEV"}
require.Equal(t, v.ReleaseVersion().String(), "0.21")
require.Equal(t, "0.21-DEV", v.String())
require.Equal(t, "0.22", v.Next().String())
c.Assert(v.ReleaseVersion().String(), qt.Equals, "0.21")
c.Assert(v.String(), qt.Equals, "0.21-DEV")
c.Assert(v.Next().String(), qt.Equals, "0.22")
nextVersionString := v.Next().Version()
require.Equal(t, "0.22", nextVersionString.String())
require.True(t, nextVersionString.Eq("0.22"))
require.False(t, nextVersionString.Eq("0.21"))
require.True(t, nextVersionString.Eq(nextVersionString))
require.Equal(t, "0.20.3", v.NextPatchLevel(3).String())
c.Assert(nextVersionString.String(), qt.Equals, "0.22")
c.Assert(nextVersionString.Eq("0.22"), qt.Equals, true)
c.Assert(nextVersionString.Eq("0.21"), qt.Equals, false)
c.Assert(nextVersionString.Eq(nextVersionString), qt.Equals, true)
c.Assert(v.NextPatchLevel(3).String(), qt.Equals, "0.20.3")
// We started to use full semver versions even for main
// releases in v0.54.0
v = Version{Number: 0.53, PatchLevel: 0}
require.Equal(t, "0.53", v.String())
require.Equal(t, "0.54.0", v.Next().String())
require.Equal(t, "0.55.0", v.Next().Next().String())
c.Assert(v.String(), qt.Equals, "0.53")
c.Assert(v.Next().String(), qt.Equals, "0.54.0")
c.Assert(v.Next().Next().String(), qt.Equals, "0.55.0")
v = Version{Number: 0.54, PatchLevel: 0, Suffix: "-DEV"}
require.Equal(t, "0.54.0-DEV", v.String())
c.Assert(v.String(), qt.Equals, "0.54.0-DEV")
}
func TestCompareVersions(t *testing.T) {
require.Equal(t, 0, compareVersions(0.20, 0, 0.20))
require.Equal(t, 0, compareVersions(0.20, 0, float32(0.20)))
require.Equal(t, 0, compareVersions(0.20, 0, float64(0.20)))
require.Equal(t, 1, compareVersions(0.19, 1, 0.20))
require.Equal(t, 1, compareVersions(0.19, 3, "0.20.2"))
require.Equal(t, -1, compareVersions(0.19, 1, 0.01))
require.Equal(t, 1, compareVersions(0, 1, 3))
require.Equal(t, 1, compareVersions(0, 1, int32(3)))
require.Equal(t, 1, compareVersions(0, 1, int64(3)))
require.Equal(t, 0, compareVersions(0.20, 0, "0.20"))
require.Equal(t, 0, compareVersions(0.20, 1, "0.20.1"))
require.Equal(t, -1, compareVersions(0.20, 1, "0.20"))
require.Equal(t, 1, compareVersions(0.20, 0, "0.20.1"))
require.Equal(t, 1, compareVersions(0.20, 1, "0.20.2"))
require.Equal(t, 1, compareVersions(0.21, 1, "0.22.1"))
require.Equal(t, -1, compareVersions(0.22, 0, "0.22-DEV"))
require.Equal(t, 1, compareVersions(0.22, 0, "0.22.1-DEV"))
require.Equal(t, 1, compareVersionsWithSuffix(0.22, 0, "-DEV", "0.22"))
require.Equal(t, -1, compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22"))
require.Equal(t, 0, compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22.1-DEV"))
c := qt.New(t)
c.Assert(compareVersions(0.20, 0, 0.20), qt.Equals, 0)
c.Assert(compareVersions(0.20, 0, float32(0.20)), qt.Equals, 0)
c.Assert(compareVersions(0.20, 0, float64(0.20)), qt.Equals, 0)
c.Assert(compareVersions(0.19, 1, 0.20), qt.Equals, 1)
c.Assert(compareVersions(0.19, 3, "0.20.2"), qt.Equals, 1)
c.Assert(compareVersions(0.19, 1, 0.01), qt.Equals, -1)
c.Assert(compareVersions(0, 1, 3), qt.Equals, 1)
c.Assert(compareVersions(0, 1, int32(3)), qt.Equals, 1)
c.Assert(compareVersions(0, 1, int64(3)), qt.Equals, 1)
c.Assert(compareVersions(0.20, 0, "0.20"), qt.Equals, 0)
c.Assert(compareVersions(0.20, 1, "0.20.1"), qt.Equals, 0)
c.Assert(compareVersions(0.20, 1, "0.20"), qt.Equals, -1)
c.Assert(compareVersions(0.20, 0, "0.20.1"), qt.Equals, 1)
c.Assert(compareVersions(0.20, 1, "0.20.2"), qt.Equals, 1)
c.Assert(compareVersions(0.21, 1, "0.22.1"), qt.Equals, 1)
c.Assert(compareVersions(0.22, 0, "0.22-DEV"), qt.Equals, -1)
c.Assert(compareVersions(0.22, 0, "0.22.1-DEV"), qt.Equals, 1)
c.Assert(compareVersionsWithSuffix(0.22, 0, "-DEV", "0.22"), qt.Equals, 1)
c.Assert(compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22"), qt.Equals, -1)
c.Assert(compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22.1-DEV"), qt.Equals, 0)
}
func TestParseHugoVersion(t *testing.T) {
require.Equal(t, "0.25", MustParseVersion("0.25").String())
require.Equal(t, "0.25.2", MustParseVersion("0.25.2").String())
require.Equal(t, "0.25-test", MustParseVersion("0.25-test").String())
require.Equal(t, "0.25-DEV", MustParseVersion("0.25-DEV").String())
c := qt.New(t)
c.Assert(MustParseVersion("0.25").String(), qt.Equals, "0.25")
c.Assert(MustParseVersion("0.25.2").String(), qt.Equals, "0.25.2")
c.Assert(MustParseVersion("0.25-test").String(), qt.Equals, "0.25-test")
c.Assert(MustParseVersion("0.25-DEV").String(), qt.Equals, "0.25-DEV")
}
func TestGoMinorVersion(t *testing.T) {
assert := require.New(t)
assert.Equal(12, goMinorVersion("go1.12.5"))
assert.True(GoMinorVersion() >= 11)
c := qt.New(t)
c.Assert(goMinorVersion("go1.12.5"), qt.Equals, 12)
c.Assert(GoMinorVersion() >= 11, qt.Equals, true)
}