Move from deprecated ioutil to os and io packages
parent
c03ffa5e58
commit
70022d9b2e
|
@ -20,7 +20,7 @@ import (
|
|||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
@ -47,7 +47,7 @@ var targetIP *string
|
|||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("Handling a request")
|
||||
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Printf("error: %v", err)
|
||||
return
|
||||
|
|
|
@ -17,8 +17,8 @@ limitations under the License.
|
|||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -84,7 +84,7 @@ var addonsConfigureCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
// Read file from disk
|
||||
dat, err := ioutil.ReadFile(gcrPath)
|
||||
dat, err := os.ReadFile(gcrPath)
|
||||
|
||||
if err != nil {
|
||||
out.FailureT("Error reading {{.path}}: {{.error}}", out.V{"path": gcrPath, "error": err})
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
@ -67,7 +66,7 @@ func TestSetOK(t *testing.T) {
|
|||
|
||||
func createTestConfig(t *testing.T) {
|
||||
t.Helper()
|
||||
td, err := ioutil.TempDir("", "config")
|
||||
td, err := os.MkdirTemp("", "config")
|
||||
if err != nil {
|
||||
t.Fatalf("tempdir: %v", err)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package cmd
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
@ -524,7 +523,7 @@ func killMountProcess() error {
|
|||
}
|
||||
|
||||
klog.Infof("Found %s ...", pidPath)
|
||||
out, err := ioutil.ReadFile(pidPath)
|
||||
out, err := os.ReadFile(pidPath)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ReadFile")
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
@ -53,7 +52,7 @@ func exclude(vals []string, exclude []string) []string {
|
|||
|
||||
func fileNames(path string) ([]string, error) {
|
||||
result := []string{}
|
||||
fis, err := ioutil.ReadDir(path)
|
||||
fis, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
@ -64,7 +63,7 @@ func fileNames(path string) ([]string, error) {
|
|||
}
|
||||
|
||||
func TestDeleteProfile(t *testing.T) {
|
||||
td, err := ioutil.TempDir("", "single")
|
||||
td, err := os.MkdirTemp("", "single")
|
||||
if err != nil {
|
||||
t.Fatalf("tempdir: %v", err)
|
||||
}
|
||||
|
@ -170,7 +169,7 @@ func deleteContextTest() error {
|
|||
}
|
||||
|
||||
func TestDeleteAllProfiles(t *testing.T) {
|
||||
td, err := ioutil.TempDir("", "all")
|
||||
td, err := os.MkdirTemp("", "all")
|
||||
if err != nil {
|
||||
t.Fatalf("tempdir: %v", err)
|
||||
}
|
||||
|
@ -234,7 +233,7 @@ func TestDeleteAllProfiles(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("profiles: %v", err)
|
||||
}
|
||||
afterMachines, err := ioutil.ReadDir(filepath.Join(localpath.MiniPath(), "machines"))
|
||||
afterMachines, err := os.ReadDir(filepath.Join(localpath.MiniPath(), "machines"))
|
||||
if err != nil {
|
||||
t.Errorf("machines: %v", err)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -27,7 +26,7 @@ import (
|
|||
)
|
||||
|
||||
func TestGenerateTestDocs(t *testing.T) {
|
||||
tempdir, err := ioutil.TempDir("", "")
|
||||
tempdir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
t.Fatalf("creating temp dir failed: %v", err)
|
||||
}
|
||||
|
@ -38,7 +37,7 @@ func TestGenerateTestDocs(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("error generating test docs: %v", err)
|
||||
}
|
||||
actualContents, err := ioutil.ReadFile(docPath)
|
||||
actualContents, err := os.ReadFile(docPath)
|
||||
if err != nil {
|
||||
t.Fatalf("error reading generated file: %v", err)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package cmd
|
|||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -58,7 +57,7 @@ var (
|
|||
)
|
||||
|
||||
func saveFile(r io.Reader) (string, error) {
|
||||
tmp, err := ioutil.TempFile("", "build.*.tar")
|
||||
tmp, err := os.CreateTemp("", "build.*.tar")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -184,7 +183,7 @@ var saveImageCmd = &cobra.Command{
|
|||
output = args[1]
|
||||
|
||||
if args[1] == "-" {
|
||||
tmp, err := ioutil.TempFile("", "image.*.tar")
|
||||
tmp, err := os.CreateTemp("", "image.*.tar")
|
||||
if err != nil {
|
||||
exit.Error(reason.GuestImageSave, "Failed to get temp", err)
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import (
|
|||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
|
@ -36,7 +36,7 @@ func getSHAFromURL(url string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -75,7 +74,7 @@ func extensionToBoilerplate(dir string) (map[string][]byte, error) {
|
|||
files, _ := filepath.Glob(dir + "/*.txt")
|
||||
for _, filename := range files {
|
||||
extension := strings.ToLower(filepath.Ext(txtExtension.ReplaceAllString(filename, "")))
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -97,7 +96,7 @@ func extensionToBoilerplate(dir string) (map[string][]byte, error) {
|
|||
|
||||
// filePasses checks whether the processed file is valid. Returning false means that the file does not the proper boilerplate template.
|
||||
func filePasses(filename string, expectedBoilerplate []byte) (bool, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
|
@ -218,7 +217,7 @@ func prepareImage(ctx context.Context, current, release string) (image string, e
|
|||
|
||||
// getKICVersion returns current kic base image version and any error
|
||||
func getKICVersion() (string, error) {
|
||||
blob, err := ioutil.ReadFile(kicFile)
|
||||
blob, err := os.ReadFile(kicFile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
@ -56,12 +56,12 @@ func downloadMinikube(ctx context.Context, minikubePath string) error {
|
|||
}
|
||||
defer rc.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(rc)
|
||||
data, err := io.ReadAll(rc)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ioutil read all")
|
||||
return errors.Wrap(err, "io read all")
|
||||
}
|
||||
log.Printf("downloading gs://%s/%s to %v", bucketName, binary(), minikubePath)
|
||||
if err := ioutil.WriteFile(minikubePath, data, 0777); err != nil {
|
||||
if err := os.WriteFile(minikubePath, data, 0777); err != nil {
|
||||
return errors.Wrap(err, "writing minikubePath")
|
||||
}
|
||||
if err := os.Chmod(minikubePath, 0700); err != nil {
|
||||
|
|
|
@ -19,7 +19,6 @@ package update
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
@ -40,7 +39,7 @@ func fsUpdate(fsRoot string, schema map[string]Item, data interface{}) (changed
|
|||
return false, fmt.Errorf("unable to get file content: %w", err)
|
||||
}
|
||||
mode = info.Mode()
|
||||
content, err = ioutil.ReadFile(path)
|
||||
content, err = os.ReadFile(path)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("unable to read file content: %w", err)
|
||||
}
|
||||
|
@ -54,7 +53,7 @@ func fsUpdate(fsRoot string, schema map[string]Item, data interface{}) (changed
|
|||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
return false, fmt.Errorf("unable to create directory: %w", err)
|
||||
}
|
||||
if err := ioutil.WriteFile(path, item.Content, mode); err != nil {
|
||||
if err := os.WriteFile(path, item.Content, mode); err != nil {
|
||||
return false, fmt.Errorf("unable to write file: %w", err)
|
||||
}
|
||||
changed = true
|
||||
|
@ -65,7 +64,7 @@ func fsUpdate(fsRoot string, schema map[string]Item, data interface{}) (changed
|
|||
|
||||
// Loadf returns the file content read as byte slice
|
||||
func Loadf(path string) []byte {
|
||||
blob, err := ioutil.ReadFile(path)
|
||||
blob, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
klog.Fatalf("Unable to load file %s: %v", path, err)
|
||||
return nil
|
||||
|
|
|
@ -28,7 +28,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -157,7 +157,7 @@ func goVersions() (stable, stableMM, k8sVersion string, err error) {
|
|||
if err != nil {
|
||||
return "", "", "", err
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", "", "", err
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
@ -121,7 +121,7 @@ func main() {
|
|||
|
||||
// KICVersions returns current and stable KIC base image versions and any error occurred.
|
||||
func KICVersions() (current, stable string, err error) {
|
||||
blob, err := ioutil.ReadFile(filepath.Join(update.FSRoot, kicFile))
|
||||
blob, err := os.ReadFile(filepath.Join(update.FSRoot, kicFile))
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
|
@ -75,7 +74,7 @@ func enableAddonGCPAuth(cfg *config.ClusterConfig) error {
|
|||
if err != nil {
|
||||
if detect.IsCloudShell() {
|
||||
if c := os.Getenv("CLOUDSDK_CONFIG"); c != "" {
|
||||
f, err := ioutil.ReadFile(path.Join(c, "application_default_credentials.json"))
|
||||
f, err := os.ReadFile(path.Join(c, "application_default_credentials.json"))
|
||||
if err == nil {
|
||||
creds, _ = google.CredentialsFromJSON(ctx, f)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package addons
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
@ -31,7 +30,7 @@ import (
|
|||
|
||||
func createTestProfile(t *testing.T) string {
|
||||
t.Helper()
|
||||
td, err := ioutil.TempDir("", "profile")
|
||||
td, err := os.MkdirTemp("", "profile")
|
||||
if err != nil {
|
||||
t.Fatalf("tempdir: %v", err)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package drivers
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
@ -136,7 +135,7 @@ func fixMachinePermissions(path string) error {
|
|||
if err := os.Chown(path, syscall.Getuid(), syscall.Getegid()); err != nil {
|
||||
return errors.Wrap(err, "chown dir")
|
||||
}
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "read dir")
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package drivers
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
@ -30,7 +29,7 @@ func Test_createDiskImage(t *testing.T) {
|
|||
defer tests.RemoveTempDir(tmpdir)
|
||||
|
||||
sshPath := filepath.Join(tmpdir, "ssh")
|
||||
if err := ioutil.WriteFile(sshPath, []byte("mysshkey"), 0644); err != nil {
|
||||
if err := os.WriteFile(sshPath, []byte("mysshkey"), 0644); err != nil {
|
||||
t.Fatalf("writefile: %v", err)
|
||||
}
|
||||
diskPath := filepath.Join(tmpdir, "disk")
|
||||
|
|
|
@ -22,7 +22,6 @@ package hyperkit
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
|
@ -366,7 +365,7 @@ func (d *Driver) recoverFromUncleanShutdown() error {
|
|||
}
|
||||
|
||||
log.Warnf("minikube might have been shutdown in an unclean way, the hyperkit pid file still exists: %s", pidFile)
|
||||
bs, err := ioutil.ReadFile(pidFile)
|
||||
bs, err := os.ReadFile(pidFile)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "reading pidfile %s", pidFile)
|
||||
}
|
||||
|
|
|
@ -17,13 +17,12 @@ limitations under the License.
|
|||
package hyperkit
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExtractFile(t *testing.T) {
|
||||
testDir, err := ioutil.TempDir(os.TempDir(), "")
|
||||
testDir, err := os.MkdirTemp(os.TempDir(), "")
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ limitations under the License.
|
|||
package hyperkit
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
@ -54,12 +54,12 @@ func Test_getIpAddressFromFile(t *testing.T) {
|
|||
defer tests.RemoveTempDir(tmpdir)
|
||||
|
||||
dhcpFile := filepath.Join(tmpdir, "dhcp")
|
||||
if err := ioutil.WriteFile(dhcpFile, validLeases, 0644); err != nil {
|
||||
if err := os.WriteFile(dhcpFile, validLeases, 0644); err != nil {
|
||||
t.Fatalf("writefile: %v", err)
|
||||
}
|
||||
|
||||
invalidFile := filepath.Join(tmpdir, "invalid")
|
||||
if err := ioutil.WriteFile(invalidFile, []byte("foo"), 0644); err != nil {
|
||||
if err := os.WriteFile(invalidFile, []byte("foo"), 0644); err != nil {
|
||||
t.Fatalf("writefile: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ package kvm
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -106,7 +105,7 @@ func getDevicesXML() (string, error) {
|
|||
func getPassthroughableNVIDIADevices() ([]string, error) {
|
||||
|
||||
// Make sure the host supports IOMMU
|
||||
iommuGroups, err := ioutil.ReadDir(sysKernelIOMMUGroupsPath)
|
||||
iommuGroups, err := os.ReadDir(sysKernelIOMMUGroupsPath)
|
||||
if err != nil {
|
||||
return []string{}, fmt.Errorf("error reading %q: %v", sysKernelIOMMUGroupsPath, err)
|
||||
}
|
||||
|
@ -115,7 +114,7 @@ func getPassthroughableNVIDIADevices() ([]string, error) {
|
|||
}
|
||||
|
||||
// Get list of PCI devices
|
||||
devices, err := ioutil.ReadDir(sysFsPCIDevicesPath)
|
||||
devices, err := os.ReadDir(sysFsPCIDevicesPath)
|
||||
if err != nil {
|
||||
return []string{}, fmt.Errorf("error reading %q: %v", sysFsPCIDevicesPath, err)
|
||||
}
|
||||
|
@ -124,7 +123,7 @@ func getPassthroughableNVIDIADevices() ([]string, error) {
|
|||
found := false
|
||||
for _, device := range devices {
|
||||
vendorPath := filepath.Join(sysFsPCIDevicesPath, device.Name(), "vendor")
|
||||
content, err := ioutil.ReadFile(vendorPath)
|
||||
content, err := os.ReadFile(vendorPath)
|
||||
if err != nil {
|
||||
log.Infof("Error while reading %q: %v", vendorPath, err)
|
||||
continue
|
||||
|
@ -173,7 +172,7 @@ func getPassthroughableNVIDIADevices() ([]string, error) {
|
|||
func isIsolated(device string) bool {
|
||||
// Find out the other devices in the same IOMMU group as one of our unbound device.
|
||||
iommuGroupPath := filepath.Join(sysFsPCIDevicesPath, device, "iommu_group", "devices")
|
||||
otherDevices, err := ioutil.ReadDir(iommuGroupPath)
|
||||
otherDevices, err := os.ReadDir(iommuGroupPath)
|
||||
if err != nil {
|
||||
log.Infof("Error reading %q: %v", iommuGroupPath, err)
|
||||
return false
|
||||
|
|
|
@ -18,7 +18,6 @@ package ssh
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -110,7 +109,7 @@ func (d *Driver) PreCreateCheck() error {
|
|||
return fmt.Errorf("SSH key does not exist: %q", d.SSHKey)
|
||||
}
|
||||
|
||||
key, err := ioutil.ReadFile(d.SSHKey)
|
||||
key, err := os.ReadFile(d.SSHKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
@ -166,5 +165,5 @@ func saveDocForCommand(command *cobra.Command, contents []byte, path string) err
|
|||
if err := os.Remove(fp); err != nil {
|
||||
klog.Warningf("error removing %s", fp)
|
||||
}
|
||||
return ioutil.WriteFile(fp, contents, 0o644)
|
||||
return os.WriteFile(fp, contents, 0o644)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -41,7 +41,7 @@ func ErrorCodes(docPath string, pathsToCheck []string) error {
|
|||
|
||||
fset := token.NewFileSet()
|
||||
for _, pathToCheck := range pathsToCheck {
|
||||
r, err := ioutil.ReadFile(pathToCheck)
|
||||
r, err := os.ReadFile(pathToCheck)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("error reading file %s", pathToCheck))
|
||||
}
|
||||
|
@ -122,5 +122,5 @@ func ErrorCodes(docPath string, pathsToCheck []string) error {
|
|||
}
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(docPath, buf.Bytes(), 0o644)
|
||||
return os.WriteFile(docPath, buf.Bytes(), 0o644)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -47,7 +46,7 @@ func TestDocs(docPath string, pathToCheck string) error {
|
|||
return nil
|
||||
}
|
||||
fset := token.NewFileSet()
|
||||
r, e := ioutil.ReadFile(path)
|
||||
r, e := os.ReadFile(path)
|
||||
if e != nil {
|
||||
return errors.Wrap(e, fmt.Sprintf("error reading file %s", path))
|
||||
}
|
||||
|
@ -103,7 +102,7 @@ func TestDocs(docPath string, pathToCheck string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(docPath, buf.Bytes(), 0o644)
|
||||
err = os.WriteFile(docPath, buf.Bytes(), 0o644)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ package gvisor
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -179,7 +178,7 @@ func copyAssetToDest(targetName, dest string) error {
|
|||
// Now, copy the data from this asset to dest
|
||||
src := filepath.Join(vmpath.GuestGvisorDir, asset.GetTargetName())
|
||||
log.Printf("%s asset path: %s", targetName, src)
|
||||
contents, err := ioutil.ReadFile(src)
|
||||
contents, err := os.ReadFile(src)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "getting contents of %s", asset.GetSourcePath())
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package audit
|
|||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
@ -39,7 +38,7 @@ func TestLogFile(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("AppendToLog", func(t *testing.T) {
|
||||
f, err := ioutil.TempFile("", "audit.json")
|
||||
f, err := os.CreateTemp("", "audit.json")
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating temporary file: %v", err)
|
||||
}
|
||||
|
|
|
@ -17,13 +17,12 @@ limitations under the License.
|
|||
package audit
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReport(t *testing.T) {
|
||||
f, err := ioutil.TempFile("", "audit.json")
|
||||
f, err := os.CreateTemp("", "audit.json")
|
||||
if err != nil {
|
||||
t.Fatalf("failed creating temporary file: %v", err)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ package bsutil
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -83,7 +83,7 @@ func getExtraOptsPodCidr() []config.ExtraOption {
|
|||
// It will error if no testdata are available or in absence of testdata for newest and default minor k8s versions.
|
||||
func recentReleases(n int) ([]string, error) {
|
||||
path := "testdata"
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to list testdata directory %s: %w", path, err)
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ func TestGenerateKubeadmYAMLDNS(t *testing.T) {
|
|||
if tc.shouldErr {
|
||||
return
|
||||
}
|
||||
expected, err := ioutil.ReadFile(fmt.Sprintf("testdata/%s/%s.yaml", version, tc.name))
|
||||
expected, err := os.ReadFile(fmt.Sprintf("testdata/%s/%s.yaml", version, tc.name))
|
||||
if err != nil {
|
||||
t.Fatalf("unable to read testdata: %v", err)
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ func TestGenerateKubeadmYAML(t *testing.T) {
|
|||
if tc.shouldErr {
|
||||
return
|
||||
}
|
||||
expected, err := ioutil.ReadFile(fmt.Sprintf("testdata/%s/%s.yaml", version, tc.name))
|
||||
expected, err := os.ReadFile(fmt.Sprintf("testdata/%s/%s.yaml", version, tc.name))
|
||||
if err != nil {
|
||||
t.Fatalf("unable to read testdata: %v", err)
|
||||
}
|
||||
|
|
|
@ -21,9 +21,10 @@ import (
|
|||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strconv"
|
||||
|
@ -237,7 +238,7 @@ func apiServerHealthz(hostname string, port int) (state.State, error) {
|
|||
func apiServerHealthzNow(hostname string, port int) (state.State, error) {
|
||||
url := fmt.Sprintf("https://%s/healthz", net.JoinHostPort(hostname, fmt.Sprint(port)))
|
||||
klog.Infof("Checking apiserver healthz at %s ...", url)
|
||||
cert, err := ioutil.ReadFile(localpath.CACert())
|
||||
cert, err := os.ReadFile(localpath.CACert())
|
||||
if err != nil {
|
||||
klog.Infof("ca certificate: %v", err)
|
||||
return state.Stopped, err
|
||||
|
@ -257,7 +258,7 @@ func apiServerHealthzNow(hostname string, port int) (state.State, error) {
|
|||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
klog.Warningf("unable to read response body: %s", err)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -334,7 +333,7 @@ func generateProfileCerts(cfg config.ClusterConfig, n config.Node, ccs CACerts,
|
|||
|
||||
// isValidPEMCertificate checks whether the input file is a valid PEM certificate (with at least one CERTIFICATE block)
|
||||
func isValidPEMCertificate(filePath string) (bool, error) {
|
||||
fileBytes, err := ioutil.ReadFile(filePath)
|
||||
fileBytes, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ func fileExists(r Runner, f assets.CopyableFile, dst string) (bool, error) {
|
|||
return srcModTime.Equal(dstModTime), nil
|
||||
}
|
||||
|
||||
// writeFile is like ioutil.WriteFile, but does not require reading file into memory
|
||||
// writeFile is like os.WriteFile, but does not require reading file into memory
|
||||
func writeFile(dst string, f assets.CopyableFile, perms os.FileMode) error {
|
||||
w, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE, perms)
|
||||
if err != nil {
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
|
@ -161,7 +160,7 @@ func (e *execRunner) Copy(f assets.CopyableFile) error {
|
|||
|
||||
if e.sudo {
|
||||
// write to temp location ...
|
||||
tmpfile, err := ioutil.TempFile("", "minikube")
|
||||
tmpfile, err := os.CreateTemp("", "minikube")
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating tempfile")
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
|
@ -192,7 +191,7 @@ func (k *kicRunner) Copy(f assets.CopyableFile) error {
|
|||
return errors.Wrap(err, "determining temp directory")
|
||||
}
|
||||
|
||||
tf, err := ioutil.TempFile(tmpFolder, "tmpf-memory-asset")
|
||||
tf, err := os.CreateTemp(tmpFolder, "tmpf-memory-asset")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "creating temporary file")
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -211,7 +210,7 @@ func (c *simpleConfigLoader) LoadConfigFromFile(profileName string, miniHome ...
|
|||
return nil, errors.Wrap(err, "stat")
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsPermission(err) {
|
||||
return nil, &ErrPermissionDenied{err.Error()}
|
||||
|
@ -231,7 +230,7 @@ func (c *simpleConfigLoader) WriteConfigToFile(profileName string, cc *ClusterCo
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(path, contents, 0644)
|
||||
return os.WriteFile(path, contents, 0644)
|
||||
}
|
||||
|
||||
// MultiNode returns true if the cluster has multiple nodes or if the request is asking for multinode
|
||||
|
|
|
@ -19,7 +19,6 @@ package config
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
@ -144,7 +143,7 @@ func TestReadConfig(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWriteConfig(t *testing.T) {
|
||||
configFile, err := ioutil.TempFile("/tmp", "configTest")
|
||||
configFile, err := os.CreateTemp("/tmp", "configTest")
|
||||
if err != nil {
|
||||
t.Fatalf("Error not expected but got %v", err)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package config
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
@ -155,13 +154,13 @@ func SaveProfile(name string, cfg *ClusterConfig, miniHome ...string) error {
|
|||
return lock.WriteFile(path, data, 0600)
|
||||
}
|
||||
|
||||
tf, err := ioutil.TempFile(filepath.Dir(path), "config.json.tmp")
|
||||
tf, err := os.CreateTemp(filepath.Dir(path), "config.json.tmp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
|
||||
if err = ioutil.WriteFile(tf.Name(), data, 0600); err != nil {
|
||||
if err = os.WriteFile(tf.Name(), data, 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -295,7 +294,7 @@ func profileDirs(miniHome ...string) (dirs []string, err error) {
|
|||
miniPath = miniHome[0]
|
||||
}
|
||||
pRootDir := filepath.Join(miniPath, "profiles")
|
||||
items, err := ioutil.ReadDir(pRootDir)
|
||||
items, err := os.ReadDir(pRootDir)
|
||||
for _, f := range items {
|
||||
if f.IsDir() {
|
||||
dirs = append(dirs, f.Name())
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
@ -302,12 +301,12 @@ func TestGetPrimaryControlPlane(t *testing.T) {
|
|||
originalFilePath := profileFilePath(tc.profile, miniDir)
|
||||
tempFilePath := filepath.Join(miniDir, "profiles", tc.profile, "config_temp.json")
|
||||
|
||||
d, err := ioutil.ReadFile(originalFilePath)
|
||||
d, err := os.ReadFile(originalFilePath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to read config file : %s", originalFilePath)
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(tempFilePath, d, 0644)
|
||||
err = os.WriteFile(tempFilePath, d, 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to write temporal config file : %s", tempFilePath)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -188,7 +187,7 @@ func Preload(k8sVersion, containerRuntime, driverName string) error {
|
|||
if err != nil {
|
||||
klog.Warningf("No checksum for preloaded tarball for k8s version %s: %v", k8sVersion, err)
|
||||
realPath = targetPath
|
||||
tmp, err := ioutil.TempFile(targetDir(), TarballName(k8sVersion, containerRuntime)+".*")
|
||||
tmp, err := os.CreateTemp(targetDir(), TarballName(k8sVersion, containerRuntime)+".*")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "tempfile")
|
||||
}
|
||||
|
@ -245,7 +244,7 @@ var getChecksum = func(k8sVersion, containerRuntime string) ([]byte, error) {
|
|||
// saveChecksumFile saves the checksum to a local file for later verification
|
||||
func saveChecksumFile(k8sVersion, containerRuntime string, checksum []byte) error {
|
||||
klog.Infof("saving checksum for %s ...", TarballName(k8sVersion, containerRuntime))
|
||||
return ioutil.WriteFile(PreloadChecksumPath(k8sVersion, containerRuntime), checksum, 0o644)
|
||||
return os.WriteFile(PreloadChecksumPath(k8sVersion, containerRuntime), checksum, 0o644)
|
||||
}
|
||||
|
||||
// verifyChecksum returns true if the checksum of the local binary matches
|
||||
|
@ -253,13 +252,13 @@ func saveChecksumFile(k8sVersion, containerRuntime string, checksum []byte) erro
|
|||
func verifyChecksum(k8sVersion, containerRuntime, path string) error {
|
||||
klog.Infof("verifying checksumm of %s ...", path)
|
||||
// get md5 checksum of tarball path
|
||||
contents, err := ioutil.ReadFile(path)
|
||||
contents, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "reading tarball")
|
||||
}
|
||||
checksum := md5.Sum(contents)
|
||||
|
||||
remoteChecksum, err := ioutil.ReadFile(PreloadChecksumPath(k8sVersion, containerRuntime))
|
||||
remoteChecksum, err := os.ReadFile(PreloadChecksumPath(k8sVersion, containerRuntime))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "reading checksum file")
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package driver
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
@ -91,7 +90,7 @@ func TestFlagDefaults(t *testing.T) {
|
|||
t.Errorf("defaults mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
|
||||
tf, err := ioutil.TempFile("", "resolv.conf")
|
||||
tf, err := os.CreateTemp("", "resolv.conf")
|
||||
if err != nil {
|
||||
t.Fatalf("tempfile: %v", err)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -161,7 +160,7 @@ func shouldCheckFile(path string) bool {
|
|||
// inspectFile goes through the given file line by line looking for translatable strings
|
||||
func inspectFile(e *state) error {
|
||||
fset := token.NewFileSet()
|
||||
r, err := ioutil.ReadFile(e.filename)
|
||||
r, err := os.ReadFile(e.filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -451,7 +450,7 @@ func writeStringsToFiles(e *state, output string) error {
|
|||
}
|
||||
fmt.Printf("Writing to %s", filepath.Base(path))
|
||||
currentTranslations := make(map[string]interface{})
|
||||
f, err := ioutil.ReadFile(path)
|
||||
f, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "reading translation file")
|
||||
}
|
||||
|
@ -491,7 +490,7 @@ func writeStringsToFiles(e *state, output string) error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "marshalling translations")
|
||||
}
|
||||
err = ioutil.WriteFile(path, c, info.Mode())
|
||||
err = os.WriteFile(path, c, info.Mode())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "writing translation file")
|
||||
}
|
||||
|
@ -509,7 +508,7 @@ func writeStringsToFiles(e *state, output string) error {
|
|||
return errors.Wrap(err, "marshalling translations")
|
||||
}
|
||||
path := filepath.Join(output, "strings.txt")
|
||||
err = ioutil.WriteFile(path, c, 0644)
|
||||
err = os.WriteFile(path, c, 0644)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "writing translation file")
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package extract
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
@ -33,7 +32,7 @@ func TestExtract(t *testing.T) {
|
|||
// The function we care about
|
||||
functions := []string{"extract.PrintToScreen"}
|
||||
|
||||
tempdir, err := ioutil.TempDir("", "temptestdata")
|
||||
tempdir, err := os.MkdirTemp("", "temptestdata")
|
||||
if err != nil {
|
||||
t.Fatalf("Creating temp dir: %v", err)
|
||||
}
|
||||
|
@ -44,13 +43,13 @@ func TestExtract(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
src, err := ioutil.ReadFile("testdata/test.json")
|
||||
src, err := os.ReadFile("testdata/test.json")
|
||||
if err != nil {
|
||||
t.Fatalf("Reading json file: %v", err)
|
||||
}
|
||||
|
||||
tempfile := filepath.Join(tempdir, "tmpdata.json")
|
||||
err = ioutil.WriteFile(tempfile, src, 0666)
|
||||
err = os.WriteFile(tempfile, src, 0666)
|
||||
if err != nil {
|
||||
t.Fatalf("Writing temp json file: %v", err)
|
||||
}
|
||||
|
@ -68,7 +67,7 @@ func TestExtract(t *testing.T) {
|
|||
t.Fatalf("Error translating strings: %v", err)
|
||||
}
|
||||
|
||||
f, err := ioutil.ReadFile(tempfile)
|
||||
f, err := os.ReadFile(tempfile)
|
||||
if err != nil {
|
||||
t.Fatalf("Reading resulting json file: %v", err)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package image
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
@ -160,7 +159,7 @@ func saveToTarFile(iname, rawDest string, overwrite bool) error {
|
|||
|
||||
func writeImage(img v1.Image, dst string, ref name.Reference) error {
|
||||
klog.Infoln("opening: ", dst)
|
||||
f, err := ioutil.TempFile(filepath.Dir(dst), filepath.Base(dst)+".*.tmp")
|
||||
f, err := os.CreateTemp(filepath.Dir(dst), filepath.Base(dst)+".*.tmp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package image
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -289,7 +288,7 @@ func cleanImageCacheDir() error {
|
|||
return nil
|
||||
}
|
||||
// If directory is empty, delete it
|
||||
entries, err := ioutil.ReadDir(path)
|
||||
entries, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package kubeconfig
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
@ -50,7 +49,7 @@ func TestDeleteContext(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSetCurrentContext(t *testing.T) {
|
||||
f, err := ioutil.TempFile("/tmp", "kubeconfig")
|
||||
f, err := os.CreateTemp("/tmp", "kubeconfig")
|
||||
if err != nil {
|
||||
t.Fatalf("Error not expected but got %v", err)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package kubeconfig
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -201,7 +200,7 @@ func readOrNew(configPath ...string) (*api.Config, error) {
|
|||
fPath = configPath[0]
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(fPath)
|
||||
data, err := os.ReadFile(fPath)
|
||||
if os.IsNotExist(err) {
|
||||
return api.NewConfig(), nil
|
||||
} else if err != nil {
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package kubeconfig
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
@ -229,7 +228,7 @@ func TestUpdate(t *testing.T) {
|
|||
|
||||
for _, test := range tests {
|
||||
t.Run(test.description, func(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
tmpDir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
t.Fatalf("Error making temp directory %v", err)
|
||||
}
|
||||
|
@ -242,7 +241,7 @@ func TestUpdate(t *testing.T) {
|
|||
|
||||
test.cfg.SetPath(filepath.Join(tmpDir, "kubeconfig"))
|
||||
if len(test.existingCfg) != 0 {
|
||||
if err := ioutil.WriteFile(test.cfg.filePath(), test.existingCfg, 0600); err != nil {
|
||||
if err := os.WriteFile(test.cfg.filePath(), test.existingCfg, 0600); err != nil {
|
||||
t.Fatalf("WriteFile: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -460,7 +459,7 @@ func TestEmptyConfig(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewConfig(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", ".kube")
|
||||
dir, err := os.MkdirTemp("", ".kube")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -537,7 +536,7 @@ func Test_Endpoint(t *testing.T) {
|
|||
// tempFile creates a temporary with the provided bytes as its contents.
|
||||
// The caller is responsible for deleting file after use.
|
||||
func tempFile(t *testing.T, data []byte) string {
|
||||
tmp, err := ioutil.TempFile("", "kubeconfig")
|
||||
tmp, err := os.CreateTemp("", "kubeconfig")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
package kubeconfig
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync/atomic"
|
||||
|
||||
|
@ -83,7 +83,7 @@ func PopulateFromSettings(cfg *Settings, apiCfg *api.Config) error {
|
|||
cluster := api.NewCluster()
|
||||
cluster.Server = cfg.ClusterServerAddress
|
||||
if cfg.EmbedCerts {
|
||||
cluster.CertificateAuthorityData, err = ioutil.ReadFile(cfg.CertificateAuthority)
|
||||
cluster.CertificateAuthorityData, err = os.ReadFile(cfg.CertificateAuthority)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "reading CertificateAuthority %s", cfg.CertificateAuthority)
|
||||
}
|
||||
|
@ -100,11 +100,11 @@ func PopulateFromSettings(cfg *Settings, apiCfg *api.Config) error {
|
|||
userName := cfg.ClusterName
|
||||
user := api.NewAuthInfo()
|
||||
if cfg.EmbedCerts {
|
||||
user.ClientCertificateData, err = ioutil.ReadFile(cfg.ClientCertificate)
|
||||
user.ClientCertificateData, err = os.ReadFile(cfg.ClientCertificate)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "reading ClientCertificate %s", cfg.ClientCertificate)
|
||||
}
|
||||
user.ClientKeyData, err = ioutil.ReadFile(cfg.ClientKey)
|
||||
user.ClientKeyData, err = os.ReadFile(cfg.ClientKey)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "reading ClientKey %s", cfg.ClientKey)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package localpath
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -29,7 +28,7 @@ import (
|
|||
)
|
||||
|
||||
func TestReplaceWinDriveLetterToVolumeName(t *testing.T) {
|
||||
path, err := ioutil.TempDir("", "repwindl2vn")
|
||||
path, err := os.MkdirTemp("", "repwindl2vn")
|
||||
if err != nil {
|
||||
t.Fatalf("Error make tmp directory: %v", err)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package machine
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -89,7 +88,7 @@ func TestCacheBinariesForBootstrapper(t *testing.T) {
|
|||
oldMinikubeHome := os.Getenv("MINIKUBE_HOME")
|
||||
defer os.Setenv("MINIKUBE_HOME", oldMinikubeHome)
|
||||
|
||||
minikubeHome, err := ioutil.TempDir("/tmp", "")
|
||||
minikubeHome, err := os.MkdirTemp("/tmp", "")
|
||||
if err != nil {
|
||||
t.Fatalf("error during creating tmp dir: %v", err)
|
||||
}
|
||||
|
@ -148,7 +147,7 @@ func TestExcludedBinariesNotDownloaded(t *testing.T) {
|
|||
oldMinikubeHome := os.Getenv("MINIKUBE_HOME")
|
||||
defer os.Setenv("MINIKUBE_HOME", oldMinikubeHome)
|
||||
|
||||
minikubeHome, err := ioutil.TempDir("/tmp", "")
|
||||
minikubeHome, err := os.MkdirTemp("/tmp", "")
|
||||
if err != nil {
|
||||
t.Fatalf("error during creating tmp dir: %v", err)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ package machine
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -105,7 +105,7 @@ func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) {
|
|||
|
||||
// showLocalOsRelease shows systemd information about the current linux distribution, on the local host
|
||||
func showLocalOsRelease() {
|
||||
osReleaseOut, err := ioutil.ReadFile("/etc/os-release")
|
||||
osReleaseOut, err := os.ReadFile("/etc/os-release")
|
||||
if err != nil {
|
||||
klog.Errorf("ReadFile: %v", err)
|
||||
return
|
||||
|
|
|
@ -18,7 +18,6 @@ package machine
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
|
@ -67,7 +66,7 @@ func TestAddHostAliasInner(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
|
||||
buff, err := ioutil.ReadFile(tempFilePath)
|
||||
buff, err := os.ReadFile(tempFilePath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -81,7 +80,7 @@ func TestAddHostAliasInner(t *testing.T) {
|
|||
}
|
||||
|
||||
func writeContentToTempFile(content string) (string, error) {
|
||||
etcHosts, err := ioutil.TempFile("", "hosts")
|
||||
etcHosts, err := os.CreateTemp("", "hosts")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ package notify
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -185,7 +185,7 @@ func writeTimeToFile(path string, inputTime time.Time) error {
|
|||
}
|
||||
|
||||
func timeFromFileIfExists(path string) time.Time {
|
||||
lastUpdateCheckTime, err := ioutil.ReadFile(path)
|
||||
lastUpdateCheckTime, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return time.Time{}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package notify
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
@ -223,7 +222,7 @@ func TestMaybePrintUpdateText(t *testing.T) {
|
|||
viper.Set(config.WantBetaUpdateNotification, tt.wantBetaUpdateNotification)
|
||||
lastUpdateCheckFilePath = filepath.Join(tempDir, "last_update_check")
|
||||
|
||||
tmpfile, err := ioutil.TempFile("", "")
|
||||
tmpfile, err := os.CreateTemp("", "")
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot create temp file: %v", err)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import (
|
|||
"html"
|
||||
"html/template"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
@ -382,7 +381,7 @@ func displayError(msg string, err error) {
|
|||
|
||||
func latestLogFilePath() (string, error) {
|
||||
tmpdir := os.TempDir()
|
||||
files, err := ioutil.ReadDir(tmpdir)
|
||||
files, err := os.ReadDir(tmpdir)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get list of files in tempdir: %v", err)
|
||||
}
|
||||
|
@ -392,11 +391,15 @@ func latestLogFilePath() (string, error) {
|
|||
if !strings.Contains(file.Name(), "minikube_") {
|
||||
continue
|
||||
}
|
||||
if !lastModTime.IsZero() && lastModTime.After(file.ModTime()) {
|
||||
fileInfo, err := file.Info()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get file info: %v", err)
|
||||
}
|
||||
if !lastModTime.IsZero() && lastModTime.After(fileInfo.ModTime()) {
|
||||
continue
|
||||
}
|
||||
lastModName = file.Name()
|
||||
lastModTime = file.ModTime()
|
||||
lastModTime = fileInfo.ModTime()
|
||||
}
|
||||
fullPath := filepath.Join(tmpdir, lastModName)
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package schedule
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
@ -51,7 +50,7 @@ func KillExisting(profiles []string) {
|
|||
|
||||
func killPIDForProfile(profile string) error {
|
||||
file := localpath.PID(profile)
|
||||
f, err := ioutil.ReadFile(file)
|
||||
f, err := os.ReadFile(file)
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
|
@ -91,7 +90,7 @@ func daemonize(profiles []string, duration time.Duration) error {
|
|||
func savePIDs(pid int, profiles []string) error {
|
||||
for _, p := range profiles {
|
||||
file := localpath.PID(p)
|
||||
if err := ioutil.WriteFile(file, []byte(fmt.Sprintf("%v", pid)), 0600); err != nil {
|
||||
if err := os.WriteFile(file, []byte(fmt.Sprintf("%v", pid)), 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
@ -612,7 +611,7 @@ users:
|
|||
t.Run(test.description, func(t *testing.T) {
|
||||
mockK8sConfigByte := []byte(test.config)
|
||||
mockK8sConfigPath := test.kubeconfigPath
|
||||
err := ioutil.WriteFile(mockK8sConfigPath, mockK8sConfigByte, 0644)
|
||||
err := os.WriteFile(mockK8sConfigPath, mockK8sConfigByte, 0644)
|
||||
defer os.Remove(mockK8sConfigPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error when writing to file %v. Error: %v", test.kubeconfigPath, err)
|
||||
|
|
|
@ -19,7 +19,6 @@ package storageclass
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -229,7 +228,7 @@ func TestGetStoragev1(t *testing.T) {
|
|||
err: true,
|
||||
},
|
||||
}
|
||||
configFile, err := ioutil.TempFile("/tmp", "")
|
||||
configFile, err := os.CreateTemp("/tmp", "")
|
||||
if err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
|
@ -255,7 +254,7 @@ func TestGetStoragev1(t *testing.T) {
|
|||
func setK8SConfig(config, kubeconfigPath string) error {
|
||||
mockK8sConfigByte := []byte(config)
|
||||
mockK8sConfigPath := kubeconfigPath
|
||||
err := ioutil.WriteFile(mockK8sConfigPath, mockK8sConfigByte, 0644)
|
||||
err := os.WriteFile(mockK8sConfigPath, mockK8sConfigByte, 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unexpected error when writing to file %v. Error: %v", kubeconfigPath, err)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package tests
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -28,7 +27,7 @@ import (
|
|||
|
||||
// MakeTempDir creates the temp dir and returns the path
|
||||
func MakeTempDir() string {
|
||||
tempDir, err := ioutil.TempDir("", "minipath")
|
||||
tempDir, err := os.MkdirTemp("", "minipath")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ package tunnel
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -186,7 +186,7 @@ func (r *persistentRegistry) List() ([]*ID, error) {
|
|||
}
|
||||
return []*ID{}, nil
|
||||
}
|
||||
byteValue, _ := ioutil.ReadAll(f)
|
||||
byteValue, _ := io.ReadAll(f)
|
||||
var tunnels []*ID
|
||||
if len(byteValue) == 0 {
|
||||
return tunnels, nil
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package tunnel
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
@ -246,7 +245,7 @@ func TestTunnelTakeoverFromNonRunningProcess(t *testing.T) {
|
|||
|
||||
func tmpFile(t *testing.T) string {
|
||||
t.Helper()
|
||||
f, err := ioutil.TempFile(os.TempDir(), "reg_")
|
||||
f, err := os.CreateTemp(os.TempDir(), "reg_")
|
||||
f.Close()
|
||||
if err != nil {
|
||||
t.Errorf("failed to create temp file %s", err)
|
||||
|
@ -255,7 +254,7 @@ func tmpFile(t *testing.T) string {
|
|||
}
|
||||
|
||||
func createTestRegistry(t *testing.T) (reg *persistentRegistry, cleanup func()) {
|
||||
f, err := ioutil.TempFile(os.TempDir(), "reg_")
|
||||
f, err := os.CreateTemp(os.TempDir(), "reg_")
|
||||
f.Close()
|
||||
if err != nil {
|
||||
t.Errorf("failed to create temp file %s", err)
|
||||
|
|
|
@ -18,7 +18,6 @@ package tunnel
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -187,7 +186,7 @@ func writeResolverFile(route *Route) error {
|
|||
klog.Infof("preparing DNS forwarding config in %q:\n%s", resolverFile, content)
|
||||
|
||||
// write resolver content into tf, then copy it to /etc/resolver/clusterDomain
|
||||
tf, err := ioutil.TempFile("", "minikube-tunnel-resolver-")
|
||||
tf, err := os.CreateTemp("", "minikube-tunnel-resolver-")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "tempfile")
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import (
|
|||
"k8s.io/minikube/pkg/minikube/tests"
|
||||
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
@ -485,7 +484,7 @@ func TestErrorCreatingTunnel(t *testing.T) {
|
|||
e: errors.New("error loading machine"),
|
||||
}
|
||||
|
||||
f, err := ioutil.TempFile(os.TempDir(), "reg_")
|
||||
f, err := os.CreateTemp(os.TempDir(), "reg_")
|
||||
f.Close()
|
||||
if err != nil {
|
||||
t.Errorf("failed to create temp file %s", err)
|
||||
|
|
|
@ -23,7 +23,6 @@ import (
|
|||
"crypto/x509"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/pem"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"net"
|
||||
"os"
|
||||
|
@ -67,7 +66,7 @@ func GenerateCACert(certPath, keyPath string, name string) error {
|
|||
// GenerateSignedCert generates a signed certificate and key
|
||||
func GenerateSignedCert(certPath, keyPath, cn string, ips []net.IP, alternateDNS []string, signerCertPath, signerKeyPath string, expiration time.Duration) error {
|
||||
klog.Infof("Generating cert %s with IP's: %s", certPath, ips)
|
||||
signerCertBytes, err := ioutil.ReadFile(signerCertPath)
|
||||
signerCertBytes, err := os.ReadFile(signerCertPath)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error reading file: signerCertPath")
|
||||
}
|
||||
|
@ -79,7 +78,7 @@ func GenerateSignedCert(certPath, keyPath, cn string, ips []net.IP, alternateDNS
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "Error parsing certificate: decodedSignerCert.Bytes")
|
||||
}
|
||||
signerKeyBytes, err := ioutil.ReadFile(signerKeyPath)
|
||||
signerKeyBytes, err := os.ReadFile(signerKeyPath)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error reading file: signerKeyPath")
|
||||
}
|
||||
|
@ -118,7 +117,7 @@ func GenerateSignedCert(certPath, keyPath, cn string, ips []net.IP, alternateDNS
|
|||
}
|
||||
|
||||
func loadOrGeneratePrivateKey(keyPath string) (*rsa.PrivateKey, error) {
|
||||
keyBytes, err := ioutil.ReadFile(keyPath)
|
||||
keyBytes, err := os.ReadFile(keyPath)
|
||||
if err == nil {
|
||||
decodedKey, _ := pem.Decode(keyBytes)
|
||||
if decodedKey != nil {
|
||||
|
|
|
@ -19,7 +19,6 @@ package util
|
|||
import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -29,7 +28,7 @@ import (
|
|||
)
|
||||
|
||||
func TestGenerateCACert(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
tmpDir, err := os.MkdirTemp("", "")
|
||||
defer func() { // clean up tempdir
|
||||
err := os.RemoveAll(tmpDir)
|
||||
if err != nil {
|
||||
|
@ -47,7 +46,7 @@ func TestGenerateCACert(t *testing.T) {
|
|||
}
|
||||
|
||||
// Check the cert has the right shape.
|
||||
certBytes, err := ioutil.ReadFile(certPath)
|
||||
certBytes, err := os.ReadFile(certPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Error reading cert data: %v", err)
|
||||
}
|
||||
|
@ -62,7 +61,7 @@ func TestGenerateCACert(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGenerateSignedCert(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
tmpDir, err := os.MkdirTemp("", "")
|
||||
defer func() { // clean up tempdir
|
||||
err := os.RemoveAll(tmpDir)
|
||||
if err != nil {
|
||||
|
@ -73,7 +72,7 @@ func TestGenerateSignedCert(t *testing.T) {
|
|||
t.Fatalf("Error generating tmpdir: %v", err)
|
||||
}
|
||||
|
||||
signerTmpDir, err := ioutil.TempDir("", "")
|
||||
signerTmpDir, err := os.MkdirTemp("", "")
|
||||
defer func() { // clean up tempdir
|
||||
err := os.RemoveAll(signerTmpDir)
|
||||
if err != nil {
|
||||
|
@ -149,7 +148,7 @@ func TestGenerateSignedCert(t *testing.T) {
|
|||
t.Errorf("GenerateSignedCert() should have returned error, but didn't")
|
||||
}
|
||||
if err == nil {
|
||||
certBytes, err := ioutil.ReadFile(certPath)
|
||||
certBytes, err := os.ReadFile(certPath)
|
||||
if err != nil {
|
||||
t.Errorf("Error reading cert data: %v", err)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package lock
|
|||
import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
|
@ -30,7 +29,7 @@ import (
|
|||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// WriteFile decorates ioutil.WriteFile with a file lock and retry
|
||||
// WriteFile decorates os.WriteFile with a file lock and retry
|
||||
func WriteFile(filename string, data []byte, perm os.FileMode) error {
|
||||
spec := PathMutexSpec(filename)
|
||||
klog.Infof("WriteFile acquiring %s: %+v", filename, spec)
|
||||
|
@ -41,7 +40,7 @@ func WriteFile(filename string, data []byte, perm os.FileMode) error {
|
|||
|
||||
defer releaser.Release()
|
||||
|
||||
return ioutil.WriteFile(filename, data, perm)
|
||||
return os.WriteFile(filename, data, perm)
|
||||
}
|
||||
|
||||
// PathMutexSpec returns a mutex spec for a path
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package util
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/user"
|
||||
"runtime"
|
||||
|
@ -81,7 +80,7 @@ func TestParseKubernetesVersion(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestChownR(t *testing.T) {
|
||||
testDir, err := ioutil.TempDir(os.TempDir(), "")
|
||||
testDir, err := os.MkdirTemp(os.TempDir(), "")
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
@ -134,7 +133,7 @@ func TestChownR(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMaybeChownDirRecursiveToMinikubeUser(t *testing.T) {
|
||||
testDir, err := ioutil.TempDir(os.TempDir(), "")
|
||||
testDir, err := os.MkdirTemp(os.TempDir(), "")
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import (
|
|||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
@ -230,7 +229,7 @@ func TestDownloadOnlyKic(t *testing.T) {
|
|||
|
||||
// Make sure the downloaded image tarball exists
|
||||
tarball := download.TarballPath(constants.DefaultKubernetesVersion, cRuntime)
|
||||
contents, err := ioutil.ReadFile(tarball)
|
||||
contents, err := os.ReadFile(tarball)
|
||||
if err != nil {
|
||||
t.Errorf("failed to read tarball file %q: %v", tarball, err)
|
||||
}
|
||||
|
@ -240,7 +239,7 @@ func TestDownloadOnlyKic(t *testing.T) {
|
|||
}
|
||||
// Make sure it has the correct checksum
|
||||
checksum := md5.Sum(contents)
|
||||
remoteChecksum, err := ioutil.ReadFile(download.PreloadChecksumPath(constants.DefaultKubernetesVersion, cRuntime))
|
||||
remoteChecksum, err := os.ReadFile(download.PreloadChecksumPath(constants.DefaultKubernetesVersion, cRuntime))
|
||||
if err != nil {
|
||||
t.Errorf("failed to read checksum file %q : %v", download.PreloadChecksumPath(constants.DefaultKubernetesVersion, cRuntime), err)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package integration
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
@ -60,7 +59,7 @@ func TestKVMDriverInstallOrUpdate(t *testing.T) {
|
|||
defer os.Setenv("PATH", originalPath)
|
||||
|
||||
for _, tc := range tests {
|
||||
dir, err := ioutil.TempDir("", tc.name)
|
||||
dir, err := os.MkdirTemp("", tc.name)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected to create tempdir. test: %s, got: %v", tc.name, err)
|
||||
}
|
||||
|
@ -129,7 +128,7 @@ func TestHyperKitDriverInstallOrUpdate(t *testing.T) {
|
|||
defer os.Setenv("PATH", originalPath)
|
||||
|
||||
for _, tc := range tests {
|
||||
dir, err := ioutil.TempDir("", tc.name)
|
||||
dir, err := os.MkdirTemp("", tc.name)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected to create tempdir. test: %s, got: %v", tc.name, err)
|
||||
}
|
||||
|
@ -267,7 +266,7 @@ func driverVersion(path string) (string, error) {
|
|||
// prepareTempMinikubeDirWithHyperkitDriver creates a temp .minikube directory
|
||||
// with structure essential to testing of hyperkit driver updates
|
||||
func prepareTempMinikubeDirWithHyperkitDriver(name, driver string) (string, string, error) {
|
||||
temp, err := ioutil.TempDir("", name)
|
||||
temp, err := os.MkdirTemp("", name)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("failed to create tempdir: %v", err)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -825,7 +825,7 @@ func validateDashboardCmd(ctx context.Context, t *testing.T, profile string) {
|
|||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Errorf("failed to read http response body from dashboard %q: %v", u.String(), err)
|
||||
}
|
||||
|
@ -940,13 +940,13 @@ func validateCacheCmd(ctx context.Context, t *testing.T, profile string) {
|
|||
t.Skipf("docker is not installed, skipping local image test")
|
||||
}
|
||||
|
||||
dname, err := ioutil.TempDir("", profile)
|
||||
dname, err := os.MkdirTemp("", profile)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot create temp dir: %v", err)
|
||||
}
|
||||
|
||||
message := []byte("FROM scratch\nADD Dockerfile /x")
|
||||
err = ioutil.WriteFile(filepath.Join(dname, "Dockerfile"), message, 0644)
|
||||
err = os.WriteFile(filepath.Join(dname, "Dockerfile"), message, 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to write Dockerfile: %v", err)
|
||||
}
|
||||
|
@ -1116,7 +1116,7 @@ func validateLogsCmd(ctx context.Context, t *testing.T, profile string) {
|
|||
|
||||
// validateLogsFileCmd asserts "logs --file" command functionality
|
||||
func validateLogsFileCmd(ctx context.Context, t *testing.T, profile string) {
|
||||
dname, err := ioutil.TempDir("", profile)
|
||||
dname, err := os.MkdirTemp("", profile)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot create temp dir: %v", err)
|
||||
}
|
||||
|
@ -1130,7 +1130,7 @@ func validateLogsFileCmd(ctx context.Context, t *testing.T, profile string) {
|
|||
t.Errorf("expected empty minikube logs output, but got: \n***%s***\n", rr.Output())
|
||||
}
|
||||
|
||||
logs, err := ioutil.ReadFile(logFileName)
|
||||
logs, err := os.ReadFile(logFileName)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to read logs output '%s': %v", logFileName, err)
|
||||
}
|
||||
|
@ -1383,7 +1383,7 @@ func validateServiceCmd(ctx context.Context, t *testing.T, profile string) {
|
|||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Logf("error reading body from %s: %v", endpoint, err)
|
||||
return err
|
||||
|
@ -1628,7 +1628,7 @@ func validateFileSync(ctx context.Context, t *testing.T, profile string) {
|
|||
t.Logf("file sync test content: %s", got)
|
||||
|
||||
syncFile := filepath.Join(*testdataDir, "sync.test")
|
||||
expected, err := ioutil.ReadFile(syncFile)
|
||||
expected, err := os.ReadFile(syncFile)
|
||||
if err != nil {
|
||||
t.Errorf("failed to read test file 'testdata/sync.test' : %v", err)
|
||||
}
|
||||
|
@ -1647,7 +1647,7 @@ func validateCertSync(ctx context.Context, t *testing.T, profile string) {
|
|||
}
|
||||
|
||||
testPem := filepath.Join(*testdataDir, "minikube_test.pem")
|
||||
want, err := ioutil.ReadFile(testPem)
|
||||
want, err := os.ReadFile(testPem)
|
||||
if err != nil {
|
||||
t.Errorf("test file not found: %v", err)
|
||||
}
|
||||
|
@ -1674,7 +1674,7 @@ func validateCertSync(ctx context.Context, t *testing.T, profile string) {
|
|||
}
|
||||
|
||||
testPem2 := filepath.Join(*testdataDir, "minikube_test2.pem")
|
||||
want, err = ioutil.ReadFile(testPem2)
|
||||
want, err = os.ReadFile(testPem2)
|
||||
if err != nil {
|
||||
t.Errorf("test file not found: %v", err)
|
||||
}
|
||||
|
@ -1791,12 +1791,12 @@ users:
|
|||
t.Parallel()
|
||||
c := exec.CommandContext(ctx, Target(), "-p", profile, "update-context", "--alsologtostderr", "-v=2")
|
||||
if tc.kubeconfig != nil {
|
||||
tf, err := ioutil.TempFile("", "kubeconfig")
|
||||
tf, err := os.CreateTemp("", "kubeconfig")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(tf.Name(), tc.kubeconfig, 0644); err != nil {
|
||||
if err := os.WriteFile(tf.Name(), tc.kubeconfig, 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
|
@ -1832,7 +1832,7 @@ func startProxyWithCustomCerts(ctx context.Context, t *testing.T) error {
|
|||
}
|
||||
}()
|
||||
|
||||
mitmDir, err := ioutil.TempDir("", "")
|
||||
mitmDir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "create temp dir")
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
|
@ -60,7 +59,7 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) { // no
|
|||
}
|
||||
|
||||
t.Run("any-port", func(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "mounttest")
|
||||
tempDir, err := os.MkdirTemp("", "mounttest")
|
||||
defer func() { // clean up tempdir
|
||||
err := os.RemoveAll(tempDir)
|
||||
if err != nil {
|
||||
|
@ -107,7 +106,7 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) { // no
|
|||
wantFromTest := []byte(testMarker)
|
||||
for _, name := range []string{createdByTest, createdByTestRemovedByPod, testMarker} {
|
||||
p := filepath.Join(tempDir, name)
|
||||
err := ioutil.WriteFile(p, wantFromTest, 0644)
|
||||
err := os.WriteFile(p, wantFromTest, 0644)
|
||||
t.Logf("wrote %q to %s", wantFromTest, p)
|
||||
if err != nil {
|
||||
t.Errorf("WriteFile %s: %v", p, err)
|
||||
|
@ -160,7 +159,7 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) { // no
|
|||
|
||||
// Read the file written by pod startup
|
||||
p := filepath.Join(tempDir, createdByPod)
|
||||
got, err := ioutil.ReadFile(p)
|
||||
got, err := os.ReadFile(p)
|
||||
if err != nil {
|
||||
t.Errorf("failed to read file created by pod %q: %v", p, err)
|
||||
}
|
||||
|
@ -209,7 +208,7 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) { // no
|
|||
}
|
||||
})
|
||||
t.Run("specific-port", func(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "mounttest")
|
||||
tempDir, err := os.MkdirTemp("", "mounttest")
|
||||
defer func() { // clean up tempdir
|
||||
err := os.RemoveAll(tempDir)
|
||||
if err != nil {
|
||||
|
|
|
@ -22,7 +22,7 @@ package integration
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
|
@ -211,7 +211,7 @@ func validateAccessDirect(ctx context.Context, t *testing.T, profile string) {
|
|||
return &retry.RetriableError{Err: fmt.Errorf("no body")}
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
got, err = ioutil.ReadAll(resp.Body)
|
||||
got, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return &retry.RetriableError{Err: err}
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ func validateAccessDNS(ctx context.Context, t *testing.T, profile string) {
|
|||
return &retry.RetriableError{Err: fmt.Errorf("no body")}
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
got, err = ioutil.ReadAll(resp.Body)
|
||||
got, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return &retry.RetriableError{Err: err}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
@ -153,14 +152,14 @@ func (ss *StartSession) Stop(t *testing.T) {
|
|||
killProcessFamily(t, ss.cmd.Process.Pid)
|
||||
if t.Failed() {
|
||||
if ss.Stdout.Size() > 0 {
|
||||
stdout, err := ioutil.ReadAll(ss.Stdout)
|
||||
stdout, err := io.ReadAll(ss.Stdout)
|
||||
if err != nil {
|
||||
t.Logf("read stdout failed: %v", err)
|
||||
}
|
||||
t.Logf("(dbg) %s stdout:\n%s", ss.cmd.Args, stdout)
|
||||
}
|
||||
if ss.Stderr.Size() > 0 {
|
||||
stderr, err := ioutil.ReadAll(ss.Stderr)
|
||||
stderr, err := io.ReadAll(ss.Stderr)
|
||||
if err != nil {
|
||||
t.Logf("read stderr failed: %v", err)
|
||||
}
|
||||
|
@ -554,7 +553,7 @@ func testCpCmd(ctx context.Context, t *testing.T, profile string, node string) {
|
|||
t.Errorf("failed to run an cp command. args %q : %v", rr.Command(), err)
|
||||
}
|
||||
|
||||
expected, err := ioutil.ReadFile(srcPath)
|
||||
expected, err := os.ReadFile(srcPath)
|
||||
if err != nil {
|
||||
t.Errorf("failed to read test file 'testdata/cp-test.txt' : %v", err)
|
||||
}
|
||||
|
@ -644,14 +643,18 @@ func CopyDir(src, dst string) error {
|
|||
|
||||
// get the collection of directory entries under src.
|
||||
// for each entry build its corresponding path under dst.
|
||||
entries, err := ioutil.ReadDir(src)
|
||||
entries, err := os.ReadDir(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
// skip symlinks
|
||||
if entry.Mode()&os.ModeSymlink != 0 {
|
||||
entryInfo, err := entry.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if entryInfo.Mode()&os.ModeSymlink != 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ package integration
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
@ -146,7 +145,7 @@ func checkPID(t *testing.T, profile string) string {
|
|||
var contents []byte
|
||||
getContents := func() error {
|
||||
var err error
|
||||
contents, err = ioutil.ReadFile(file)
|
||||
contents, err = os.ReadFile(file)
|
||||
return err
|
||||
}
|
||||
// first, make sure the PID file exists
|
||||
|
|
|
@ -22,7 +22,6 @@ package integration
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
@ -122,7 +121,7 @@ func TestSkaffold(t *testing.T) {
|
|||
|
||||
// installSkaffold installs the latest release of skaffold
|
||||
func installSkaffold() (f *os.File, err error) {
|
||||
tf, err := ioutil.TempFile("", "skaffold.exe")
|
||||
tf, err := os.CreateTemp("", "skaffold.exe")
|
||||
if err != nil {
|
||||
return tf, err
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
@ -37,7 +36,7 @@ import (
|
|||
)
|
||||
|
||||
func installRelease(version string) (f *os.File, err error) {
|
||||
tf, err := ioutil.TempFile("", fmt.Sprintf("minikube-%s.*.exe", version))
|
||||
tf, err := os.CreateTemp("", fmt.Sprintf("minikube-%s.*.exe", version))
|
||||
if err != nil {
|
||||
return tf, err
|
||||
}
|
||||
|
@ -117,7 +116,7 @@ func TestRunningBinaryUpgrade(t *testing.T) {
|
|||
}
|
||||
}
|
||||
// using a fresh kubeconfig for this test
|
||||
legacyKubeConfig, err := ioutil.TempFile("", "legacy_kubeconfig")
|
||||
legacyKubeConfig, err := os.CreateTemp("", "legacy_kubeconfig")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temp file for legacy kubeconfig %v", err)
|
||||
}
|
||||
|
@ -176,7 +175,7 @@ func TestStoppedBinaryUpgrade(t *testing.T) {
|
|||
}
|
||||
}
|
||||
// using a fresh kubeconfig for this test
|
||||
legacyKubeConfig, err := ioutil.TempFile("", "legacy_kubeconfig")
|
||||
legacyKubeConfig, err := os.CreateTemp("", "legacy_kubeconfig")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temp file for legacy kubeconfig %v", err)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ package docker
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -112,7 +111,7 @@ func validateContextDirectory(srcPath string, excludes []string) error {
|
|||
|
||||
func parseDockerignore(root string) ([]string, error) {
|
||||
var excludes []string
|
||||
ignore, err := ioutil.ReadFile(path.Join(root, ".dockerignore"))
|
||||
ignore, err := os.ReadFile(path.Join(root, ".dockerignore"))
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return excludes, fmt.Errorf("error reading .dockerignore: %w", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue