Skip to content

Commit 9e57182

Browse files
committed
tests: Convert from testify to quicktest
1 parent 6027ee1 commit 9e57182

File tree

195 files changed

+3933
-3707
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+3933
-3707
lines changed

bufferpool/bufpool_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
package bufferpool
1515

1616
import (
17-
"github.com/stretchr/testify/assert"
1817
"testing"
18+
19+
qt "github.com/frankban/quicktest"
1920
)
2021

2122
func TestBufferPool(t *testing.T) {
23+
c := qt.New(t)
24+
2225
buff := GetBuffer()
2326
buff.WriteString("do be do be do")
24-
assert.Equal(t, "do be do be do", buff.String())
27+
c.Assert(buff.String(), qt.Equals, "do be do be do")
2528
PutBuffer(buff)
26-
assert.Equal(t, 0, buff.Len())
29+
30+
c.Assert(buff.Len(), qt.Equals, 0)
2731
}

cache/filecache/filecache_config_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import (
2424

2525
"github.com/gohugoio/hugo/config"
2626

27+
qt "github.com/frankban/quicktest"
2728
"github.com/spf13/viper"
28-
"github.com/stretchr/testify/require"
2929
)
3030

3131
func TestDecodeConfig(t *testing.T) {
3232
t.Parallel()
3333

34-
assert := require.New(t)
34+
c := qt.New(t)
3535

3636
configStr := `
3737
resourceDir = "myresources"
@@ -55,27 +55,27 @@ dir = "/path/to/c3"
5555
`
5656

5757
cfg, err := config.FromConfigString(configStr, "toml")
58-
assert.NoError(err)
58+
c.Assert(err, qt.IsNil)
5959
fs := afero.NewMemMapFs()
6060
decoded, err := DecodeConfig(fs, cfg)
61-
assert.NoError(err)
61+
c.Assert(err, qt.IsNil)
6262

63-
assert.Equal(5, len(decoded))
63+
c.Assert(len(decoded), qt.Equals, 5)
6464

6565
c2 := decoded["getcsv"]
66-
assert.Equal("11h0m0s", c2.MaxAge.String())
67-
assert.Equal(filepath.FromSlash("/path/to/c2/filecache/getcsv"), c2.Dir)
66+
c.Assert(c2.MaxAge.String(), qt.Equals, "11h0m0s")
67+
c.Assert(c2.Dir, qt.Equals, filepath.FromSlash("/path/to/c2/filecache/getcsv"))
6868

6969
c3 := decoded["images"]
70-
assert.Equal(time.Duration(-1), c3.MaxAge)
71-
assert.Equal(filepath.FromSlash("/path/to/c3/filecache/images"), c3.Dir)
70+
c.Assert(c3.MaxAge, qt.Equals, time.Duration(-1))
71+
c.Assert(c3.Dir, qt.Equals, filepath.FromSlash("/path/to/c3/filecache/images"))
7272

7373
}
7474

7575
func TestDecodeConfigIgnoreCache(t *testing.T) {
7676
t.Parallel()
7777

78-
assert := require.New(t)
78+
c := qt.New(t)
7979

8080
configStr := `
8181
resourceDir = "myresources"
@@ -100,21 +100,21 @@ dir = "/path/to/c3"
100100
`
101101

102102
cfg, err := config.FromConfigString(configStr, "toml")
103-
assert.NoError(err)
103+
c.Assert(err, qt.IsNil)
104104
fs := afero.NewMemMapFs()
105105
decoded, err := DecodeConfig(fs, cfg)
106-
assert.NoError(err)
106+
c.Assert(err, qt.IsNil)
107107

108-
assert.Equal(5, len(decoded))
108+
c.Assert(len(decoded), qt.Equals, 5)
109109

110110
for _, v := range decoded {
111-
assert.Equal(time.Duration(0), v.MaxAge)
111+
c.Assert(v.MaxAge, qt.Equals, time.Duration(0))
112112
}
113113

114114
}
115115

