From 0c9766d8dbeff4c1ac5975da8992cec25a21616c Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Thu, 17 Nov 2022 12:33:35 +0300 Subject: [PATCH] Removed deprecated function calls --- selenoid/docker.go | 9 ++++----- selenoid/docker_test.go | 3 +-- selenoid/drivers.go | 5 ++--- selenoid/drivers_test.go | 9 ++++----- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/selenoid/docker.go b/selenoid/docker.go index aa11eae..5eaac53 100644 --- a/selenoid/docker.go +++ b/selenoid/docker.go @@ -7,7 +7,6 @@ import ( "fmt" "github.com/docker/docker/api" "github.com/docker/go-units" - "io/ioutil" "log" "sort" @@ -114,7 +113,7 @@ func NewDockerConfigurator(config *LifecycleConfig) (*DockerConfigurator, error) } if c.Quiet { log.SetFlags(0) - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) } err := c.initDockerClient() if err != nil { @@ -389,12 +388,12 @@ func (c *DockerConfigurator) Configure() (*SelenoidConfig, error) { if err != nil { return nil, fmt.Errorf("failed to marshal json: %v", err) } - return &cfg, ioutil.WriteFile(getSelenoidConfigPath(c.ConfigDir), data, 0644) + return &cfg, os.WriteFile(getSelenoidConfigPath(c.ConfigDir), data, 0644) } func (c *DockerConfigurator) syncWithConfig() (*SelenoidConfig, error) { c.Titlef(`Requested to sync configuration from "%v"...`, color.GreenString(c.BrowsersJson)) - data, err := ioutil.ReadFile(c.BrowsersJson) + data, err := os.ReadFile(c.BrowsersJson) if err != nil { return nil, fmt.Errorf("failed to read browsers.json from %s: %v", c.BrowsersJson, err) } @@ -418,7 +417,7 @@ func (c *DockerConfigurator) syncWithConfig() (*SelenoidConfig, error) { } c.pullVideoRecorderImage() } - return &cfg, ioutil.WriteFile(getSelenoidConfigPath(c.ConfigDir), data, 0644) + return &cfg, os.WriteFile(getSelenoidConfigPath(c.ConfigDir), data, 0644) } func (c *DockerConfigurator) createConfig() SelenoidConfig { diff --git a/selenoid/docker_test.go b/selenoid/docker_test.go index a2385c0..e4cfdd5 100644 --- a/selenoid/docker_test.go +++ b/selenoid/docker_test.go @@ -6,7 +6,6 @@ import ( . "github.com/aandryashin/matchers" "github.com/aerokube/selenoid/config" "github.com/docker/docker/api/types" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -431,7 +430,7 @@ func TestSyncWithConfig(t *testing.T) { initialCfgFile := filepath.Join(dir, "initial-browsers.json") data, _ := json.Marshal(initialCfg) - ioutil.WriteFile(initialCfgFile, data, 0644) + os.WriteFile(initialCfgFile, data, 0644) lcConfig := LifecycleConfig{ ConfigDir: dir, diff --git a/selenoid/drivers.go b/selenoid/drivers.go index e8663a9..a46e289 100644 --- a/selenoid/drivers.go +++ b/selenoid/drivers.go @@ -16,7 +16,6 @@ import ( "github.com/mitchellh/go-ps" "gopkg.in/cheggaaa/pb.v1" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -285,7 +284,7 @@ func (d *DriversConfigurator) Configure() (*SelenoidConfig, error) { if err != nil { return &cfg, fmt.Errorf("failed to marshal json: %v", err) } - return &cfg, ioutil.WriteFile(getSelenoidConfigPath(d.ConfigDir), data, 0644) + return &cfg, os.WriteFile(getSelenoidConfigPath(d.ConfigDir), data, 0644) } func (d *DriversConfigurator) generateConfig(downloadedDrivers []downloadedDriver) SelenoidConfig { @@ -406,7 +405,7 @@ func extractFile(data []byte, filename string, outputDir string) (string, error) return untar(data, filename, outputDir) } else { outputPath := filepath.Join(outputDir, filename) - err := ioutil.WriteFile(outputPath, data, os.ModePerm) + err := os.WriteFile(outputPath, data, os.ModePerm) if err != nil { return "", fmt.Errorf("failed to save file %s: %v", outputPath, err) } diff --git a/selenoid/drivers_test.go b/selenoid/drivers_test.go index 9559c78..e142c45 100644 --- a/selenoid/drivers_test.go +++ b/selenoid/drivers_test.go @@ -6,7 +6,6 @@ import ( . "github.com/aandryashin/matchers" "github.com/aerokube/selenoid/config" "github.com/google/go-github/github" - "io/ioutil" "net/http" "net/http/httptest" "net/url" @@ -276,7 +275,7 @@ func testUnpack(t *testing.T, data []byte, fileName string, fn func([]byte, stri } func readFile(t *testing.T, fileName string) []byte { - data, err := ioutil.ReadFile(fileName) + data, err := os.ReadFile(fileName) if err != nil { t.Fatal(err) } @@ -299,7 +298,7 @@ func mockServerUrl(mockServer *httptest.Server, relativeUrl string) string { } func withTmpDir(t *testing.T, prefix string, fn func(*testing.T, string)) { - dir, err := ioutil.TempDir("", prefix) + dir, err := os.MkdirTemp("", prefix) if err != nil { t.Fatal(err) } @@ -365,7 +364,7 @@ func checkContentsEqual(t *testing.T, outputPath string, expectedFileContents st if !fileExists(outputPath) { t.Fatalf("release was not downloaded to %s: file does not exist\n", outputPath) } - data, err := ioutil.ReadFile(outputPath) + data, err := os.ReadFile(outputPath) AssertThat(t, err, Is{nil}) AssertThat(t, string(data), EqualTo{expectedFileContents}) @@ -418,7 +417,7 @@ func TestWrongBaseUrl(t *testing.T) { }) } -//Based on https://npf.io/2015/06/testing-exec-command/ +// Based on https://npf.io/2015/06/testing-exec-command/ func TestStartStopProcess(t *testing.T) { execCommand = fakeExecCommand defer func() {