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

@@ -14,15 +14,14 @@
package metadecoders
import (
"fmt"
"reflect"
"testing"
"github.com/stretchr/testify/require"
qt "github.com/frankban/quicktest"
)
func TestUnmarshalToMap(t *testing.T) {
assert := require.New(t)
c := qt.New(t)
expect := map[string]interface{}{"a": "b"}
@@ -44,19 +43,19 @@ func TestUnmarshalToMap(t *testing.T) {
{`a = b`, TOML, false},
{`a,b,c`, CSV, false}, // Use Unmarshal for CSV
} {
msg := fmt.Sprintf("%d: %s", i, test.format)
msg := qt.Commentf("%d: %s", i, test.format)
m, err := d.UnmarshalToMap([]byte(test.data), test.format)
if b, ok := test.expect.(bool); ok && !b {
assert.Error(err, msg)
c.Assert(err, qt.Not(qt.IsNil), msg)
} else {
assert.NoError(err, msg)
assert.Equal(test.expect, m, msg)
c.Assert(err, qt.IsNil, msg)
c.Assert(m, qt.DeepEquals, test.expect, msg)
}
}
}
func TestUnmarshalToInterface(t *testing.T) {
assert := require.New(t)
c := qt.New(t)
expect := map[string]interface{}{"a": "b"}
@@ -77,13 +76,13 @@ func TestUnmarshalToInterface(t *testing.T) {
// errors
{`a = "`, TOML, false},
} {
msg := fmt.Sprintf("%d: %s", i, test.format)
msg := qt.Commentf("%d: %s", i, test.format)
m, err := d.Unmarshal([]byte(test.data), test.format)
if b, ok := test.expect.(bool); ok && !b {
assert.Error(err, msg)
c.Assert(err, qt.Not(qt.IsNil), msg)
} else {
assert.NoError(err, msg)
assert.Equal(test.expect, m, msg)
c.Assert(err, qt.IsNil, msg)
c.Assert(m, qt.DeepEquals, test.expect, msg)
}
}
@@ -91,7 +90,7 @@ func TestUnmarshalToInterface(t *testing.T) {
}
func TestUnmarshalStringTo(t *testing.T) {
assert := require.New(t)
c := qt.New(t)
d := Default
@@ -110,13 +109,13 @@ func TestUnmarshalStringTo(t *testing.T) {
{"[3,7,9]", []interface{}{}, []interface{}{3, 7, 9}},
{"[3.1,7.2,9.3]", []interface{}{}, []interface{}{3.1, 7.2, 9.3}},
} {
msg := fmt.Sprintf("%d: %T", i, test.to)
msg := qt.Commentf("%d: %T", i, test.to)
m, err := d.UnmarshalStringTo(test.data, test.to)
if b, ok := test.expect.(bool); ok && !b {
assert.Error(err, msg)
c.Assert(err, qt.Not(qt.IsNil), msg)
} else {
assert.NoError(err, msg)
assert.Equal(test.expect, m, msg)
c.Assert(err, qt.IsNil, msg)
c.Assert(m, qt.DeepEquals, test.expect, msg)
}
}

View File

@@ -14,19 +14,18 @@
package metadecoders
import (
"fmt"
"testing"
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/parser/pageparser"
"github.com/stretchr/testify/require"
qt "github.com/frankban/quicktest"
)
func TestFormatFromString(t *testing.T) {
assert := require.New(t)
for i, test := range []struct {
c := qt.New(t)
for _, test := range []struct {
s string
expect Format
}{
@@ -39,13 +38,13 @@ func TestFormatFromString(t *testing.T) {
{"org", ORG},
{"foo", ""},
} {
assert.Equal(test.expect, FormatFromString(test.s), fmt.Sprintf("t%d", i))
c.Assert(FormatFromString(test.s), qt.Equals, test.expect)
}
}
func TestFormatFromMediaType(t *testing.T) {
assert := require.New(t)
for i, test := range []struct {
c := qt.New(t)
for _, test := range []struct {
m media.Type
expect Format
}{
@@ -54,13 +53,13 @@ func TestFormatFromMediaType(t *testing.T) {
{media.TOMLType, TOML},
{media.CalendarType, ""},
} {
assert.Equal(test.expect, FormatFromMediaType(test.m), fmt.Sprintf("t%d", i))
c.Assert(FormatFromMediaType(test.m), qt.Equals, test.expect)
}
}
func TestFormatFromFrontMatterType(t *testing.T) {
assert := require.New(t)
for i, test := range []struct {
c := qt.New(t)
for _, test := range []struct {
typ pageparser.ItemType
expect Format
}{
@@ -70,13 +69,13 @@ func TestFormatFromFrontMatterType(t *testing.T) {
{pageparser.TypeFrontMatterORG, ORG},
{pageparser.TypeIgnore, ""},
} {
assert.Equal(test.expect, FormatFromFrontMatterType(test.typ), fmt.Sprintf("t%d", i))
c.Assert(FormatFromFrontMatterType(test.typ), qt.Equals, test.expect)
}
}
func TestFormatFromContentString(t *testing.T) {
t.Parallel()
assert := require.New(t)
c := qt.New(t)
for i, test := range []struct {
data string
@@ -92,10 +91,10 @@ func TestFormatFromContentString(t *testing.T) {
{`asdfasdf`, Format("")},
{``, Format("")},
} {
errMsg := fmt.Sprintf("[%d] %s", i, test.data)
errMsg := qt.Commentf("[%d] %s", i, test.data)
result := Default.FormatFromContentString(test.data)
assert.Equal(test.expect, result, errMsg)
c.Assert(result, qt.Equals, test.expect, errMsg)
}
}