From 0215361b52d4369a388610e98fd0edffcd93eec0 Mon Sep 17 00:00:00 2001 From: Erik Seliger Date: Fri, 3 Sep 2021 12:15:14 +0200 Subject: [PATCH] Fix ioutil rule in golangci-lint --- .golangci.yml | 2 +- cmd/src/api.go | 4 ++-- cmd/src/batch_common.go | 3 +-- cmd/src/config_edit.go | 4 ++-- cmd/src/extensions_copy.go | 4 ++-- cmd/src/extensions_publish.go | 9 ++++----- cmd/src/extsvc_edit.go | 6 +++--- cmd/src/login.go | 3 +-- cmd/src/login_test.go | 4 ++-- cmd/src/main.go | 3 +-- cmd/src/main_test.go | 5 ++--- cmd/src/search_stream_test.go | 6 +++--- cmd/src/search_test.go | 9 ++++----- cmd/src/servegit.go | 4 ++-- cmd/src/validate.go | 14 +++++++------- cmd/src/version.go | 4 ++-- internal/api/api.go | 3 +-- internal/api/gzip_test.go | 6 +++--- internal/batches/executor/execution_cache.go | 6 +++--- internal/batches/executor/execution_cache_test.go | 3 +-- internal/batches/executor/executor_test.go | 5 ++--- internal/batches/executor/run_steps.go | 9 ++++----- internal/batches/log/task_logger.go | 3 +-- internal/batches/repozip/fetcher_test.go | 5 ++--- internal/batches/workspace/bind_workspace.go | 5 ++--- internal/batches/workspace/bind_workspace_test.go | 13 ++++++------- internal/batches/workspace/volume_workspace.go | 3 +-- .../batches/workspace/volume_workspace_test.go | 5 ++--- internal/exec/expect/expect.go | 5 ++--- internal/servegit/serve_test.go | 14 +++++++------- 30 files changed, 76 insertions(+), 93 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 49f4ea5eba..159d867086 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,7 +22,7 @@ linters-settings: packages-with-error-message: - errors: 'Use github.com/cockroachdb/errors instead' - github.com/pkg/errors: 'Use github.com/cockroachdb/errors instead' - - ioutil: 'The ioutil package has been deprecated' + - io/ioutil: 'The ioutil package has been deprecated' gocritic: disabled-checks: - appendAssign # Too many false positives diff --git a/cmd/src/api.go b/cmd/src/api.go index f2e3a4f2e6..0dd1b73b77 100644 --- a/cmd/src/api.go +++ b/cmd/src/api.go @@ -5,7 +5,7 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" + "io" "os" "strings" @@ -68,7 +68,7 @@ Examples: if isatty.IsTerminal(os.Stdin.Fd()) { return cmderrors.Usage("expected query to be piped into 'src api' or -query flag to be specified") } - data, err := ioutil.ReadAll(os.Stdin) + data, err := io.ReadAll(os.Stdin) if err != nil { return err } diff --git a/cmd/src/batch_common.go b/cmd/src/batch_common.go index 1fd346e0f1..9cb220ec55 100644 --- a/cmd/src/batch_common.go +++ b/cmd/src/batch_common.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "os" "os/exec" "os/signal" @@ -374,7 +373,7 @@ func parseBatchSpec(file *string, svc *service.Service) (*batcheslib.BatchSpec, } defer f.Close() - data, err := ioutil.ReadAll(f) + data, err := io.ReadAll(f) if err != nil { return nil, "", errors.Wrap(err, "reading batch spec") } diff --git a/cmd/src/config_edit.go b/cmd/src/config_edit.go index d06711457f..4a7c65380b 100644 --- a/cmd/src/config_edit.go +++ b/cmd/src/config_edit.go @@ -4,7 +4,7 @@ import ( "context" "flag" "fmt" - "io/ioutil" + "os" "github.com/sourcegraph/src-cli/internal/api" "github.com/sourcegraph/src-cli/internal/cmderrors" @@ -71,7 +71,7 @@ Examples: if *valueFlag != "" { value = *valueFlag } else if *valueFileFlag != "" { - data, err := ioutil.ReadFile(*valueFileFlag) + data, err := os.ReadFile(*valueFileFlag) if err != nil { return err } diff --git a/cmd/src/extensions_copy.go b/cmd/src/extensions_copy.go index 526be189e3..45cb3441a3 100644 --- a/cmd/src/extensions_copy.go +++ b/cmd/src/extensions_copy.go @@ -4,7 +4,7 @@ import ( "context" "flag" "fmt" - "io/ioutil" + "io" "net/http" "strings" @@ -106,7 +106,7 @@ Copy an extension from Sourcegraph.com to your private registry. return err } defer response.Body.Close() - bundle, err := ioutil.ReadAll(response.Body) + bundle, err := io.ReadAll(response.Body) if err != nil { return err } diff --git a/cmd/src/extensions_publish.go b/cmd/src/extensions_publish.go index 36a3ac94e2..0c1d7819c7 100644 --- a/cmd/src/extensions_publish.go +++ b/cmd/src/extensions_publish.go @@ -5,7 +5,6 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -67,7 +66,7 @@ Notes: } manifestDir := filepath.Dir(manifestPath) - manifest, err := ioutil.ReadFile(manifestPath) + manifest, err := os.ReadFile(manifestPath) if err != nil { return fmt.Errorf("%s\n\nRun this command in a directory with a %s file for an extension.\n\nSee 'src extensions %s -h' for help", err, *manifestFlag, flagSet.Name()) } @@ -256,7 +255,7 @@ func addReadmeToManifest(manifest []byte, dir string) ([]byte, error) { var readme string filenames := []string{"README.md", "README.txt", "README", "readme.md", "readme.txt", "readme", "Readme.md", "Readme.txt", "Readme"} for _, f := range filenames { - data, err := ioutil.ReadFile(filepath.Join(dir, f)) + data, err := os.ReadFile(filepath.Join(dir, f)) if err != nil { continue } @@ -292,7 +291,7 @@ func readExtensionArtifacts(manifest []byte, dir string) (bundle, sourceMap *str mainPath := filepath.Join(dir, o.Main) - data, err := ioutil.ReadFile(mainPath) + data, err := os.ReadFile(mainPath) if err != nil { return nil, nil, fmt.Errorf(`extension manifest "main" bundle file: %s`, err) } @@ -303,7 +302,7 @@ func readExtensionArtifacts(manifest []byte, dir string) (bundle, sourceMap *str // Guess that source map is the main file with a ".map" extension. sourceMapPath := strings.TrimSuffix(mainPath, filepath.Ext(mainPath)) + ".map" - data, err = ioutil.ReadFile(sourceMapPath) + data, err = os.ReadFile(sourceMapPath) if err == nil { tmp := string(data) sourceMap = &tmp diff --git a/cmd/src/extsvc_edit.go b/cmd/src/extsvc_edit.go index d29a7bcda7..dd420fa27d 100644 --- a/cmd/src/extsvc_edit.go +++ b/cmd/src/extsvc_edit.go @@ -5,7 +5,7 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" + "io" "os" "strings" @@ -73,14 +73,14 @@ Examples: // Determine if we are updating the JSON configuration or not. var updateJSON []byte if len(flagSet.Args()) == 1 { - updateJSON, err = ioutil.ReadFile(flagSet.Arg(0)) + updateJSON, err = os.ReadFile(flagSet.Arg(0)) if err != nil { return err } } if !isatty.IsTerminal(os.Stdin.Fd()) { // stdin is a pipe not a terminal - updateJSON, err = ioutil.ReadAll(os.Stdin) + updateJSON, err = io.ReadAll(os.Stdin) if err != nil { return err } diff --git a/cmd/src/login.go b/cmd/src/login.go index e8d29bb0f2..82d4168c60 100644 --- a/cmd/src/login.go +++ b/cmd/src/login.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "os" "strings" @@ -53,7 +52,7 @@ Examples: return cmderrors.Usage("expected exactly one argument: the Sourcegraph URL, or SRC_ENDPOINT to be set") } - client := cfg.apiClient(apiFlags, ioutil.Discard) + client := cfg.apiClient(apiFlags, io.Discard) return loginCmd(context.Background(), cfg, client, endpoint, os.Stdout) } diff --git a/cmd/src/login_test.go b/cmd/src/login_test.go index 7ae87c03bc..e2b8beeeea 100644 --- a/cmd/src/login_test.go +++ b/cmd/src/login_test.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "strings" @@ -18,7 +18,7 @@ func TestLogin(t *testing.T) { t.Helper() var out bytes.Buffer - err = loginCmd(context.Background(), cfg, cfg.apiClient(nil, ioutil.Discard), endpointArg, &out) + err = loginCmd(context.Background(), cfg, cfg.apiClient(nil, io.Discard), endpointArg, &out) return strings.TrimSpace(out.String()), err } diff --git a/cmd/src/main.go b/cmd/src/main.go index 7f21386579..e7fff11d8f 100644 --- a/cmd/src/main.go +++ b/cmd/src/main.go @@ -4,7 +4,6 @@ import ( "encoding/json" "flag" "io" - "io/ioutil" "log" "os" "os/user" @@ -114,7 +113,7 @@ func readConfig() (*config, error) { } else if strings.HasPrefix(cfgPath, "~/") { cfgPath = filepath.Join(homeDir, cfgPath[2:]) } - data, err := ioutil.ReadFile(os.ExpandEnv(cfgPath)) + data, err := os.ReadFile(os.ExpandEnv(cfgPath)) if err != nil && (!os.IsNotExist(err) || userSpecified) { return nil, err } diff --git a/cmd/src/main_test.go b/cmd/src/main_test.go index b36766d014..813ff220f1 100644 --- a/cmd/src/main_test.go +++ b/cmd/src/main_test.go @@ -2,7 +2,6 @@ package main import ( "encoding/json" - "io/ioutil" "os" "path/filepath" "testing" @@ -154,7 +153,7 @@ func TestReadConfig(t *testing.T) { setEnv("SRC_ACCESS_TOKEN", test.envToken) setEnv("SRC_ENDPOINT", test.envEndpoint) - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -176,7 +175,7 @@ func TestReadConfig(t *testing.T) { t.Fatal(err) } filePath := filepath.Join(tmpDir, "config.json") - err = ioutil.WriteFile(filePath, data, 0600) + err = os.WriteFile(filePath, data, 0600) if err != nil { t.Fatal(err) } diff --git a/cmd/src/search_stream_test.go b/cmd/src/search_stream_test.go index e053dd8db4..8d55dee145 100644 --- a/cmd/src/search_stream_test.go +++ b/cmd/src/search_stream_test.go @@ -2,7 +2,7 @@ package main import ( "flag" - "io/ioutil" + "io" "net" "net/http" "net/http/httptest" @@ -147,11 +147,11 @@ func TestSearchStream(t *testing.T) { if err != nil { t.Fatal(err) } - got, err := ioutil.ReadAll(r) + got, err := io.ReadAll(r) if err != nil { t.Fatal(err) } - want, err := ioutil.ReadFile(c.want) + want, err := os.ReadFile(c.want) if err != nil { t.Fatal(err) } diff --git a/cmd/src/search_test.go b/cmd/src/search_test.go index 1f79b79cdf..59b28c558e 100644 --- a/cmd/src/search_test.go +++ b/cmd/src/search_test.go @@ -3,7 +3,6 @@ package main import ( "bytes" "encoding/json" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -29,7 +28,7 @@ func TestSearchOutput(t *testing.T) { tests := map[string]*testT{} dataDir := "testdata/search_formatting" - infos, err := ioutil.ReadDir(dataDir) + infos, err := os.ReadDir(dataDir) if err != nil { t.Fatal(err) } @@ -50,7 +49,7 @@ func TestSearchOutput(t *testing.T) { tests[testName] = &testT{} } - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { t.Fatal(err) } @@ -74,7 +73,7 @@ func TestSearchOutput(t *testing.T) { if tst.want == nil { // Create the initial (empty) .want.txt file. wantFile := filepath.Join(dataDir, testName+".want.txt") - if err := ioutil.WriteFile(wantFile, nil, 0600); err != nil { + if err := os.WriteFile(wantFile, nil, 0600); err != nil { t.Fatal(err) } tmp := "" @@ -100,7 +99,7 @@ func TestSearchOutput(t *testing.T) { gotFile := filepath.Join(dataDir, testName+".got.txt") wantFile := filepath.Join(dataDir, testName+".want.txt") - err := ioutil.WriteFile(gotFile, []byte(got), 0600) + err := os.WriteFile(gotFile, []byte(got), 0600) if err != nil { t.Fatal(err) } diff --git a/cmd/src/servegit.go b/cmd/src/servegit.go index 2dcf5363e0..99d46ddb30 100644 --- a/cmd/src/servegit.go +++ b/cmd/src/servegit.go @@ -3,7 +3,7 @@ package main import ( "flag" "fmt" - "io/ioutil" + "io" "log" "os" @@ -53,7 +53,7 @@ Documentation at https://docs.sourcegraph.com/admin/external_service/src_serve_g return cmderrors.Usage("requires zero or one arguments") } - dbug := log.New(ioutil.Discard, "", log.LstdFlags) + dbug := log.New(io.Discard, "", log.LstdFlags) if *verbose { dbug = log.New(os.Stderr, "DBUG serve-git: ", log.LstdFlags) } diff --git a/cmd/src/validate.go b/cmd/src/validate.go index b1b2363f34..9652464829 100644 --- a/cmd/src/validate.go +++ b/cmd/src/validate.go @@ -6,7 +6,7 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -92,7 +92,7 @@ Please visit https://docs.sourcegraph.com/admin/validation for documentation of var err error if len(flagSet.Args()) == 1 { filename := flagSet.Arg(0) - script, err = ioutil.ReadFile(filename) + script, err = os.ReadFile(filename) if err != nil { return err } @@ -102,7 +102,7 @@ Please visit https://docs.sourcegraph.com/admin/validation for documentation of } if !isatty.IsTerminal(os.Stdin.Fd()) { // stdin is a pipe not a terminal - script, err = ioutil.ReadAll(os.Stdin) + script, err = io.ReadAll(os.Stdin) if err != nil { return err } @@ -147,7 +147,7 @@ func (vd *validator) parseKVPairs(val string, pairSep string) map[string]string } func (vd *validator) readSecrets(path string) (map[string]string, error) { - bs, err := ioutil.ReadFile(path) + bs, err := os.ReadFile(path) if err != nil { return nil, err } @@ -497,7 +497,7 @@ func (vd *validator) newClient(baseURL string) (*vdClient, error) { } defer func() { _ = resp.Body.Close() }() - p, err := ioutil.ReadAll(resp.Body) + p, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -548,7 +548,7 @@ func (c *vdClient) authenticate(path string, body interface{}) error { defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { - p, err := ioutil.ReadAll(resp.Body) + p, err := io.ReadAll(resp.Body) if err != nil { return err } @@ -654,7 +654,7 @@ func (c *vdClient) graphQL(token, query string, variables map[string]interface{} defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { - p, err := ioutil.ReadAll(resp.Body) + p, err := io.ReadAll(resp.Body) if err != nil { return err } diff --git a/cmd/src/version.go b/cmd/src/version.go index eec0bb183e..37bdeb7bdd 100644 --- a/cmd/src/version.go +++ b/cmd/src/version.go @@ -5,7 +5,7 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" + "io" "net/http" "github.com/sourcegraph/src-cli/internal/api" @@ -66,7 +66,7 @@ func getRecommendedVersion(ctx context.Context, client api.Client) (string, erro } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return "", err } diff --git a/internal/api/api.go b/internal/api/api.go index 221edbb9ec..132b594ae4 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "os" "strings" @@ -248,7 +247,7 @@ func (r *request) do(ctx context.Context, result interface{}) (bool, error) { fmt.Println("See https://github.com/sourcegraph/src-cli#readme") fmt.Println("") } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return false, err } diff --git a/internal/api/gzip_test.go b/internal/api/gzip_test.go index 5cca5ee585..1d6b3006ad 100644 --- a/internal/api/gzip_test.go +++ b/internal/api/gzip_test.go @@ -3,7 +3,7 @@ package api import ( "bytes" "compress/gzip" - "io/ioutil" + "io" "testing" "github.com/google/go-cmp/cmp" @@ -15,7 +15,7 @@ func TestGzipReader(t *testing.T) { uncompressed = append(uncompressed, byte(i)) } - contents, err := ioutil.ReadAll(gzipReader(bytes.NewReader(uncompressed))) + contents, err := io.ReadAll(gzipReader(bytes.NewReader(uncompressed))) if err != nil { t.Fatalf("unexpected error reading from gzip reader: %s", err) } @@ -24,7 +24,7 @@ func TestGzipReader(t *testing.T) { if err != nil { t.Fatalf("unexpected error creating gzip.Reader: %s", err) } - decompressed, err := ioutil.ReadAll(gzipReader) + decompressed, err := io.ReadAll(gzipReader) if err != nil { t.Fatalf("unexpected error reading from gzip.Reader: %s", err) } diff --git a/internal/batches/executor/execution_cache.go b/internal/batches/executor/execution_cache.go index 1b092a4ee3..e4eb0b66ba 100644 --- a/internal/batches/executor/execution_cache.go +++ b/internal/batches/executor/execution_cache.go @@ -6,12 +6,12 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "github.com/cockroachdb/errors" batcheslib "github.com/sourcegraph/sourcegraph/lib/batches" + "github.com/sourcegraph/src-cli/internal/batches/util" ) @@ -190,7 +190,7 @@ func (c ExecutionDiskCache) readCacheFile(path string, result interface{}) (bool return false, nil } - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return false, err } @@ -216,7 +216,7 @@ func (c ExecutionDiskCache) writeCacheFile(path string, result interface{}) erro return err } - return ioutil.WriteFile(path, raw, 0600) + return os.WriteFile(path, raw, 0600) } func (c ExecutionDiskCache) Set(ctx context.Context, key CacheKeyer, result executionResult) error { diff --git a/internal/batches/executor/execution_cache_test.go b/internal/batches/executor/execution_cache_test.go index 7002e68c20..d2bc18de0c 100644 --- a/internal/batches/executor/execution_cache_test.go +++ b/internal/batches/executor/execution_cache_test.go @@ -2,7 +2,6 @@ package executor import ( "context" - "io/ioutil" "os" "testing" @@ -110,7 +109,7 @@ func TestExecutionDiskCache_GetSet(t *testing.T) { ctx := context.Background() cacheTmpDir := func(t *testing.T) string { - testTempDir, err := ioutil.TempDir("", "execution-disk-cache-test-*") + testTempDir, err := os.MkdirTemp("", "execution-disk-cache-test-*") if err != nil { t.Fatal(err) } diff --git a/internal/batches/executor/executor_test.go b/internal/batches/executor/executor_test.go index 4490e38d3b..2a53b9102b 100644 --- a/internal/batches/executor/executor_test.go +++ b/internal/batches/executor/executor_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "fmt" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -334,7 +333,7 @@ func TestExecutor_Integration(t *testing.T) { client := api.NewClient(api.ClientOpts{Endpoint: ts.URL, Out: &clientBuffer}) // Temp dir for log files and downloaded archives - testTempDir, err := ioutil.TempDir("", "executor-integration-test-*") + testTempDir, err := os.MkdirTemp("", "executor-integration-test-*") if err != nil { t.Fatal(err) } @@ -666,7 +665,7 @@ func testExecuteTasks(t *testing.T, tasks []*Task, archives ...mock.RepoArchive) t.Skip("Test doesn't work on Windows because dummydocker is written in bash") } - testTempDir, err := ioutil.TempDir("", "executor-integration-test-*") + testTempDir, err := os.MkdirTemp("", "executor-integration-test-*") if err != nil { t.Fatal(err) } diff --git a/internal/batches/executor/run_steps.go b/internal/batches/executor/run_steps.go index 6dcb66eac8..78d8890e96 100644 --- a/internal/batches/executor/run_steps.go +++ b/internal/batches/executor/run_steps.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "os/exec" "strings" @@ -455,7 +454,7 @@ func createFilesToMount(tempDir string, step batcheslib.Step, stepContext *templ // can mount them into the container. filesToMount := make(map[string]*os.File, len(files)) for name, content := range files { - fp, err := ioutil.TempFile(tempDir, "") + fp, err := os.CreateTemp(tempDir, "") if err != nil { return nil, cleanup, errors.Wrap(err, "creating temporary file") } @@ -481,7 +480,7 @@ func createFilesToMount(tempDir string, step batcheslib.Step, stepContext *templ func createRunScriptFile(ctx context.Context, tempDir string, stepRun string, stepCtx *template.StepContext) (string, string, func(), error) { // Set up a temporary file on the host filesystem to contain the // script. - runScriptFile, err := ioutil.TempFile(tempDir, "") + runScriptFile, err := os.CreateTemp(tempDir, "") if err != nil { return "", "", nil, errors.Wrap(err, "creating temporary file") } @@ -523,7 +522,7 @@ func createCidFile(ctx context.Context, tempDir string, repoSlug string) (string // Find a location that we can use for a cidfile, which will contain the // container ID that is used below. We can then use this to remove the // container on a successful run, rather than leaving it dangling. - cidFile, err := ioutil.TempFile(tempDir, repoSlug+"-container-id") + cidFile, err := os.CreateTemp(tempDir, repoSlug+"-container-id") if err != nil { return "", nil, errors.Wrap(err, "Creating a CID file failed") } @@ -539,7 +538,7 @@ func createCidFile(ctx context.Context, tempDir string, repoSlug string) (string // Since we went to all that effort, we can now defer a function that // uses the cidfile to clean up after this function is done. cleanup := func() { - cid, err := ioutil.ReadFile(cidFile.Name()) + cid, err := os.ReadFile(cidFile.Name()) _ = os.Remove(cidFile.Name()) if err == nil { ctx, cancel := context.WithTimeout(ctx, 2*time.Second) diff --git a/internal/batches/log/task_logger.go b/internal/batches/log/task_logger.go index 6f71fa0544..84dd1616d2 100644 --- a/internal/batches/log/task_logger.go +++ b/internal/batches/log/task_logger.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "time" @@ -30,7 +29,7 @@ type FileTaskLogger struct { func newTaskLogger(slug string, keep bool, dir string) (*FileTaskLogger, error) { prefix := "changeset-" + slug - f, err := ioutil.TempFile(dir, prefix+".*.log") + f, err := os.CreateTemp(dir, prefix+".*.log") if err != nil { return nil, errors.Wrapf(err, "creating temporary file with prefix %q", prefix) } diff --git a/internal/batches/repozip/fetcher_test.go b/internal/batches/repozip/fetcher_test.go index 3587c1e0bd..3e778d3f4a 100644 --- a/internal/batches/repozip/fetcher_test.go +++ b/internal/batches/repozip/fetcher_test.go @@ -3,7 +3,6 @@ package repozip import ( "bytes" "context" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -23,7 +22,7 @@ import ( func TestArchive_Ensure(t *testing.T) { workspaceTmpDir := func(t *testing.T) string { - testTempDir, err := ioutil.TempDir("", "executor-integration-test-*") + testTempDir, err := os.MkdirTemp("", "executor-integration-test-*") if err != nil { t.Fatal(err) } @@ -310,7 +309,7 @@ func TestArchive_Ensure(t *testing.T) { func sortStrings(a, b string) bool { return a < b } func dirContains(dir, filename string) (bool, error) { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return false, err } diff --git a/internal/batches/workspace/bind_workspace.go b/internal/batches/workspace/bind_workspace.go index c20108d1ab..2d1e71a92f 100644 --- a/internal/batches/workspace/bind_workspace.go +++ b/internal/batches/workspace/bind_workspace.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -159,7 +158,7 @@ func (w *dockerBindWorkspace) Diff(ctx context.Context) ([]byte, error) { func (w *dockerBindWorkspace) ApplyDiff(ctx context.Context, diff []byte) error { // Write the diff to a temp file so we can pass it to `git apply` - tmp, err := ioutil.TempFile(w.tempDir, "bind-workspace-test-*") + tmp, err := os.CreateTemp(w.tempDir, "bind-workspace-test-*") if err != nil { return errors.Wrap(err, "saving cached diff to temporary file") } @@ -184,7 +183,7 @@ func (w *dockerBindWorkspace) ApplyDiff(ctx context.Context, diff []byte) error } func unzipToTempDir(ctx context.Context, zipFile, tempDir, tempFilePrefix string) (string, error) { - volumeDir, err := ioutil.TempDir(tempDir, tempFilePrefix) + volumeDir, err := os.MkdirTemp(tempDir, tempFilePrefix) if err != nil { return "", err } diff --git a/internal/batches/workspace/bind_workspace_test.go b/internal/batches/workspace/bind_workspace_test.go index 31dfa33669..ed64664edc 100644 --- a/internal/batches/workspace/bind_workspace_test.go +++ b/internal/batches/workspace/bind_workspace_test.go @@ -3,7 +3,6 @@ package workspace import ( "archive/zip" "context" - "io/ioutil" "os" "path/filepath" "strings" @@ -22,7 +21,7 @@ var repo = &graphql.Repository{ } func zipUpFiles(t *testing.T, dir string, files map[string]string) string { - f, err := ioutil.TempFile(dir, "repo-zip-*") + f, err := os.CreateTemp(dir, "repo-zip-*") if err != nil { t.Fatal(err) } @@ -46,7 +45,7 @@ func zipUpFiles(t *testing.T, dir string, files map[string]string) string { } func workspaceTmpDir(t *testing.T) string { - testTempDir, err := ioutil.TempDir("", "bind-workspace-test-*") + testTempDir, err := os.MkdirTemp("", "bind-workspace-test-*") if err != nil { t.Fatal(err) } @@ -70,7 +69,7 @@ func TestDockerBindWorkspaceCreator_Create(t *testing.T) { } additionalFilePaths := map[string]string{} for name, content := range additionalFiles { - f, err := ioutil.TempFile(fakeFilesTmpDir, name+"-*") + f, err := os.CreateTemp(fakeFilesTmpDir, name+"-*") if err != nil { t.Fatal(err) } @@ -109,7 +108,7 @@ func TestDockerBindWorkspaceCreator_Create(t *testing.T) { testTempDir := workspaceTmpDir(t) // Create an empty file (which is therefore a bad zip file). - badZip, err := ioutil.TempFile(testTempDir, "bad-zip-*") + badZip, err := os.CreateTemp(testTempDir, "bad-zip-*") if err != nil { t.Fatal(err) } @@ -327,7 +326,7 @@ func TestEnsureAll(t *testing.T) { } func mustCreateWorkspace(t *testing.T) string { - base, err := ioutil.TempDir("", "") + base, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -375,7 +374,7 @@ func readWorkspaceFiles(workspace Workspace) (map[string]string, error) { return nil } - content, err := ioutil.ReadFile(path) + content, err := os.ReadFile(path) if err != nil { return err } diff --git a/internal/batches/workspace/volume_workspace.go b/internal/batches/workspace/volume_workspace.go index f3436a6b7b..a189d58671 100644 --- a/internal/batches/workspace/volume_workspace.go +++ b/internal/batches/workspace/volume_workspace.go @@ -6,7 +6,6 @@ import ( "crypto/rand" "encoding/hex" "fmt" - "io/ioutil" "os" "sort" "strings" @@ -313,7 +312,7 @@ func init() { // container started from the dockerWorkspaceImage, then run it and return the // output. func (w *dockerVolumeWorkspace) runScript(ctx context.Context, target, script string) ([]byte, error) { - f, err := ioutil.TempFile(w.tempDir, "src-run-*") + f, err := os.CreateTemp(w.tempDir, "src-run-*") if err != nil { return nil, errors.Wrap(err, "creating run script") } diff --git a/internal/batches/workspace/volume_workspace_test.go b/internal/batches/workspace/volume_workspace_test.go index aa5b0b377c..8ac6af42e3 100644 --- a/internal/batches/workspace/volume_workspace_test.go +++ b/internal/batches/workspace/volume_workspace_test.go @@ -3,7 +3,6 @@ package workspace import ( "bytes" "context" - "io/ioutil" "os" "path/filepath" "strings" @@ -29,7 +28,7 @@ func TestVolumeWorkspaceCreator(t *testing.T) { // Create an empty file. It doesn't matter that it's an invalid zip, since // we're mocking the unzip command anyway. - f, err := ioutil.TempFile(os.TempDir(), "volume-workspace-*") + f, err := os.CreateTemp(os.TempDir(), "volume-workspace-*") if err != nil { t.Fatal(err) } @@ -644,7 +643,7 @@ func TestVolumeWorkspace_runScript(t *testing.T) { // mount options. Let's go get it! values := strings.Split(arg[6], ",") source := strings.SplitN(values[1], "=", 2) - have, err := ioutil.ReadFile(source[1]) + have, err := os.ReadFile(source[1]) if err != nil { return errors.Errorf("error reading temporary file %q: %v", source[1], err) } diff --git a/internal/exec/expect/expect.go b/internal/exec/expect/expect.go index e6c4f9ae4d..82e2e044c0 100644 --- a/internal/exec/expect/expect.go +++ b/internal/exec/expect/expect.go @@ -19,7 +19,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "os" goexec "os/exec" "testing" @@ -95,7 +94,7 @@ func Commands(t *testing.T, exp ...*Expectation) { cmd.Args = []string{} // Actually create the behaviour file. - f, err := ioutil.TempFile(os.TempDir(), "behaviour") + f, err := os.CreateTemp(os.TempDir(), "behaviour") if err != nil { t.Fatalf("error creating behaviour file: %v", err) } @@ -143,7 +142,7 @@ func Handle(m interface{ Run() int }) int { } // Load up the expected behaviour of this command. - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err != nil { panicErr(err) } diff --git a/internal/servegit/serve_test.go b/internal/servegit/serve_test.go index ce1c2e063c..bc62011bfc 100644 --- a/internal/servegit/serve_test.go +++ b/internal/servegit/serve_test.go @@ -2,7 +2,7 @@ package servegit import ( "encoding/json" - "io/ioutil" + "io" "log" "net/http" "net/http/httptest" @@ -19,7 +19,7 @@ import ( const testAddress = "test.local:3939" -var discardLogger = log.New(ioutil.Discard, "", log.LstdFlags) +var discardLogger = log.New(io.Discard, "", log.LstdFlags) func TestReposHandler(t *testing.T) { cases := []struct { @@ -87,7 +87,7 @@ func TestReposHandler(t *testing.T) { // This is the difference, we create a symlink for root { - tmp, err := ioutil.TempDir("", "") + tmp, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -125,7 +125,7 @@ func testReposHandler(t *testing.T, h http.Handler, repos []Repo) { if err != nil { t.Fatal(err) } - b, err := ioutil.ReadAll(res.Body) + b, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { t.Fatal(err) @@ -172,7 +172,7 @@ func testReposHandler(t *testing.T, h http.Handler, repos []Repo) { } func gitInitRepos(t *testing.T, names ...string) string { - root, err := ioutil.TempDir("", "") + root, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -194,7 +194,7 @@ func gitInitRepos(t *testing.T, names ...string) string { } func TestIgnoreGitSubmodules(t *testing.T) { - root, err := ioutil.TempDir("", "") + root, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -204,7 +204,7 @@ func TestIgnoreGitSubmodules(t *testing.T) { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(root, "dir", ".git"), []byte("ignore me please"), os.ModePerm); err != nil { + if err := os.WriteFile(filepath.Join(root, "dir", ".git"), []byte("ignore me please"), os.ModePerm); err != nil { t.Fatal(err) }