Update ioutil library references to os and io respectively for command (#16329)
No user facing changes so I assume no change log is required
This commit is contained in:
parent
de766a4239
commit
d9e585b965
|
@ -2,7 +2,7 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -88,10 +88,10 @@ func (c *ACLBootstrapCommand) Run(args []string) int {
|
|||
case "":
|
||||
terminalToken = []byte{}
|
||||
case "-":
|
||||
terminalToken, err = ioutil.ReadAll(os.Stdin)
|
||||
terminalToken, err = io.ReadAll(os.Stdin)
|
||||
default:
|
||||
file = args[0]
|
||||
terminalToken, err = ioutil.ReadFile(file)
|
||||
terminalToken, err = os.ReadFile(file)
|
||||
}
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error reading provided token: %v", err))
|
||||
|
|
|
@ -2,7 +2,7 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -98,13 +98,13 @@ func (c *ACLPolicyApplyCommand) Run(args []string) int {
|
|||
var rawPolicy []byte
|
||||
var err error
|
||||
if file == "-" {
|
||||
rawPolicy, err = ioutil.ReadAll(os.Stdin)
|
||||
rawPolicy, err = io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read stdin: %v", err))
|
||||
return 1
|
||||
}
|
||||
} else {
|
||||
rawPolicy, err = ioutil.ReadFile(file)
|
||||
rawPolicy, err = os.ReadFile(file)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read file: %v", err))
|
||||
return 1
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
golog "log"
|
||||
"net"
|
||||
"os"
|
||||
|
@ -945,7 +944,7 @@ func (a *Agent) setupNodeID(config *nomad.Config) error {
|
|||
// validate it. Saved state overwrites any configured node id
|
||||
fileID := filepath.Join(config.DataDir, "node-id")
|
||||
if _, err := os.Stat(fileID); err == nil {
|
||||
rawID, err := ioutil.ReadFile(fileID)
|
||||
rawID, err := os.ReadFile(fileID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -970,7 +969,7 @@ func (a *Agent) setupNodeID(config *nomad.Config) error {
|
|||
if err := escapingfs.EnsurePath(fileID, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ioutil.WriteFile(fileID, []byte(config.NodeID), 0600); err != nil {
|
||||
if err := os.WriteFile(fileID, []byte(config.NodeID), 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -982,7 +981,7 @@ func (a *Agent) setupNodeID(config *nomad.Config) error {
|
|||
if err := escapingfs.EnsurePath(fileID, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ioutil.WriteFile(fileID, []byte(id), 0600); err != nil {
|
||||
if err := os.WriteFile(fileID, []byte(id), 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -379,7 +379,7 @@ func TestHTTP_AgentMonitor(t *testing.T) {
|
|||
s.Server.logger.Warn("log that should be sent")
|
||||
tried++
|
||||
}
|
||||
output, err := ioutil.ReadAll(resp.Body)
|
||||
output, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ func TestHTTP_AgentMonitor(t *testing.T) {
|
|||
s.Agent.logger.Warn("log that should be sent")
|
||||
tried++
|
||||
}
|
||||
output, err := ioutil.ReadAll(resp.Body)
|
||||
output, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package agent
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -1400,7 +1399,7 @@ func TestServer_ShouldReload_ReturnTrueForFileChanges(t *testing.T) {
|
|||
dir := t.TempDir()
|
||||
|
||||
tmpfn := filepath.Join(dir, "testcert")
|
||||
err := ioutil.WriteFile(tmpfn, content, 0666)
|
||||
err := os.WriteFile(tmpfn, content, 0666)
|
||||
require.Nil(err)
|
||||
|
||||
const (
|
||||
|
@ -1452,7 +1451,7 @@ func TestServer_ShouldReload_ReturnTrueForFileChanges(t *testing.T) {
|
|||
`
|
||||
|
||||
os.Remove(tmpfn)
|
||||
err = ioutil.WriteFile(tmpfn, []byte(newCertificate), 0666)
|
||||
err = os.WriteFile(tmpfn, []byte(newCertificate), 0666)
|
||||
require.Nil(err)
|
||||
|
||||
newAgentConfig := &Config{
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"archive/tar"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
@ -766,7 +765,7 @@ func TestHTTP_AllocSnapshot_Atomic(t *testing.T) {
|
|||
os.RemoveAll(allocDir.TaskDirs["web"].LocalDir)
|
||||
|
||||
// require Snapshot fails
|
||||
if err := allocDir.Snapshot(ioutil.Discard); err != nil {
|
||||
if err := allocDir.Snapshot(io.Discard); err != nil {
|
||||
t.Logf("[DEBUG] agent.test: snapshot returned error: %v", err)
|
||||
} else {
|
||||
t.Errorf("expected Snapshot() to fail but it did not")
|
||||
|
|
|
@ -41,7 +41,6 @@ import (
|
|||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -855,7 +854,7 @@ func RestoreAsset(dir, name string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
err = os.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -109,7 +109,7 @@ func TestCommand_MetaConfigValidation(t *testing.T) {
|
|||
}
|
||||
for _, tc := range tcases {
|
||||
configFile := filepath.Join(tmpDir, "conf1.hcl")
|
||||
err := ioutil.WriteFile(configFile, []byte(`client{
|
||||
err := os.WriteFile(configFile, []byte(`client{
|
||||
enabled = true
|
||||
meta = {
|
||||
"valid" = "yes"
|
||||
|
@ -163,7 +163,7 @@ func TestCommand_InvalidCharInDatacenter(t *testing.T) {
|
|||
}
|
||||
for _, tc := range tcases {
|
||||
configFile := filepath.Join(tmpDir, "conf1.hcl")
|
||||
err := ioutil.WriteFile(configFile, []byte(`
|
||||
err := os.WriteFile(configFile, []byte(`
|
||||
datacenter = "`+tc+`"
|
||||
client{
|
||||
enabled = true
|
||||
|
@ -210,7 +210,7 @@ func TestCommand_NullCharInRegion(t *testing.T) {
|
|||
}
|
||||
for _, tc := range tcases {
|
||||
configFile := filepath.Join(tmpDir, "conf1.hcl")
|
||||
err := ioutil.WriteFile(configFile, []byte(`
|
||||
err := os.WriteFile(configFile, []byte(`
|
||||
region = "`+tc+`"
|
||||
client{
|
||||
enabled = true
|
||||
|
|
|
@ -2,7 +2,6 @@ package agent
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -469,7 +468,7 @@ func TestConfig_ParseConfigFile(t *testing.T) {
|
|||
t.Fatalf("expected error, got nothing")
|
||||
}
|
||||
|
||||
fh, err := ioutil.TempFile("", "nomad")
|
||||
fh, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -523,19 +522,19 @@ func TestConfig_LoadConfigDir(t *testing.T) {
|
|||
}
|
||||
|
||||
file1 := filepath.Join(dir, "conf1.hcl")
|
||||
err = ioutil.WriteFile(file1, []byte(`{"region":"west"}`), 0600)
|
||||
err = os.WriteFile(file1, []byte(`{"region":"west"}`), 0600)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
file2 := filepath.Join(dir, "conf2.hcl")
|
||||
err = ioutil.WriteFile(file2, []byte(`{"datacenter":"sfo"}`), 0600)
|
||||
err = os.WriteFile(file2, []byte(`{"datacenter":"sfo"}`), 0600)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
file3 := filepath.Join(dir, "conf3.hcl")
|
||||
err = ioutil.WriteFile(file3, []byte(`nope;!!!`), 0600)
|
||||
err = os.WriteFile(file3, []byte(`nope;!!!`), 0600)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -567,7 +566,7 @@ func TestConfig_LoadConfig(t *testing.T) {
|
|||
t.Fatalf("expected error, got nothing")
|
||||
}
|
||||
|
||||
fh, err := ioutil.TempFile("", "nomad")
|
||||
fh, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -595,7 +594,7 @@ func TestConfig_LoadConfig(t *testing.T) {
|
|||
dir := t.TempDir()
|
||||
|
||||
file1 := filepath.Join(dir, "config1.hcl")
|
||||
err = ioutil.WriteFile(file1, []byte(`{"datacenter":"sfo"}`), 0600)
|
||||
err = os.WriteFile(file1, []byte(`{"datacenter":"sfo"}`), 0600)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -1351,7 +1350,7 @@ func TestTelemetry_Parse(t *testing.T) {
|
|||
dir := t.TempDir()
|
||||
|
||||
file1 := filepath.Join(dir, "config1.hcl")
|
||||
err := ioutil.WriteFile(file1, []byte(`telemetry{
|
||||
err := os.WriteFile(file1, []byte(`telemetry{
|
||||
prefix_filter = ["+nomad.raft"]
|
||||
filter_default = false
|
||||
disable_dispatched_job_summary_metrics = true
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package consul
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -20,11 +20,11 @@ func TestConsul_Connect(t *testing.T) {
|
|||
|
||||
// Create an embedded Consul server
|
||||
testconsul, err := testutil.NewTestServerConfigT(t, func(c *testutil.TestServerConfig) {
|
||||
c.Peering = nil // fix for older versions of Consul (<1.13.0) that don't support peering
|
||||
c.Peering = nil // fix for older versions of Consul (<1.13.0) that don't support peering
|
||||
// If -v wasn't specified squelch consul logging
|
||||
if !testing.Verbose() {
|
||||
c.Stdout = ioutil.Discard
|
||||
c.Stderr = ioutil.Discard
|
||||
c.Stdout = io.Discard
|
||||
c.Stderr = io.Discard
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -2,7 +2,7 @@ package consul_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -49,8 +49,8 @@ func TestConsul_Integration(t *testing.T) {
|
|||
c.Peering = nil // fix for older versions of Consul (<1.13.0) that don't support peering
|
||||
// If -v wasn't specified squelch consul logging
|
||||
if !testing.Verbose() {
|
||||
c.Stdout = ioutil.Discard
|
||||
c.Stderr = ioutil.Discard
|
||||
c.Stdout = io.Discard
|
||||
c.Stderr = io.Discard
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -3,7 +3,7 @@ package agent
|
|||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
|
@ -322,7 +322,7 @@ func TestHTTP_FS_ReadAt(t *testing.T) {
|
|||
_, err = s.Server.FileReadAtRequest(respW, req)
|
||||
require.Nil(err)
|
||||
|
||||
output, err := ioutil.ReadAll(respW.Result().Body)
|
||||
output, err := io.ReadAll(respW.Result().Body)
|
||||
require.Nil(err)
|
||||
require.EqualValues(expectation, output)
|
||||
})
|
||||
|
@ -341,7 +341,7 @@ func TestHTTP_FS_ReadAt_XSS(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
buf, err := ioutil.ReadAll(resp.Body)
|
||||
buf, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, xssLoggerMockDriverStdout, string(buf))
|
||||
|
||||
|
@ -368,7 +368,7 @@ func TestHTTP_FS_Cat(t *testing.T) {
|
|||
_, err = s.Server.FileCatRequest(respW, req)
|
||||
require.Nil(err)
|
||||
|
||||
output, err := ioutil.ReadAll(respW.Result().Body)
|
||||
output, err := io.ReadAll(respW.Result().Body)
|
||||
require.Nil(err)
|
||||
require.EqualValues(defaultLoggerMockDriverStdout, output)
|
||||
})
|
||||
|
@ -386,7 +386,7 @@ func TestHTTP_FS_Cat_XSS(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
buf, err := ioutil.ReadAll(resp.Body)
|
||||
buf, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, xssLoggerMockDriverStdout, string(buf))
|
||||
|
||||
|
@ -423,7 +423,7 @@ func TestHTTP_FS_Stream_NoFollow(t *testing.T) {
|
|||
|
||||
out := ""
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
output, err := ioutil.ReadAll(respW)
|
||||
output, err := io.ReadAll(respW)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ func TestHTTP_FS_Stream_NoFollow_XSS(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
buf, err := ioutil.ReadAll(resp.Body)
|
||||
buf, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
expected := `{"Data":"PHNjcmlwdD5hbGVydChkb2N1bWVudC5kb21haW4pOzwvc2NyaXB0Pg==","File":"alloc/logs/web.stdout.0","Offset":40}`
|
||||
require.Equal(t, expected, string(buf))
|
||||
|
@ -487,7 +487,7 @@ func TestHTTP_FS_Stream_Follow(t *testing.T) {
|
|||
|
||||
out := ""
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
output, err := ioutil.ReadAll(respW.Body)
|
||||
output, err := io.ReadAll(respW.Body)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -528,7 +528,7 @@ func TestHTTP_FS_Logs(t *testing.T) {
|
|||
|
||||
out := ""
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
output, err := ioutil.ReadAll(respW)
|
||||
output, err := io.ReadAll(respW)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -557,7 +557,7 @@ func TestHTTP_FS_Logs_XSS(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
buf, err := ioutil.ReadAll(resp.Body)
|
||||
buf, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, xssLoggerMockDriverStdout, string(buf))
|
||||
|
||||
|
@ -588,7 +588,7 @@ func TestHTTP_FS_Logs_Follow(t *testing.T) {
|
|||
|
||||
out := ""
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
output, err := ioutil.ReadAll(respW)
|
||||
output, err := io.ReadAll(respW)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package host
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
@ -119,7 +119,7 @@ func slurp(path string) string {
|
|||
return err.Error()
|
||||
}
|
||||
|
||||
bs, err := ioutil.ReadAll(fh)
|
||||
bs, err := io.ReadAll(fh)
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -271,7 +270,7 @@ func TestWrapNonJSON(t *testing.T) {
|
|||
req, _ := http.NewRequest("GET", "/v1/kv/key", nil)
|
||||
s.Server.wrapNonJSON(handler)(resp, req)
|
||||
|
||||
respBody, _ := ioutil.ReadAll(resp.Body)
|
||||
respBody, _ := io.ReadAll(resp.Body)
|
||||
require.Equal(t, respBody, []byte("test response"))
|
||||
|
||||
}
|
||||
|
@ -294,7 +293,7 @@ func TestWrapNonJSON_Error(t *testing.T) {
|
|||
resp := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/v1/kv/key", nil)
|
||||
s.Server.wrapNonJSON(handlerRPCErr)(resp, req)
|
||||
respBody, _ := ioutil.ReadAll(resp.Body)
|
||||
respBody, _ := io.ReadAll(resp.Body)
|
||||
require.Equal(t, []byte("not found"), respBody)
|
||||
require.Equal(t, 404, resp.Code)
|
||||
}
|
||||
|
@ -304,7 +303,7 @@ func TestWrapNonJSON_Error(t *testing.T) {
|
|||
resp := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/v1/kv/key", nil)
|
||||
s.Server.wrapNonJSON(handlerCodedErr)(resp, req)
|
||||
respBody, _ := ioutil.ReadAll(resp.Body)
|
||||
respBody, _ := io.ReadAll(resp.Body)
|
||||
require.Equal(t, []byte("unprocessable"), respBody)
|
||||
require.Equal(t, 422, resp.Code)
|
||||
}
|
||||
|
@ -354,7 +353,7 @@ func testPrettyPrint(pretty string, prettyFmt bool, t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("failed to encode: %v", err)
|
||||
}
|
||||
actual, err := ioutil.ReadAll(resp.Body)
|
||||
actual, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -798,7 +797,7 @@ func TestHTTP_VerifyHTTPSClient(t *testing.T) {
|
|||
|
||||
// FAIL: Requests that specify a valid hostname and CA cert but lack a
|
||||
// client certificate should fail
|
||||
cacertBytes, err := ioutil.ReadFile(cafile)
|
||||
cacertBytes, err := os.ReadFile(cafile)
|
||||
if err != nil {
|
||||
t.Fatalf("error reading cacert: %v", err)
|
||||
}
|
||||
|
@ -908,7 +907,7 @@ func TestHTTP_VerifyHTTPSClient_AfterConfigReload(t *testing.T) {
|
|||
// HTTPS request should succeed
|
||||
httpsReqURL := fmt.Sprintf("https://%s/v1/agent/self", s.Agent.config.AdvertiseAddrs.HTTP)
|
||||
|
||||
cacertBytes, err := ioutil.ReadFile(cafile)
|
||||
cacertBytes, err := os.ReadFile(cafile)
|
||||
assert.Nil(err)
|
||||
tlsConf.RootCAs.AppendCertsFromPEM(cacertBytes)
|
||||
|
||||
|
@ -939,7 +938,7 @@ func TestHTTP_VerifyHTTPSClient_AfterConfigReload(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
cacertBytes, err = ioutil.ReadFile(cafile)
|
||||
cacertBytes, err = os.ReadFile(cafile)
|
||||
assert.Nil(err)
|
||||
tlsConf.RootCAs.AppendCertsFromPEM(cacertBytes)
|
||||
|
||||
|
@ -1418,7 +1417,7 @@ func Test_decodeBody(t *testing.T) {
|
|||
name: "empty input request body",
|
||||
},
|
||||
{
|
||||
inputReq: &http.Request{Body: ioutil.NopCloser(strings.NewReader(`{"foo":"bar"}`))},
|
||||
inputReq: &http.Request{Body: io.NopCloser(strings.NewReader(`{"foo":"bar"}`))},
|
||||
inputOut: &struct {
|
||||
Foo string `json:"foo"`
|
||||
}{},
|
||||
|
@ -1496,5 +1495,5 @@ func encodeReq(obj interface{}) io.ReadCloser {
|
|||
buf := bytes.NewBuffer(nil)
|
||||
enc := json.NewEncoder(buf)
|
||||
enc.Encode(obj)
|
||||
return ioutil.NopCloser(buf)
|
||||
return io.NopCloser(buf)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
@ -81,7 +80,7 @@ func loadKeyringFile(c *serf.Config) error {
|
|||
}
|
||||
|
||||
// Read in the keyring file data
|
||||
keyringData, err := ioutil.ReadFile(c.KeyringFile)
|
||||
keyringData, err := os.ReadFile(c.KeyringFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package agent
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
@ -63,7 +63,7 @@ func TestAgent_InitKeyring(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
content, err := ioutil.ReadFile(file)
|
||||
content, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func TestAgent_InitKeyring(t *testing.T) {
|
|||
}
|
||||
|
||||
// Content should still be the same
|
||||
content, err = ioutil.ReadFile(file)
|
||||
content, err = os.ReadFile(file)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -33,7 +33,7 @@ func TestLogFile_timeRotation(t *testing.T) {
|
|||
time.Sleep(2 * time.Second)
|
||||
logFile.Write([]byte("Second File"))
|
||||
want := 2
|
||||
if got, _ := ioutil.ReadDir(tempDir); len(got) != want {
|
||||
if got, _ := os.ReadDir(tempDir); len(got) != want {
|
||||
t.Errorf("Expected %d files, got %v file(s)", want, len(got))
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func TestLogFile_openNew(t *testing.T) {
|
|||
}
|
||||
require.NoError(logFile.openNew())
|
||||
|
||||
_, err := ioutil.ReadFile(logFile.FileInfo.Name())
|
||||
_, err := os.ReadFile(logFile.FileInfo.Name())
|
||||
require.NoError(err)
|
||||
|
||||
require.Equal(logFile.FileInfo.Name(), filepath.Join(tempDir, testFileName))
|
||||
|
@ -91,7 +91,7 @@ func TestLogFile_byteRotation(t *testing.T) {
|
|||
logFile.Write([]byte("Hello World"))
|
||||
logFile.Write([]byte("Second File"))
|
||||
want := 2
|
||||
tempFiles, _ := ioutil.ReadDir(tempDir)
|
||||
tempFiles, _ := os.ReadDir(tempDir)
|
||||
require.Equal(want, len(tempFiles))
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ func TestLogFile_logLevelFiltering(t *testing.T) {
|
|||
logFile.Write([]byte("[DEBUG] This is a debug message"))
|
||||
logFile.Write([]byte("[ERR] This is an error message"))
|
||||
want := 2
|
||||
tempFiles, _ := ioutil.ReadDir(tempDir)
|
||||
tempFiles, _ := os.ReadDir(tempDir)
|
||||
require.Equal(want, len(tempFiles))
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ func TestLogFile_deleteArchives(t *testing.T) {
|
|||
logFile.Write([]byte("[INFO] Second File"))
|
||||
logFile.Write([]byte("[INFO] Third File"))
|
||||
want := 2
|
||||
tempFiles, _ := ioutil.ReadDir(tempDir)
|
||||
tempFiles, _ := os.ReadDir(tempDir)
|
||||
|
||||
require.Equal(want, len(tempFiles))
|
||||
|
||||
|
@ -144,7 +144,7 @@ func TestLogFile_deleteArchives(t *testing.T) {
|
|||
var bytes []byte
|
||||
var err error
|
||||
path := filepath.Join(tempDir, tempFile.Name())
|
||||
if bytes, err = ioutil.ReadFile(path); err != nil {
|
||||
if bytes, err = os.ReadFile(path); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
return
|
||||
}
|
||||
|
@ -174,6 +174,6 @@ func TestLogFile_deleteArchivesDisabled(t *testing.T) {
|
|||
logFile.Write([]byte("[INFO] Second File"))
|
||||
logFile.Write([]byte("[INFO] Third File"))
|
||||
want := 3
|
||||
tempFiles, _ := ioutil.ReadDir(tempDir)
|
||||
tempFiles, _ := os.ReadDir(tempDir)
|
||||
require.Equal(want, len(tempFiles))
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
|
||||
"github.com/hashicorp/logutils"
|
||||
)
|
||||
|
@ -12,7 +12,7 @@ func LevelFilter() *logutils.LevelFilter {
|
|||
return &logutils.LevelFilter{
|
||||
Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF"},
|
||||
MinLevel: "INFO",
|
||||
Writer: ioutil.Discard,
|
||||
Writer: io.Discard,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package agent
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -121,7 +120,7 @@ func (a *TestAgent) Start() *TestAgent {
|
|||
name = a.Name + "-agent"
|
||||
}
|
||||
name = strings.ReplaceAll(name, "/", "_")
|
||||
d, err := ioutil.TempDir(TempDir, name)
|
||||
d, err := os.MkdirTemp(TempDir, name)
|
||||
if err != nil {
|
||||
a.T.Fatalf("Error creating data dir %s: %s", filepath.Join(TempDir, name), err)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
@ -475,7 +474,7 @@ func encodeBrokenReq(obj interface{}) io.ReadCloser {
|
|||
// enc.Encode(obj)
|
||||
b, _ := json.Marshal(obj)
|
||||
b = b[0 : len(b)-5] // strip newline and final }
|
||||
return ioutil.NopCloser(bytes.NewReader(b))
|
||||
return io.NopCloser(bytes.NewReader(b))
|
||||
}
|
||||
|
||||
// rpcReadSV lets this test read a variable using the RPC endpoint
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
|
@ -130,9 +129,9 @@ test`,
|
|||
}
|
||||
|
||||
for i, c := range cases {
|
||||
in := ioutil.NopCloser(strings.NewReader(c.Input))
|
||||
in := io.NopCloser(strings.NewReader(c.Input))
|
||||
limit := NewLineLimitReader(in, c.Lines, c.SearchLimit, 0)
|
||||
outBytes, err := ioutil.ReadAll(limit)
|
||||
outBytes, err := io.ReadAll(limit)
|
||||
if err != nil {
|
||||
t.Fatalf("case %d failed: %v", i, err)
|
||||
}
|
||||
|
@ -182,7 +181,7 @@ func TestHelpers_LineLimitReader_TimeLimit(t *testing.T) {
|
|||
go func() {
|
||||
defer close(resultCh)
|
||||
defer close(errCh)
|
||||
outBytes, err := ioutil.ReadAll(limit)
|
||||
outBytes, err := io.ReadAll(limit)
|
||||
if err != nil {
|
||||
errCh <- fmt.Errorf("ReadAll failed: %v", err)
|
||||
return
|
||||
|
@ -258,7 +257,7 @@ var (
|
|||
// Test APIJob with local jobfile
|
||||
func TestJobGetter_LocalFile(t *testing.T) {
|
||||
ci.Parallel(t)
|
||||
fh, err := ioutil.TempFile("", "nomad")
|
||||
fh, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -307,7 +306,7 @@ func TestJobGetter_LocalFile_InvalidHCL2(t *testing.T) {
|
|||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
fh, err := ioutil.TempFile("", "nomad")
|
||||
fh, err := os.CreateTemp("", "nomad")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(fh.Name())
|
||||
defer fh.Close()
|
||||
|
@ -351,7 +350,7 @@ job "example" {
|
|||
fileVars := `var3 = "from-varfile"`
|
||||
expected := []string{"default-val", "from-cli", "from-varfile", "from-envvar"}
|
||||
|
||||
hclf, err := ioutil.TempFile("", "hcl")
|
||||
hclf, err := os.CreateTemp("", "hcl")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(hclf.Name())
|
||||
defer hclf.Close()
|
||||
|
@ -359,7 +358,7 @@ job "example" {
|
|||
_, err = hclf.WriteString(hcl)
|
||||
require.NoError(t, err)
|
||||
|
||||
vf, err := ioutil.TempFile("", "var.hcl")
|
||||
vf, err := os.CreateTemp("", "var.hcl")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(vf.Name())
|
||||
defer vf.Close()
|
||||
|
@ -400,7 +399,7 @@ unsedVar2 = "from-varfile"
|
|||
`
|
||||
expected := []string{"default-val", "from-cli", "from-varfile", "from-envvar"}
|
||||
|
||||
hclf, err := ioutil.TempFile("", "hcl")
|
||||
hclf, err := os.CreateTemp("", "hcl")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(hclf.Name())
|
||||
defer hclf.Close()
|
||||
|
@ -408,7 +407,7 @@ unsedVar2 = "from-varfile"
|
|||
_, err = hclf.WriteString(hcl)
|
||||
require.NoError(t, err)
|
||||
|
||||
vf, err := ioutil.TempFile("", "var.hcl")
|
||||
vf, err := os.CreateTemp("", "var.hcl")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(vf.Name())
|
||||
defer vf.Close()
|
||||
|
|
|
@ -2,7 +2,7 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -145,9 +145,9 @@ func (c *JobDispatchCommand) Run(args []string) int {
|
|||
if len(args) == 2 {
|
||||
switch args[1] {
|
||||
case "-":
|
||||
payload, readErr = ioutil.ReadAll(os.Stdin)
|
||||
payload, readErr = io.ReadAll(os.Stdin)
|
||||
default:
|
||||
payload, readErr = ioutil.ReadFile(args[1])
|
||||
payload, readErr = os.ReadFile(args[1])
|
||||
}
|
||||
if readErr != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error reading input data: %v", readErr))
|
||||
|
|
|
@ -2,7 +2,6 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -182,7 +181,7 @@ func (c *JobInitCommand) Run(args []string) int {
|
|||
}
|
||||
|
||||
// Write out the example
|
||||
err = ioutil.WriteFile(filename, jobSpec, 0660)
|
||||
err = os.WriteFile(filename, jobSpec, 0660)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to write '%s': %v", filename, err))
|
||||
return 1
|
||||
|
|
|
@ -2,7 +2,6 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -50,7 +49,7 @@ func TestInitCommand_Run(t *testing.T) {
|
|||
if code := cmd.Run([]string{}); code != 0 {
|
||||
t.Fatalf("expect exit code 0, got: %d", code)
|
||||
}
|
||||
content, err := ioutil.ReadFile(DefaultInitName)
|
||||
content, err := os.ReadFile(DefaultInitName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -64,7 +63,7 @@ func TestInitCommand_Run(t *testing.T) {
|
|||
if code := cmd.Run([]string{"-short"}); code != 0 {
|
||||
require.Zero(t, code, "unexpected exit code: %d", code)
|
||||
}
|
||||
content, err = ioutil.ReadFile(DefaultInitName)
|
||||
content, err = os.ReadFile(DefaultInitName)
|
||||
require.NoError(t, err)
|
||||
shortJob := asset.JobExampleShort
|
||||
require.Equal(t, string(content), string(shortJob))
|
||||
|
@ -158,7 +157,7 @@ func TestInitCommand_fromJobTemplate(t *testing.T) {
|
|||
// Works if the file doesn't exist
|
||||
must.Eq(t, 0, jobCmd.Run([]string{"-address=" + url, "-template=valid-template"}))
|
||||
|
||||
content, err := ioutil.ReadFile(DefaultInitName)
|
||||
content, err := os.ReadFile(DefaultInitName)
|
||||
must.NoError(t, err)
|
||||
must.Eq(t, string(content), string(tinyJob))
|
||||
|
||||
|
@ -190,7 +189,7 @@ func TestInitCommand_customFilename(t *testing.T) {
|
|||
if code := cmd.Run([]string{filename}); code != 0 {
|
||||
t.Fatalf("expect exit code 0, got: %d", code)
|
||||
}
|
||||
content, err := ioutil.ReadFile(filename)
|
||||
content, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -204,7 +203,7 @@ func TestInitCommand_customFilename(t *testing.T) {
|
|||
if code := cmd.Run([]string{"-short", filename}); code != 0 {
|
||||
require.Zero(t, code, "unexpected exit code: %d", code)
|
||||
}
|
||||
content, err = ioutil.ReadFile(filename)
|
||||
content, err = os.ReadFile(filename)
|
||||
require.NoError(t, err)
|
||||
shortJob := asset.JobExampleShort
|
||||
require.Equal(t, string(content), string(shortJob))
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -49,7 +48,7 @@ func TestPlanCommand_Fails(t *testing.T) {
|
|||
ui.ErrorWriter.Reset()
|
||||
|
||||
// Fails on invalid HCL
|
||||
fh1, err := ioutil.TempFile("", "nomad")
|
||||
fh1, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -66,7 +65,7 @@ func TestPlanCommand_Fails(t *testing.T) {
|
|||
ui.ErrorWriter.Reset()
|
||||
|
||||
// Fails on invalid job spec
|
||||
fh2, err := ioutil.TempFile("", "nomad")
|
||||
fh2, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -83,7 +82,7 @@ func TestPlanCommand_Fails(t *testing.T) {
|
|||
ui.ErrorWriter.Reset()
|
||||
|
||||
// Fails on connection failure (requires a valid job)
|
||||
fh3, err := ioutil.TempFile("", "nomad")
|
||||
fh3, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package command
|
|||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -23,7 +22,7 @@ func TestRunCommand_Output_Json(t *testing.T) {
|
|||
ui := cli.NewMockUi()
|
||||
cmd := &JobRunCommand{Meta: Meta{Ui: ui}}
|
||||
|
||||
fh, err := ioutil.TempFile("", "nomad")
|
||||
fh, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -101,7 +100,7 @@ func TestRunCommand_Fails(t *testing.T) {
|
|||
ui.ErrorWriter.Reset()
|
||||
|
||||
// Fails on invalid HCL
|
||||
fh1, err := ioutil.TempFile("", "nomad")
|
||||
fh1, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -118,7 +117,7 @@ func TestRunCommand_Fails(t *testing.T) {
|
|||
ui.ErrorWriter.Reset()
|
||||
|
||||
// Fails on invalid job spec
|
||||
fh2, err := ioutil.TempFile("", "nomad")
|
||||
fh2, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -135,7 +134,7 @@ func TestRunCommand_Fails(t *testing.T) {
|
|||
ui.ErrorWriter.Reset()
|
||||
|
||||
// Fails on connection failure (requires a valid job)
|
||||
fh3, err := ioutil.TempFile("", "nomad")
|
||||
fh3, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -109,7 +108,7 @@ func TestValidateCommand_Fails(t *testing.T) {
|
|||
ui.ErrorWriter.Reset()
|
||||
|
||||
// Fails on invalid HCL
|
||||
fh1, err := ioutil.TempFile("", "nomad")
|
||||
fh1, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -126,7 +125,7 @@ func TestValidateCommand_Fails(t *testing.T) {
|
|||
ui.ErrorWriter.Reset()
|
||||
|
||||
// Fails on invalid job spec
|
||||
fh2, err := ioutil.TempFile("", "nomad")
|
||||
fh2, err := os.CreateTemp("", "nomad")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -120,13 +120,13 @@ func (c *NamespaceApplyCommand) Run(args []string) int {
|
|||
}
|
||||
|
||||
if file == "-" {
|
||||
rawNamespace, err = ioutil.ReadAll(os.Stdin)
|
||||
rawNamespace, err = io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read stdin: %v", err))
|
||||
return 1
|
||||
}
|
||||
} else {
|
||||
rawNamespace, err = ioutil.ReadFile(file)
|
||||
rawNamespace, err = os.ReadFile(file)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read file: %v", err))
|
||||
return 1
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -151,7 +150,7 @@ func (c *OperatorAPICommand) Run(args []string) int {
|
|||
|
||||
// Load stdin into a *bytes.Reader so that http.NewRequest can set the
|
||||
// correct Content-Length value.
|
||||
b, err := ioutil.ReadAll(Stdin)
|
||||
b, err := io.ReadAll(Stdin)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error reading stdin: %v", err))
|
||||
return 1
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
@ -482,7 +481,7 @@ func (c *OperatorDebugCommand) Run(args []string) int {
|
|||
}
|
||||
} else {
|
||||
// Generate temp directory
|
||||
tmp, err = ioutil.TempDir(os.TempDir(), stamped)
|
||||
tmp, err = os.MkdirTemp(os.TempDir(), stamped)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error creating tmp directory: %s", err.Error()))
|
||||
return 2
|
||||
|
@ -1476,7 +1475,7 @@ func (c *OperatorDebugCommand) writeBody(dir, file string, resp *http.Response,
|
|||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
c.writeError(dir, file, err)
|
||||
return
|
||||
|
@ -1821,7 +1820,7 @@ func (e *external) token() string {
|
|||
}
|
||||
|
||||
if e.tokenFile != "" {
|
||||
bs, err := ioutil.ReadFile(e.tokenFile)
|
||||
bs, err := os.ReadFile(e.tokenFile)
|
||||
if err == nil {
|
||||
return strings.TrimSpace(string(bs))
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
@ -730,8 +730,8 @@ func TestDebug_CollectConsul(t *testing.T) {
|
|||
c.Peering = nil // fix for older versions of Consul (<1.13.0) that don't support peering
|
||||
// If -v wasn't specified squelch consul logging
|
||||
if !testing.Verbose() {
|
||||
c.Stdout = ioutil.Discard
|
||||
c.Stderr = ioutil.Discard
|
||||
c.Stdout = io.Discard
|
||||
c.Stderr = io.Discard
|
||||
}
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
@ -40,7 +40,7 @@ func TestOperatorSnapshotInspect_HandlesFailure(t *testing.T) {
|
|||
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
err := ioutil.WriteFile(
|
||||
err := os.WriteFile(
|
||||
filepath.Join(tmpDir, "invalid.snap"),
|
||||
[]byte("invalid data"),
|
||||
0600)
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -85,13 +85,13 @@ func (c *QuotaApplyCommand) Run(args []string) int {
|
|||
var rawQuota []byte
|
||||
var err error
|
||||
if file == "-" {
|
||||
rawQuota, err = ioutil.ReadAll(os.Stdin)
|
||||
rawQuota, err = io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read stdin: %v", err))
|
||||
return 1
|
||||
}
|
||||
} else {
|
||||
rawQuota, err = ioutil.ReadFile(file)
|
||||
rawQuota, err = os.ReadFile(file)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read file: %v", err))
|
||||
return 1
|
||||
|
|
|
@ -2,7 +2,6 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -97,7 +96,7 @@ func (c *QuotaInitCommand) Run(args []string) int {
|
|||
}
|
||||
|
||||
// Write out the example
|
||||
err = ioutil.WriteFile(fileName, []byte(fileContent), 0660)
|
||||
err = os.WriteFile(fileName, []byte(fileContent), 0660)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to write %q: %v", fileName, err))
|
||||
return 1
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
@ -42,7 +41,7 @@ func TestQuotaInitCommand_Run_HCL(t *testing.T) {
|
|||
require.Empty(t, ui.ErrorWriter.String())
|
||||
require.Zero(t, code)
|
||||
|
||||
content, err := ioutil.ReadFile(DefaultHclQuotaInitName)
|
||||
content, err := os.ReadFile(DefaultHclQuotaInitName)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, defaultHclQuotaSpec, string(content))
|
||||
|
||||
|
@ -57,7 +56,7 @@ func TestQuotaInitCommand_Run_HCL(t *testing.T) {
|
|||
require.Empty(t, ui.ErrorWriter.String())
|
||||
require.Zero(t, code)
|
||||
|
||||
content, err = ioutil.ReadFile("mytest.hcl")
|
||||
content, err = os.ReadFile("mytest.hcl")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, defaultHclQuotaSpec, string(content))
|
||||
}
|
||||
|
@ -89,7 +88,7 @@ func TestQuotaInitCommand_Run_JSON(t *testing.T) {
|
|||
require.Empty(t, ui.ErrorWriter.String())
|
||||
require.Zero(t, code)
|
||||
|
||||
content, err := ioutil.ReadFile(DefaultJsonQuotaInitName)
|
||||
content, err := os.ReadFile(DefaultJsonQuotaInitName)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, defaultJsonQuotaSpec, string(content))
|
||||
|
||||
|
@ -104,7 +103,7 @@ func TestQuotaInitCommand_Run_JSON(t *testing.T) {
|
|||
require.Empty(t, ui.ErrorWriter.String())
|
||||
require.Zero(t, code)
|
||||
|
||||
content, err = ioutil.ReadFile("mytest.json")
|
||||
content, err = os.ReadFile("mytest.json")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, defaultJsonQuotaSpec, string(content))
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -91,13 +91,13 @@ func (c *SentinelApplyCommand) Run(args []string) int {
|
|||
file := args[1]
|
||||
var rawPolicy []byte
|
||||
if file == "-" {
|
||||
rawPolicy, err = ioutil.ReadAll(os.Stdin)
|
||||
rawPolicy, err = io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read stdin: %v", err))
|
||||
return 1
|
||||
}
|
||||
} else {
|
||||
rawPolicy, err = ioutil.ReadFile(file)
|
||||
rawPolicy, err = os.ReadFile(file)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read file: %v", err))
|
||||
return 1
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -235,7 +234,7 @@ func (b *KVBuilder) add(raw string) error {
|
|||
|
||||
if len(value) > 0 {
|
||||
if value[0] == '@' {
|
||||
contents, err := ioutil.ReadFile(value[1:])
|
||||
contents, err := os.ReadFile(value[1:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading file: %w", err)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -68,13 +68,13 @@ func (c *VolumeCreateCommand) Run(args []string) int {
|
|||
var rawVolume []byte
|
||||
var err error
|
||||
if file == "-" {
|
||||
rawVolume, err = ioutil.ReadAll(os.Stdin)
|
||||
rawVolume, err = io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read stdin: %v", err))
|
||||
return 1
|
||||
}
|
||||
} else {
|
||||
rawVolume, err = ioutil.ReadFile(file)
|
||||
rawVolume, err = os.ReadFile(file)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read file: %v", err))
|
||||
return 1
|
||||
|
|
|
@ -2,7 +2,6 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -97,7 +96,7 @@ func (c *VolumeInitCommand) Run(args []string) int {
|
|||
}
|
||||
|
||||
// Write out the example
|
||||
err = ioutil.WriteFile(fileName, []byte(fileContent), 0660)
|
||||
err = os.WriteFile(fileName, []byte(fileContent), 0660)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to write %q: %v", fileName, err))
|
||||
return 1
|
||||
|
|
|
@ -2,7 +2,7 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -71,13 +71,13 @@ func (c *VolumeRegisterCommand) Run(args []string) int {
|
|||
var rawVolume []byte
|
||||
var err error
|
||||
if file == "-" {
|
||||
rawVolume, err = ioutil.ReadAll(os.Stdin)
|
||||
rawVolume, err = io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read stdin: %v", err))
|
||||
return 1
|
||||
}
|
||||
} else {
|
||||
rawVolume, err = ioutil.ReadFile(file)
|
||||
rawVolume, err = os.ReadFile(file)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to read file: %v", err))
|
||||
return 1
|
||||
|
|
Loading…
Reference in New Issue