Skip to content

Commit

Permalink
Update ioutil library references to os and io respectively for command
Browse files Browse the repository at this point in the history
(manual cherry-pick f0fd046)

No user facing changes so I assume no change log is required
  • Loading branch information
lhaig authored and shoenig committed Mar 8, 2023
1 parent 707224c commit 99fb937
Show file tree
Hide file tree
Showing 38 changed files with 126 additions and 145 deletions.
6 changes: 3 additions & 3 deletions command/acl_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package command

import (
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -86,10 +86,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))
Expand Down
6 changes: 3 additions & 3 deletions command/acl_policy_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package command

import (
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -76,13 +76,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
Expand Down
7 changes: 3 additions & 4 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
golog "log"
"net"
"os"
Expand Down Expand Up @@ -850,7 +849,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
}
Expand All @@ -875,7 +874,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
Expand All @@ -887,7 +886,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
}

Expand Down
6 changes: 3 additions & 3 deletions command/agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions command/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package agent

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -1273,7 +1272,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 (
Expand Down Expand Up @@ -1325,7 +1324,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{
Expand Down
3 changes: 1 addition & 2 deletions command/agent/alloc_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"archive/tar"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions command/agent/bindata_assetfs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions command/agent/command_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package agent

import (
"io/ioutil"
"math"
"os"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestCommand_NullCharInDatacenter(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
Expand Down Expand Up @@ -207,7 +207,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
Expand Down
15 changes: 7 additions & 8 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package agent

import (
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -460,7 +459,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)
}
Expand Down Expand Up @@ -514,19 +513,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)
}
Expand Down Expand Up @@ -558,7 +557,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)
}
Expand Down Expand Up @@ -586,7 +585,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)
}
Expand Down Expand Up @@ -1342,7 +1341,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
Expand Down
6 changes: 3 additions & 3 deletions command/agent/consul/group_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package consul

import (
"io/ioutil"
"io"
"testing"
"time"

Expand All @@ -22,8 +22,8 @@ func TestConsul_Connect(t *testing.T) {
testconsul, err := testutil.NewTestServerConfigT(t, func(c *testutil.TestServerConfig) {
// 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 {
Expand Down
6 changes: 3 additions & 3 deletions command/agent/consul/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package consul_test

import (
"context"
"io/ioutil"
"io"
"testing"
"time"

Expand Down Expand Up @@ -48,8 +48,8 @@ func TestConsul_Integration(t *testing.T) {
testconsul, err := testutil.NewTestServerConfigT(t, func(c *testutil.TestServerConfig) {
// 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 {
Expand Down
Loading

0 comments on commit 99fb937

Please sign in to comment.