116116
func TestDecodeConfigDefault(t *testing.T) {
117-
assert := require.New(t)
117+
c := qt.New(t)
118118
cfg := newTestConfig()
119119

120120
if runtime.GOOS == "windows" {
@@ -130,28 +130,28 @@ func TestDecodeConfigDefault(t *testing.T) {
130130

131131
decoded, err := DecodeConfig(fs, cfg)
132132

133-
assert.NoError(err)
133+
c.Assert(err, qt.IsNil)
134134

135-
assert.Equal(5, len(decoded))
135+
c.Assert(len(decoded), qt.Equals, 5)
136136

137137
imgConfig := decoded[cacheKeyImages]
138138
jsonConfig := decoded[cacheKeyGetJSON]
139139

140140
if runtime.GOOS == "windows" {
141-
assert.Equal(filepath.FromSlash("_gen/images"), imgConfig.Dir)
141+
c.Assert(imgConfig.Dir, qt.Equals, filepath.FromSlash("_gen/images"))
142142
} else {
143-
assert.Equal("_gen/images", imgConfig.Dir)
144-
assert.Equal("/cache/thecache/hugoproject/filecache/getjson", jsonConfig.Dir)
143+
c.Assert(imgConfig.Dir, qt.Equals, "_gen/images")
144+
c.Assert(jsonConfig.Dir, qt.Equals, "/cache/thecache/hugoproject/filecache/getjson")
145145
}
146146

147-
assert.True(imgConfig.isResourceDir)
148-
assert.False(jsonConfig.isResourceDir)
147+
c.Assert(imgConfig.isResourceDir, qt.Equals, true)
148+
c.Assert(jsonConfig.isResourceDir, qt.Equals, false)
149149
}
150150

151151
func TestDecodeConfigInvalidDir(t *testing.T) {
152152
t.Parallel()
153153

154-
assert := require.New(t)
154+
c := qt.New(t)
155155

156156
configStr := `
157157
resourceDir = "myresources"
@@ -173,11 +173,11 @@ dir = "/"
173173
}
174174

175175
cfg, err := config.FromConfigString(configStr, "toml")
176-
assert.NoError(err)
176+
c.Assert(err, qt.IsNil)
177177
fs := afero.NewMemMapFs()
178178

179179
_, err = DecodeConfig(fs, cfg)
180-
assert.Error(err)
180+
c.Assert(err, qt.Not(qt.IsNil))
181181

182182
}
183183

cache/filecache/filecache_pruner_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import (
2020

2121
"github.com/spf13/afero"
2222

23-
"github.com/stretchr/testify/require"
23+
qt "github.com/frankban/quicktest"
2424
)
2525

2626
func TestPrune(t *testing.T) {
2727
t.Parallel()
2828

29-
assert := require.New(t)
29+
c := qt.New(t)
3030

3131
configStr := `
3232
resourceDir = "myresources"
@@ -53,10 +53,10 @@ dir = ":resourceDir/_gen"
5353
`
5454

5555
for _, name := range []string{cacheKeyGetCSV, cacheKeyGetJSON, cacheKeyAssets, cacheKeyImages} {
56-
msg := fmt.Sprintf("cache: %s", name)
56+
msg := qt.Commentf("cache: %s", name)
5757
p := newPathsSpec(t, afero.NewMemMapFs(), configStr)
5858
caches, err := NewCaches(p)
59-
assert.NoError(err)
59+
c.Assert(err, qt.IsNil)
6060
cache := caches[name]
6161
for i := 0; i < 10; i++ {
6262
id := fmt.Sprintf("i%d", i)
@@ -70,39 +70,39 @@ dir = ":resourceDir/_gen"
7070
}
7171

7272
count, err := caches.Prune()
73-
assert.NoError(err)
74-
assert.Equal(5, count, msg)
73+
c.Assert(err, qt.IsNil)
74+
c.Assert(count, qt.Equals, 5, msg)
7575

7676
for i := 0; i < 10; i++ {
7777
id := fmt.Sprintf("i%d", i)
7878
v := cache.getString(id)
7979
if i < 5 {
80-
assert.Equal("", v, id)
80+
c.Assert(v, qt.Equals, "")
8181
} else {
82-
assert.Equal("abc", v, id)
82+
c.Assert(v, qt.Equals, "abc")
8383
}
8484
}
8585

8686
caches, err = NewCaches(p)
87-
assert.NoError(err)
87+
c.Assert(err, qt.IsNil)
8888
cache = caches[name]
8989
// Touch one and then prune.
9090
cache.GetOrCreateBytes("i5", func() ([]byte, error) {
9191
return []byte("abc"), nil
9292
})
9393

9494
count, err = caches.Prune()
95-
assert.NoError(err)
96-
assert.Equal(4, count)
95+
c.Assert(err, qt.IsNil)
96+
c.Assert(count, qt.Equals, 4)
9797

9898
// Now only the i5 should be left.
9999
for i := 0; i < 10; i++ {
100100
id := fmt.Sprintf("i%d", i)
101101
v := cache.getString(id)
102102
if i != 5 {
103-
assert.Equal("", v, id)
103+
c.Assert(v, qt.Equals, "")
104104
} else {
105-
assert.Equal("abc", v, id)
105+
c.Assert(v, qt.Equals, "abc")
106106
}
107107
}
108108

0 commit comments

Comments
 (0)