build: don't use ioutil

This is deprecated.
This commit is contained in:
Vincent Bernat
2023-11-12 22:54:44 +01:00
parent 9cfa8e0da5
commit 9db516e424
9 changed files with 20 additions and 24 deletions

View File

@@ -6,7 +6,6 @@ package cmd_test
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@@ -84,7 +83,7 @@ module1:
workers: -5
`
configFile := filepath.Join(t.TempDir(), "config.yaml")
ioutil.WriteFile(configFile, []byte(config), 0o644)
os.WriteFile(configFile, []byte(config), 0o644)
c := cmd.ConfigRelatedOptions{
Path: configFile,
@@ -117,7 +116,7 @@ module2:
- name: second
`
configFile := filepath.Join(t.TempDir(), "config.yaml")
ioutil.WriteFile(configFile, []byte(config), 0o644)
os.WriteFile(configFile, []byte(config), 0o644)
c := cmd.ConfigRelatedOptions{
Path: configFile,
@@ -198,7 +197,7 @@ module2:
interval-value: 20m
`
configFile := filepath.Join(t.TempDir(), "config.yaml")
ioutil.WriteFile(configFile, []byte(config), 0o644)
os.WriteFile(configFile, []byte(config), 0o644)
// Environment
clean := func() {
@@ -319,7 +318,7 @@ module1:
workers: 10
`
configFile := filepath.Join(t.TempDir(), "config.yaml")
ioutil.WriteFile(configFile, []byte(config), 0o644)
os.WriteFile(configFile, []byte(config), 0o644)
c := cmd.ConfigRelatedOptions{Path: configFile}
@@ -339,7 +338,7 @@ module1:
workers: 10
`
configFile := filepath.Join(t.TempDir(), "config.yaml")
ioutil.WriteFile(configFile, []byte(config), 0o644)
os.WriteFile(configFile, []byte(config), 0o644)
c := cmd.ConfigRelatedOptions{Path: configFile}
@@ -366,7 +365,7 @@ modules:
topic: flows2
`
configFile := filepath.Join(t.TempDir(), "config.yaml")
ioutil.WriteFile(configFile, []byte(config), 0o644)
os.WriteFile(configFile, []byte(config), 0o644)
c := cmd.ConfigRelatedOptions{
Path: configFile,

View File

@@ -5,7 +5,7 @@ package cmd
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strconv"
@@ -27,7 +27,7 @@ func TestOrchestratorStart(t *testing.T) {
}
func TestOrchestratorConfig(t *testing.T) {
tests, err := ioutil.ReadDir("testdata/configurations")
tests, err := os.ReadDir("testdata/configurations")
if err != nil {
t.Fatalf("ReadDir(%q) error:\n%+v", "testdata/configurations", err)
}
@@ -36,7 +36,7 @@ func TestOrchestratorConfig(t *testing.T) {
continue
}
t.Run(test.Name(), func(t *testing.T) {
expected, err := ioutil.ReadFile(
expected, err := os.ReadFile(
filepath.Join("testdata/configurations", test.Name(), "expected.yaml"))
if err != nil {
t.Fatalf("ReadFile() error:\n%+v", err)

View File

@@ -7,14 +7,13 @@ import (
"bytes"
"encoding/gob"
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
// Save persists the cache to the specified file
func (c *Cache[K, V]) Save(cacheFile string) error {
tmpFile, err := ioutil.TempFile(
tmpFile, err := os.CreateTemp(
filepath.Dir(cacheFile),
fmt.Sprintf("%s-*", filepath.Base(cacheFile)))
if err != nil {

View File

@@ -6,7 +6,7 @@ package httpserver
import (
"bytes"
"crypto"
"io/ioutil"
"io"
"time"
cache "github.com/chenyahui/gin-cache"
@@ -31,7 +31,7 @@ func (c *Component) CacheByRequestBody(expire time.Duration) gin.HandlerFunc {
opts := c.commonCacheOptions()
opts = append(opts, cache.WithCacheStrategyByRequest(func(gc *gin.Context) (bool, cache.Strategy) {
requestBody, err := gc.GetRawData()
gc.Request.Body = ioutil.NopCloser(bytes.NewBuffer(requestBody))
gc.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
if err != nil {
return false, cache.Strategy{}
}

View File

@@ -10,7 +10,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"net/http"
"regexp"
"strings"
@@ -74,7 +73,7 @@ func (c *Component) docsHandlerFunc(gc *gin.Context) {
}
// Markdown rendering to build ToC
content, _ := ioutil.ReadAll(f)
content, _ := io.ReadAll(f)
f.Close()
if matches[3] == requestedDocument {
// That's the one we need to do final rendering on.

View File

@@ -5,7 +5,7 @@ package console
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@@ -40,7 +40,7 @@ func TestServeDocs(t *testing.T) {
t.Errorf("GET /api/v0/console/docs/%s: got status code %d, not 200",
tc.Path, resp.StatusCode)
}
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
if !strings.Contains(string(body), tc.Expect) {
t.Logf("Body:\n%s", string(body))
t.Errorf("GET /api/v0/console/docs/%s: does not contain %q",

View File

@@ -6,8 +6,8 @@ package file
import (
"errors"
"io/ioutil"
"net"
"os"
"time"
"gopkg.in/tomb.v2"
@@ -50,7 +50,7 @@ func (in *Input) Start() (<-chan []*schema.FlowMessage, error) {
in.t.Go(func() error {
for idx := 0; true; idx++ {
path := in.config.Paths[idx%len(in.config.Paths)]
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
in.r.Err(err).Str("path", path).Msg("unable to read path")
return err

View File

@@ -9,8 +9,8 @@ import (
"encoding/csv"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strconv"
"text/template"
"time"
@@ -103,7 +103,7 @@ func (c *Component) registerHTTPHandlers() error {
w.WriteHeader(http.StatusServiceUnavailable)
return
}
file, err := ioutil.ReadFile(v.Source)
file, err := os.ReadFile(v.Source)
if err != nil {
c.r.Err(err).Msg("unable to deliver custom dict csv file")
http.Error(w, fmt.Sprintf("unable to deliver custom dict csv file %s", v.Source), http.StatusNotFound)

View File

@@ -8,7 +8,6 @@ import (
"encoding/csv"
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"path"
@@ -199,7 +198,7 @@ func TestMigration(t *testing.T) {
var lastRun map[string]string
var lastSteps int
files, err := ioutil.ReadDir("testdata/states")
files, err := os.ReadDir("testdata/states")
if err != nil {
t.Fatalf("ReadDir(%q) error:\n%+v", "testdata/states", err)
}