Remove dependency of deprecated `ioutil` package

This commit is contained in:
Deluan 2021-07-20 20:00:58 -04:00
parent 774ad65155
commit 8afa2cd833
23 changed files with 77 additions and 86 deletions

View File

@ -4,7 +4,7 @@ import (
"bytes"
"context"
"errors"
"io/ioutil"
"io"
"net/http"
"os"
"strconv"
@ -70,7 +70,7 @@ var _ = Describe("lastfmAgent", func() {
})
It("returns an error if Last.FM call returns an error", func() {
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError3)), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString(lastfmError3)), StatusCode: 200}
_, err := agent.GetBiography(ctx, "123", "U2", "mbid-1234")
Expect(err).To(HaveOccurred())
Expect(httpClient.RequestCount).To(Equal(1))
@ -78,7 +78,7 @@ var _ = Describe("lastfmAgent", func() {
})
It("returns an error if Last.FM call returns an error 6 and mbid is empty", func() {
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
_, err := agent.GetBiography(ctx, "123", "U2", "")
Expect(err).To(HaveOccurred())
Expect(httpClient.RequestCount).To(Equal(1))
@ -93,7 +93,7 @@ var _ = Describe("lastfmAgent", func() {
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(BeEmpty())
})
It("calls again when last.fm returns an error 6", func() {
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
_, _ = agent.GetBiography(ctx, "123", "U2", "mbid-1234")
Expect(httpClient.RequestCount).To(Equal(2))
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(BeEmpty())
@ -131,7 +131,7 @@ var _ = Describe("lastfmAgent", func() {
})
It("returns an error if Last.FM call returns an error", func() {
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError3)), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString(lastfmError3)), StatusCode: 200}
_, err := agent.GetSimilar(ctx, "123", "U2", "mbid-1234", 2)
Expect(err).To(HaveOccurred())
Expect(httpClient.RequestCount).To(Equal(1))
@ -139,7 +139,7 @@ var _ = Describe("lastfmAgent", func() {
})
It("returns an error if Last.FM call returns an error 6 and mbid is empty", func() {
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
_, err := agent.GetSimilar(ctx, "123", "U2", "", 2)
Expect(err).To(HaveOccurred())
Expect(httpClient.RequestCount).To(Equal(1))
@ -154,7 +154,7 @@ var _ = Describe("lastfmAgent", func() {
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(BeEmpty())
})
It("calls again when last.fm returns an error 6", func() {
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
_, _ = agent.GetSimilar(ctx, "123", "U2", "mbid-1234", 2)
Expect(httpClient.RequestCount).To(Equal(2))
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(BeEmpty())
@ -192,7 +192,7 @@ var _ = Describe("lastfmAgent", func() {
})
It("returns an error if Last.FM call returns an error", func() {
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError3)), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString(lastfmError3)), StatusCode: 200}
_, err := agent.GetTopSongs(ctx, "123", "U2", "mbid-1234", 2)
Expect(err).To(HaveOccurred())
Expect(httpClient.RequestCount).To(Equal(1))
@ -200,7 +200,7 @@ var _ = Describe("lastfmAgent", func() {
})
It("returns an error if Last.FM call returns an error 6 and mbid is empty", func() {
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
_, err := agent.GetTopSongs(ctx, "123", "U2", "", 2)
Expect(err).To(HaveOccurred())
Expect(httpClient.RequestCount).To(Equal(1))
@ -215,7 +215,7 @@ var _ = Describe("lastfmAgent", func() {
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(BeEmpty())
})
It("calls again when last.fm returns an error 6", func() {
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString(lastfmError6)), StatusCode: 200}
_, _ = agent.GetTopSongs(ctx, "123", "U2", "mbid-1234", 2)
Expect(httpClient.RequestCount).To(Equal(2))
Expect(httpClient.SavedRequest.URL.Query().Get("mbid")).To(BeEmpty())
@ -247,7 +247,7 @@ var _ = Describe("lastfmAgent", func() {
Describe("NowPlaying", func() {
It("calls Last.fm with correct params", func() {
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString("{}")), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString("{}")), StatusCode: 200}
err := agent.NowPlaying(ctx, "user-1", track)
@ -274,7 +274,7 @@ var _ = Describe("lastfmAgent", func() {
Describe("Scrobble", func() {
It("calls Last.fm with correct params", func() {
ts := time.Now()
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString("{}")), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString("{}")), StatusCode: 200}
err := agent.Scrobble(ctx, "user-1", scrobbler.Scrobble{MediaFile: *track, TimeStamp: ts})
@ -295,7 +295,7 @@ var _ = Describe("lastfmAgent", func() {
It("skips songs with less than 31 seconds", func() {
track.Duration = 29
httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString("{}")), StatusCode: 200}
httpClient.Res = http.Response{Body: io.NopCloser(bytes.NewBufferString("{}")), StatusCode: 200}
err := agent.Scrobble(ctx, "user-1", scrobbler.Scrobble{MediaFile: *track, TimeStamp: time.Now()})
@ -310,7 +310,7 @@ var _ = Describe("lastfmAgent", func() {
It("returns ErrRetryLater on error 11", func() {
httpClient.Res = http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(`{"error":11,"message":"Service Offline - This service is temporarily offline. Try again later."}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"error":11,"message":"Service Offline - This service is temporarily offline. Try again later."}`)),
StatusCode: 400,
}
@ -320,7 +320,7 @@ var _ = Describe("lastfmAgent", func() {
It("returns ErrRetryLater on error 16", func() {
httpClient.Res = http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(`{"error":16,"message":"There was a temporary error processing your request. Please try again"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"error":16,"message":"There was a temporary error processing your request. Please try again"}`)),
StatusCode: 400,
}
@ -330,7 +330,7 @@ var _ = Describe("lastfmAgent", func() {
It("returns ErrRetryLater on http errors", func() {
httpClient.Res = http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(`internal server error`)),
Body: io.NopCloser(bytes.NewBufferString(`internal server error`)),
StatusCode: 500,
}
@ -340,7 +340,7 @@ var _ = Describe("lastfmAgent", func() {
It("returns ErrUnrecoverable on other errors", func() {
httpClient.Res = http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(`{"error":8,"message":"Operation failed - Something else went wrong"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"error":8,"message":"Operation failed - Something else went wrong"}`)),
StatusCode: 400,
}

View File

@ -6,7 +6,7 @@ import (
"crypto/md5"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
@ -38,7 +38,7 @@ var _ = Describe("Client", func() {
It("fails if Last.FM returns an http status != 200", func() {
httpClient.Res = http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(`Internal Server Error`)),
Body: io.NopCloser(bytes.NewBufferString(`Internal Server Error`)),
StatusCode: 500,
}
@ -48,7 +48,7 @@ var _ = Describe("Client", func() {
It("fails if Last.FM returns an http status != 200", func() {
httpClient.Res = http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(`{"error":3,"message":"Invalid Method - No method with that name in this package"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"error":3,"message":"Invalid Method - No method with that name in this package"}`)),
StatusCode: 400,
}
@ -58,7 +58,7 @@ var _ = Describe("Client", func() {
It("fails if Last.FM returns an error", func() {
httpClient.Res = http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(`{"error":6,"message":"The artist you supplied could not be found"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"error":6,"message":"The artist you supplied could not be found"}`)),
StatusCode: 200,
}
@ -75,7 +75,7 @@ var _ = Describe("Client", func() {
It("fails if returned body is not a valid JSON", func() {
httpClient.Res = http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(`<xml>NOT_VALID_JSON</xml>`)),
Body: io.NopCloser(bytes.NewBufferString(`<xml>NOT_VALID_JSON</xml>`)),
StatusCode: 200,
}
@ -112,7 +112,7 @@ var _ = Describe("Client", func() {
Describe("GetToken", func() {
It("returns a token when the request is successful", func() {
httpClient.Res = http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(`{"token":"TOKEN"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"token":"TOKEN"}`)),
StatusCode: 200,
}
@ -128,7 +128,7 @@ var _ = Describe("Client", func() {
Describe("GetSession", func() {
It("returns a session key when the request is successful", func() {
httpClient.Res = http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(`{"session":{"name":"Navidrome","key":"SESSION_KEY","subscriber":0}}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"session":{"name":"Navidrome","key":"SESSION_KEY","subscriber":0}}`)),
StatusCode: 200,
}

View File

@ -2,7 +2,7 @@ package lastfm
import (
"encoding/json"
"io/ioutil"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -12,7 +12,7 @@ var _ = Describe("LastFM responses", func() {
Describe("Artist", func() {
It("parses the response correctly", func() {
var resp Response
body, _ := ioutil.ReadFile("tests/fixtures/lastfm.artist.getinfo.json")
body, _ := os.ReadFile("tests/fixtures/lastfm.artist.getinfo.json")
err := json.Unmarshal(body, &resp)
Expect(err).To(BeNil())
@ -26,7 +26,7 @@ var _ = Describe("LastFM responses", func() {
Describe("SimilarArtists", func() {
It("parses the response correctly", func() {
var resp Response
body, _ := ioutil.ReadFile("tests/fixtures/lastfm.artist.getsimilar.json")
body, _ := os.ReadFile("tests/fixtures/lastfm.artist.getsimilar.json")
err := json.Unmarshal(body, &resp)
Expect(err).To(BeNil())
@ -39,7 +39,7 @@ var _ = Describe("LastFM responses", func() {
Describe("TopTracks", func() {
It("parses the response correctly", func() {
var resp Response
body, _ := ioutil.ReadFile("tests/fixtures/lastfm.artist.gettoptracks.json")
body, _ := os.ReadFile("tests/fixtures/lastfm.artist.gettoptracks.json")
err := json.Unmarshal(body, &resp)
Expect(err).To(BeNil())

View File

@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
@ -93,7 +93,7 @@ func (c *Client) makeRequest(req *http.Request, response interface{}) error {
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return err
}

View File

@ -3,7 +3,7 @@ package spotify
import (
"bytes"
"context"
"io/ioutil"
"io"
"net/http"
"os"
@ -26,7 +26,7 @@ var _ = Describe("Client", func() {
httpClient.mock("https://api.spotify.com/v1/search", http.Response{Body: f, StatusCode: 200})
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"access_token": "NEW_ACCESS_TOKEN","token_type": "Bearer","expires_in": 3600}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"access_token": "NEW_ACCESS_TOKEN","token_type": "Bearer","expires_in": 3600}`)),
})
artists, err := client.SearchArtists(context.TODO(), "U2", 10)
@ -44,7 +44,7 @@ var _ = Describe("Client", func() {
It("fails if artist was not found", func() {
httpClient.mock("https://api.spotify.com/v1/search", http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`{
Body: io.NopCloser(bytes.NewBufferString(`{
"artists" : {
"href" : "https://api.spotify.com/v1/search?query=dasdasdas%2Cdna&type=artist&offset=0&limit=20",
"items" : [ ], "limit" : 20, "next" : null, "offset" : 0, "previous" : null, "total" : 0
@ -52,7 +52,7 @@ var _ = Describe("Client", func() {
})
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"access_token": "NEW_ACCESS_TOKEN","token_type": "Bearer","expires_in": 3600}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"access_token": "NEW_ACCESS_TOKEN","token_type": "Bearer","expires_in": 3600}`)),
})
_, err := client.SearchArtists(context.TODO(), "U2", 10)
@ -64,7 +64,7 @@ var _ = Describe("Client", func() {
httpClient.mock("https://api.spotify.com/v1/search", http.Response{Body: f, StatusCode: 200})
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"error":"invalid_client","error_description":"Invalid client"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"error":"invalid_client","error_description":"Invalid client"}`)),
})
_, err := client.SearchArtists(context.TODO(), "U2", 10)
@ -76,7 +76,7 @@ var _ = Describe("Client", func() {
It("returns an access_token on successful authorization", func() {
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"access_token": "NEW_ACCESS_TOKEN","token_type": "Bearer","expires_in": 3600}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"access_token": "NEW_ACCESS_TOKEN","token_type": "Bearer","expires_in": 3600}`)),
})
token, err := client.authorize(context.TODO())
@ -89,7 +89,7 @@ var _ = Describe("Client", func() {
It("fails on unsuccessful authorization", func() {
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"error":"invalid_client","error_description":"Invalid client"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"error":"invalid_client","error_description":"Invalid client"}`)),
})
_, err := client.authorize(context.TODO())
@ -99,7 +99,7 @@ var _ = Describe("Client", func() {
It("fails on invalid JSON response", func() {
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`{NOT_VALID}`)),
Body: io.NopCloser(bytes.NewBufferString(`{NOT_VALID}`)),
})
_, err := client.authorize(context.TODO())

View File

@ -2,7 +2,7 @@ package spotify
import (
"encoding/json"
"io/ioutil"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -12,7 +12,7 @@ var _ = Describe("Responses", func() {
Describe("Search type=artist", func() {
It("parses the artist search result correctly ", func() {
var resp SearchResults
body, _ := ioutil.ReadFile("tests/fixtures/spotify.search.artist.json")
body, _ := os.ReadFile("tests/fixtures/spotify.search.artist.json")
err := json.Unmarshal(body, &resp)
Expect(err).To(BeNil())

View File

@ -10,7 +10,6 @@ import (
"image/jpeg"
_ "image/png"
"io"
"io/ioutil"
"os"
"strings"
"sync"
@ -173,7 +172,7 @@ func resizeImage(reader io.Reader, size int) (io.ReadCloser, error) {
buf := new(bytes.Buffer)
err = jpeg.Encode(buf, m, &jpeg.Options{Quality: conf.Server.CoverJpegQuality})
return ioutil.NopCloser(buf), err
return io.NopCloser(buf), err
}
func readFromTag(path string) (io.ReadCloser, error) {
@ -192,7 +191,7 @@ func readFromTag(path string) (io.ReadCloser, error) {
if picture == nil {
return nil, errors.New("file does not contain embedded art")
}
return ioutil.NopCloser(bytes.NewReader(picture.Data)), nil
return io.NopCloser(bytes.NewReader(picture.Data)), nil
}
func readFromFile(path string) (io.ReadCloser, error) {

View File

@ -3,7 +3,7 @@ package core
import (
"context"
"image"
"io/ioutil"
"os"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/log"
@ -33,7 +33,7 @@ var _ = Describe("Artwork", func() {
Context("Cache is configured", func() {
BeforeEach(func() {
conf.Server.DataFolder, _ = ioutil.TempDir("", "file_caches")
conf.Server.DataFolder, _ = os.MkdirTemp("", "file_caches")
conf.Server.ImageCacheSize = "100MB"
cache := GetImageCache()
Eventually(func() bool { return cache.Ready(context.TODO()) }).Should(BeTrue())

View File

@ -3,7 +3,6 @@ package core
import (
"context"
"io"
"io/ioutil"
"time"
"github.com/navidrome/navidrome/conf"
@ -80,7 +79,7 @@ func (w *warmer) execute(workload interface{}) {
return
}
defer r.Close()
_, _ = io.Copy(ioutil.Discard, r)
_, _ = io.Copy(io.Discard, r)
}
type artworkItem struct {

View File

@ -3,7 +3,7 @@ package core
import (
"context"
"io"
"io/ioutil"
"os"
"strings"
"github.com/navidrome/navidrome/conf"
@ -22,7 +22,7 @@ var _ = Describe("MediaStreamer", func() {
ctx := log.NewContext(context.TODO())
BeforeEach(func() {
conf.Server.DataFolder, _ = ioutil.TempDir("", "file_caches")
conf.Server.DataFolder, _ = os.MkdirTemp("", "file_caches")
conf.Server.TranscodingCacheSize = "100MB"
ds = &tests.MockDataStore{MockedTranscoding: &tests.MockTranscodingRepo{}}
ds.MediaFile(ctx).(*tests.MockMediaFileRepo).SetData(model.MediaFiles{
@ -58,7 +58,7 @@ var _ = Describe("MediaStreamer", func() {
It("returns a seekable stream if the file is complete in the cache", func() {
s, err := streamer.NewStream(ctx, "123", "mp3", 32)
Expect(err).To(BeNil())
_, _ = ioutil.ReadAll(s)
_, _ = io.ReadAll(s)
_ = s.Close()
Eventually(func() bool { return ffmpeg.closed }, "3s").Should(BeTrue())

View File

@ -2,7 +2,6 @@ package persistence
import (
"context"
"io/ioutil"
"os"
"path/filepath"
@ -89,7 +88,7 @@ var _ = Describe("AlbumRepository", func() {
})
Describe("getCoverFromPath", func() {
testFolder, _ := ioutil.TempDir("", "album_persistence_tests")
testFolder, _ := os.MkdirTemp("", "album_persistence_tests")
if err := os.MkdirAll(testFolder, 0777); err != nil {
panic(err)
}

View File

@ -2,7 +2,7 @@ package resources
import (
"embed"
"io/ioutil"
"io"
)
//go:embed *
@ -13,5 +13,5 @@ func Asset(path string) ([]byte, error) {
if err != nil {
return nil, err
}
return ioutil.ReadAll(f)
return io.ReadAll(f)
}

View File

@ -5,7 +5,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -26,7 +25,7 @@ func newPlaylistSync(ds model.DataStore) *playlistSync {
func (s *playlistSync) processPlaylists(ctx context.Context, dir string) int64 {
var count int64
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
log.Error(ctx, "Error reading files", "dir", dir, err)
return count

View File

@ -4,8 +4,8 @@ import (
"bytes"
"context"
"encoding/json"
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -112,7 +112,7 @@ func loadTranslation(fsys fs.FS, fileName string) (translation translation, err
if err != nil {
return
}
data, err := ioutil.ReadAll(file)
data, err := io.ReadAll(file)
if err != nil {
return
}

View File

@ -2,7 +2,7 @@ package nativeapi
import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
@ -26,7 +26,7 @@ var _ = Describe("Translations", func() {
name := filepath.Base(f.Name())
filePath := filepath.Join(consts.I18nFolder, name)
file, _ := fs.Open(filePath)
data, _ := ioutil.ReadAll(file)
data, _ := io.ReadAll(file)
var out map[string]interface{}
Expect(filepath.Ext(filePath)).To(Equal(".json"), filePath)

View File

@ -3,8 +3,8 @@ package server
import (
"encoding/json"
"html/template"
"io"
"io/fs"
"io/ioutil"
"net/http"
"strings"
@ -82,7 +82,7 @@ func getIndexTemplate(r *http.Request, fs fs.FS) (*template.Template, error) {
log.Error(r, "Could not find `index.html` template", err)
return nil, err
}
indexStr, err := ioutil.ReadAll(indexHtml)
indexStr, err := io.ReadAll(indexHtml)
if err != nil {
log.Error(r, "Could not read from `index.html`", err)
return nil, err

View File

@ -5,7 +5,6 @@ import (
"context"
"errors"
"io"
"io/ioutil"
"net/http/httptest"
"github.com/navidrome/navidrome/model"
@ -76,5 +75,5 @@ func (c *fakeArtwork) Get(ctx context.Context, id string, size int) (io.ReadClos
}
c.recvId = id
c.recvSize = size
return ioutil.NopCloser(bytes.NewReader([]byte(c.data))), nil
return io.NopCloser(bytes.NewReader([]byte(c.data))), nil
}

View File

@ -3,7 +3,6 @@ package subsonic
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"
"strings"
@ -67,7 +66,7 @@ func (c *StreamController) Stream(w http.ResponseWriter, r *http.Request) (*resp
}
if r.Method == "HEAD" {
go func() { _, _ = io.Copy(ioutil.Discard, stream) }()
go func() { _, _ = io.Copy(io.Discard, stream) }()
} else {
if c, err := io.Copy(w, stream); err != nil {
log.Error(ctx, "Error sending transcoded file", "id", id, err)

View File

@ -3,7 +3,6 @@ package cache
import (
"context"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -22,7 +21,7 @@ func callNewFileCache(name, cacheSize, cacheFolder string, maxItems int, getRead
var _ = Describe("File Caches", func() {
BeforeEach(func() {
conf.Server.DataFolder, _ = ioutil.TempDir("", "file_caches")
conf.Server.DataFolder, _ = os.MkdirTemp("", "file_caches")
})
AfterEach(func() {
os.RemoveAll(conf.Server.DataFolder)
@ -61,13 +60,13 @@ var _ = Describe("File Caches", func() {
Expect(err).To(BeNil())
Expect(s.Cached).To(BeFalse())
Expect(s.Closer).To(BeNil())
Expect(ioutil.ReadAll(s)).To(Equal([]byte("test")))
Expect(io.ReadAll(s)).To(Equal([]byte("test")))
// Second call is a HIT
called = false
s, err = fc.Get(context.TODO(), &testArg{"test"})
Expect(err).To(BeNil())
Expect(ioutil.ReadAll(s)).To(Equal([]byte("test")))
Expect(io.ReadAll(s)).To(Equal([]byte("test")))
Expect(s.Cached).To(BeTrue())
Expect(s.Closer).ToNot(BeNil())
Expect(called).To(BeFalse())
@ -83,13 +82,13 @@ var _ = Describe("File Caches", func() {
s, err := fc.Get(context.TODO(), &testArg{"test"})
Expect(err).To(BeNil())
Expect(s.Cached).To(BeFalse())
Expect(ioutil.ReadAll(s)).To(Equal([]byte("test")))
Expect(io.ReadAll(s)).To(Equal([]byte("test")))
// Second call is also a MISS
called = false
s, err = fc.Get(context.TODO(), &testArg{"test"})
Expect(err).To(BeNil())
Expect(ioutil.ReadAll(s)).To(Equal([]byte("test")))
Expect(io.ReadAll(s)).To(Equal([]byte("test")))
Expect(s.Cached).To(BeFalse())
Expect(called).To(BeTrue())
})

View File

@ -1,7 +1,6 @@
package cache
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -16,7 +15,7 @@ var _ = Describe("Spread FS", func() {
BeforeEach(func() {
var err error
rootDir, _ = ioutil.TempDir("", "spread_fs")
rootDir, _ = os.MkdirTemp("", "spread_fs")
fs, err = NewSpreadFS(rootDir, 0755)
Expect(err).To(BeNil())
})
@ -54,7 +53,7 @@ var _ = Describe("Spread FS", func() {
var actual []string
err := fs.Reload(func(key string, name string) {
Expect(key).To(Equal(name))
data, err := ioutil.ReadFile(name)
data, err := os.ReadFile(name)
Expect(err).To(BeNil())
actual = append(actual, string(data))
})

View File

@ -6,7 +6,6 @@ import (
"encoding/base64"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"strings"
"time"
@ -71,7 +70,7 @@ func (c *CachedHTTPClient) serializeReq(req *http.Request) string {
URL: req.URL.String(),
}
if req.Body != nil {
bodyData, _ := ioutil.ReadAll(req.Body)
bodyData, _ := io.ReadAll(req.Body)
bodyStr := base64.StdEncoding.EncodeToString(bodyData)
data.Body = &bodyStr
}

View File

@ -2,7 +2,7 @@ package utils
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"time"
@ -36,7 +36,7 @@ var _ = Describe("CachedHttpClient", func() {
r, _ := http.NewRequest("GET", ts.URL+"?name=doe", nil)
resp, err := chc.Do(r)
Expect(err).To(BeNil())
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).To(BeNil())
Expect(string(body)).To(Equal("Hello, [doe]"))
Expect(requestsReceived).To(Equal(1))
@ -45,7 +45,7 @@ var _ = Describe("CachedHttpClient", func() {
r, _ = http.NewRequest("GET", ts.URL+"?name=doe", nil)
resp, err = chc.Do(r)
Expect(err).To(BeNil())
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
Expect(err).To(BeNil())
Expect(string(body)).To(Equal("Hello, [doe]"))
Expect(requestsReceived).To(Equal(1))
@ -54,7 +54,7 @@ var _ = Describe("CachedHttpClient", func() {
r, _ = http.NewRequest("GET", ts.URL, nil)
resp, err = chc.Do(r)
Expect(err).To(BeNil())
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
Expect(err).To(BeNil())
Expect(string(body)).To(Equal("Hello, []"))
Expect(requestsReceived).To(Equal(2))
@ -64,7 +64,7 @@ var _ = Describe("CachedHttpClient", func() {
r.Header.Add("head", "this is a header")
resp, err = chc.Do(r)
Expect(err).To(BeNil())
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
Expect(err).To(BeNil())
Expect(string(body)).To(Equal("Hello, []"))
Expect(header).To(Equal("this is a header"))

View File

@ -1,8 +1,8 @@
package utils_test
import (
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
@ -16,8 +16,8 @@ var _ = Describe("MergeFS", func() {
var baseDir, overlayDir, mergedDir fs.FS
BeforeEach(func() {
baseName, _ = ioutil.TempDir("", "merge_fs_base_test")
overlayName, _ = ioutil.TempDir("", "merge_fs_overlay_test")
baseName, _ = os.MkdirTemp("", "merge_fs_base_test")
overlayName, _ = os.MkdirTemp("", "merge_fs_overlay_test")
baseDir = os.DirFS(baseName)
overlayDir = os.DirFS(overlayName)
mergedDir = utils.MergeFS{Base: baseDir, Overlay: overlayDir}
@ -41,7 +41,7 @@ var _ = Describe("MergeFS", func() {
file, err := mergedDir.Open("b.json")
Expect(err).To(BeNil())
content, err := ioutil.ReadAll(file)
content, err := io.ReadAll(file)
Expect(err).To(BeNil())
Expect(string(content)).To(Equal("overridden"))
})