aboutsummaryrefslogtreecommitdiffhomepage
path: root/cache
diff options
context:
space:
mode:
authorOleksandr Redko <[email protected]>2023-02-19 00:43:26 +0200
committerBjørn Erik Pedersen <[email protected]>2023-03-01 16:28:43 +0100
commitd453c12742e992d672fcf3e61b7a5ed35391c4b0 (patch)
tree1299a1f5a44bda1cf6449a8257f393350b2cc012 /cache
parent97b010f521e592b5fc29daace225476b64543643 (diff)
downloadhugo-d453c12742e992d672fcf3e61b7a5ed35391c4b0.tar.gz
hugo-d453c12742e992d672fcf3e61b7a5ed35391c4b0.zip
Replace deprecated ioutil with io and os
https://pkg.go.dev/io/ioutil is deprecated since Go 1.16.
Diffstat (limited to 'cache')
-rw-r--r--cache/filecache/filecache.go7
-rw-r--r--cache/filecache/filecache_test.go23
2 files changed, 11 insertions, 19 deletions
diff --git a/cache/filecache/filecache.go b/cache/filecache/filecache.go
index 63d939ef6..8723c4bdc 100644
--- a/cache/filecache/filecache.go
+++ b/cache/filecache/filecache.go
@@ -17,7 +17,6 @@ import (
"bytes"
"errors"
"io"
- "io/ioutil"
"os"
"path/filepath"
"strings"
@@ -207,7 +206,7 @@ func (c *Cache) GetOrCreateBytes(id string, create func() ([]byte, error)) (Item
if r := c.getOrRemove(id); r != nil {
defer r.Close()
- b, err := ioutil.ReadAll(r)
+ b, err := io.ReadAll(r)
return info, b, err
}
@@ -242,7 +241,7 @@ func (c *Cache) GetBytes(id string) (ItemInfo, []byte, error) {
if r := c.getOrRemove(id); r != nil {
defer r.Close()
- b, err := ioutil.ReadAll(r)
+ b, err := io.ReadAll(r)
return info, b, err
}
@@ -314,7 +313,7 @@ func (c *Cache) getString(id string) string {
}
defer f.Close()
- b, _ := ioutil.ReadAll(f)
+ b, _ := io.ReadAll(f)
return string(b)
}
diff --git a/cache/filecache/filecache_test.go b/cache/filecache/filecache_test.go
index 47b5a7fcf..6b96a8601 100644
--- a/cache/filecache/filecache_test.go
+++ b/cache/filecache/filecache_test.go
@@ -17,8 +17,6 @@ import (
"errors"
"fmt"
"io"
- "io/ioutil"
- "os"
"path/filepath"
"strings"
"sync"
@@ -44,13 +42,8 @@ func TestFileCache(t *testing.T) {
t.Parallel()
c := qt.New(t)
- tempWorkingDir, err := ioutil.TempDir("", "hugo_filecache_test_work")
- c.Assert(err, qt.IsNil)
- defer os.Remove(tempWorkingDir)
-
- tempCacheDir, err := ioutil.TempDir("", "hugo_filecache_test_cache")
- c.Assert(err, qt.IsNil)
- defer os.Remove(tempCacheDir)
+ tempWorkingDir := t.TempDir()
+ tempCacheDir := t.TempDir()
osfs := afero.NewOsFs()
@@ -123,7 +116,7 @@ dir = ":cacheDir/c"
io.Closer
}{
strings.NewReader(s),
- ioutil.NopCloser(nil),
+ io.NopCloser(nil),
}, nil
}
}
@@ -138,7 +131,7 @@ dir = ":cacheDir/c"
c.Assert(err, qt.IsNil)
c.Assert(r, qt.Not(qt.IsNil))
c.Assert(info.Name, qt.Equals, "a")
- b, _ := ioutil.ReadAll(r)
+ b, _ := io.ReadAll(r)
r.Close()
c.Assert(string(b), qt.Equals, "abc")
@@ -154,7 +147,7 @@ dir = ":cacheDir/c"
_, r, err = ca.GetOrCreate("a", rf("bcd"))
c.Assert(err, qt.IsNil)
- b, _ = ioutil.ReadAll(r)
+ b, _ = io.ReadAll(r)
r.Close()
c.Assert(string(b), qt.Equals, "abc")
}
@@ -173,7 +166,7 @@ dir = ":cacheDir/c"
c.Assert(err, qt.IsNil)
c.Assert(r, qt.Not(qt.IsNil))
c.Assert(info.Name, qt.Equals, "mykey")
- b, _ := ioutil.ReadAll(r)
+ b, _ := io.ReadAll(r)
r.Close()
c.Assert(string(b), qt.Equals, "Hugo is great!")
@@ -233,7 +226,7 @@ dir = "/cache/c"
return hugio.ToReadCloser(strings.NewReader(data)), nil
})
c.Assert(err, qt.IsNil)
- b, _ := ioutil.ReadAll(r)
+ b, _ := io.ReadAll(r)
r.Close()
c.Assert(string(b), qt.Equals, data)
// Trigger some expiration.
@@ -260,7 +253,7 @@ func TestFileCacheReadOrCreateErrorInRead(t *testing.T) {
return errors.New("fail")
}
- b, _ := ioutil.ReadAll(r)
+ b, _ := io.ReadAll(r)
result = string(b)
return nil