From 1ba16485174fdafcb5e692ae618cac81e9b37b32 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Tue, 3 Oct 2023 23:05:47 +0300 Subject: [PATCH] Replace deprecated package io/ioutil with io and os (#1423) Co-authored-by: Andrew Starr-Bochicchio --- commands/apps.go | 3 +- commands/apps_dev_config_test.go | 3 +- commands/apps_test.go | 24 +++------- commands/auth_test.go | 7 ++- commands/certificates.go | 4 +- commands/certificates_test.go | 7 ++- commands/commands_test.go | 4 +- commands/droplets.go | 4 +- commands/droplets_test.go | 4 +- commands/invoices.go | 6 +-- commands/invoices_test.go | 5 +- commands/serverless_test.go | 19 ++------ commands/sshkeys.go | 4 +- commands/sshkeys_test.go | 3 +- do/serverless.go | 9 ++-- integration/apps_test.go | 46 ++++++------------- integration/auth_remove_context_test.go | 8 ++-- integration/auth_test.go | 21 ++++----- integration/cdn_create_test.go | 4 +- integration/cdn_flush_test.go | 4 +- integration/cdn_update_test.go | 4 +- integration/certificate_create_test.go | 7 +-- integration/compute_droplet_action_test.go | 4 +- .../compute_floating_ip_action_test.go | 6 +-- integration/compute_image_action_test.go | 4 +- .../compute_reserved_ip_action_test.go | 6 +-- integration/compute_volume_action_test.go | 8 ++-- integration/database_create_fork_test.go | 4 +- .../database_create_restore_from_cluster.go | 4 +- integration/database_create_test.go | 4 +- integration/database_firewall_update_test.go | 4 +- integration/database_sql_mode_test.go | 4 +- integration/database_user_create_test.go | 4 +- integration/domain_create_test.go | 4 +- integration/domain_records_create_test.go | 6 +-- integration/domain_records_delete_test.go | 6 +-- integration/domain_records_update_test.go | 4 +- integration/droplet_create_test.go | 4 +- integration/droplet_get_test.go | 3 +- integration/droplet_neighbors_test.go | 3 +- integration/droplet_tag_test.go | 4 +- integration/firewall_create_test.go | 4 +- integration/firewall_update_test.go | 4 +- integration/floating_ip_create_test.go | 4 +- integration/image_list_test.go | 6 +-- integration/image_update_test.go | 4 +- integration/init_test.go | 7 ++- integration/invoice_csv_test.go | 3 +- integration/invoice_pdf_test.go | 3 +- .../kubernetes_clusters_create_test.go | 13 ++---- ...ubernetes_clusters_kubeconfig_save_test.go | 20 +++----- integration/lb_add_droplets_test.go | 4 +- integration/lb_add_forwarding_rules_test.go | 4 +- integration/lb_create_test.go | 4 +- integration/lb_remove_droplets_test.go | 4 +- .../lb_remove_forwarding_rules_test.go | 4 +- integration/lb_update_test.go | 4 +- integration/projects_create_test.go | 4 +- integration/projects_resources_assign_test.go | 4 +- integration/projects_update_test.go | 4 +- integration/registry_create_test.go | 4 +- .../registry_garbagecollection_test.go | 4 +- integration/registry_login_test.go | 7 ++- integration/registry_logout_test.go | 5 +- integration/reserved_ip_create_test.go | 4 +- integration/tags_apply_test.go | 6 +-- integration/tags_delete_test.go | 6 +-- integration/tags_remove_test.go | 6 +-- integration/volume_create_test.go | 4 +- integration/volume_snapshot_test.go | 4 +- integration/vpc_create_test.go | 4 +- integration/vpc_update_test.go | 4 +- internal/apps/apps.go | 3 +- internal/apps/apps_test.go | 4 +- internal/apps/builder/cnb_test.go | 8 ++-- internal/apps/builder/docker.go | 3 +- internal/apps/builder/docker_test.go | 7 ++- internal/apps/config/appdev.go | 3 +- internal/apps/workspace/workspace.go | 3 +- internal/apps/workspace/workspace_test.go | 5 +- pkg/extract/extract_test.go | 29 +++--------- 81 files changed, 214 insertions(+), 299 deletions(-) diff --git a/commands/apps.go b/commands/apps.go index 054fe5dcf..fa3f3e190 100644 --- a/commands/apps.go +++ b/commands/apps.go @@ -18,7 +18,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -953,7 +952,7 @@ func readAppAlertDestination(stdin io.Reader, path string) (*godo.AlertDestinati alertDestinations = alertDestinationsFile } - byt, err := ioutil.ReadAll(alertDestinations) + byt, err := io.ReadAll(alertDestinations) if err != nil { return nil, fmt.Errorf("reading app alert destinations: %w", err) } diff --git a/commands/apps_dev_config_test.go b/commands/apps_dev_config_test.go index 6b76a6b08..c9f2b6efc 100644 --- a/commands/apps_dev_config_test.go +++ b/commands/apps_dev_config_test.go @@ -2,7 +2,6 @@ package commands import ( "errors" - "io/ioutil" "os" "path/filepath" "testing" @@ -202,7 +201,7 @@ func tempAppSpec(t *testing.T, spec *godo.AppSpec) (path string) { path = tempFile(t, "app.yaml") specYaml, err := yaml.Marshal(spec) require.NoError(t, err, "marshaling app spec") - err = ioutil.WriteFile(path, specYaml, 0664) + err = os.WriteFile(path, specYaml, 0664) require.NoError(t, err, "writing app spec to disk") return } diff --git a/commands/apps_test.go b/commands/apps_test.go index f5775c419..619620768 100644 --- a/commands/apps_test.go +++ b/commands/apps_test.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "io" - "io/ioutil" "net/url" "os" "testing" @@ -130,12 +129,9 @@ var ( func TestRunAppsCreate(t *testing.T) { withTestClient(t, func(config *CmdConfig, tm *tcMocks) { - specFile, err := ioutil.TempFile("", "spec") + specFile, err := os.CreateTemp(t.TempDir(), "spec") require.NoError(t, err) - defer func() { - os.Remove(specFile.Name()) - specFile.Close() - }() + defer specFile.Close() err = json.NewEncoder(specFile).Encode(&testAppSpec) require.NoError(t, err) @@ -195,12 +191,9 @@ func TestRunAppsList(t *testing.T) { func TestRunAppsUpdate(t *testing.T) { withTestClient(t, func(config *CmdConfig, tm *tcMocks) { - specFile, err := ioutil.TempFile("", "spec") + specFile, err := os.CreateTemp(t.TempDir(), "spec") require.NoError(t, err) - defer func() { - os.Remove(specFile.Name()) - specFile.Close() - }() + defer specFile.Close() err = json.NewEncoder(specFile).Encode(&testAppSpec) require.NoError(t, err) @@ -543,7 +536,7 @@ var validAppSpec = &godo.AppSpec{ func testTempFile(t *testing.T, data []byte) string { t.Helper() file := t.TempDir() + "/file" - err := ioutil.WriteFile(file, data, 0644) + err := os.WriteFile(file, data, 0644) require.NoError(t, err, "writing temp file") return file } @@ -769,12 +762,9 @@ func TestRunAppsListAlerts(t *testing.T) { func TestRunAppsUpdateAlertDestinations(t *testing.T) { withTestClient(t, func(config *CmdConfig, tm *tcMocks) { - destinationsFile, err := ioutil.TempFile("", "dest") + destinationsFile, err := os.CreateTemp(t.TempDir(), "dest") require.NoError(t, err) - defer func() { - os.Remove(destinationsFile.Name()) - destinationsFile.Close() - }() + defer destinationsFile.Close() err = json.NewEncoder(destinationsFile).Encode(&testAlertUpdate) require.NoError(t, err) diff --git a/commands/auth_test.go b/commands/auth_test.go index fbd890bda..459975b54 100644 --- a/commands/auth_test.go +++ b/commands/auth_test.go @@ -17,7 +17,6 @@ import ( "bufio" "bytes" "io" - "io/ioutil" "path/filepath" "testing" @@ -48,7 +47,7 @@ func TestAuthInit(t *testing.T) { return "valid-token", nil } - cfgFileWriter = func() (io.WriteCloser, error) { return &nopWriteCloser{Writer: ioutil.Discard}, nil } + cfgFileWriter = func() (io.WriteCloser, error) { return &nopWriteCloser{Writer: io.Discard}, nil } withTestClient(t, func(config *CmdConfig, tm *tcMocks) { tm.oauth.EXPECT().TokenInfo(gomock.Any()).Return(&do.OAuthTokenInfo{}, nil) @@ -114,7 +113,7 @@ func TestAuthInitWithProvidedToken(t *testing.T) { return "", errors.New("should not have called this") } - cfgFileWriter = func() (io.WriteCloser, error) { return &nopWriteCloser{Writer: ioutil.Discard}, nil } + cfgFileWriter = func() (io.WriteCloser, error) { return &nopWriteCloser{Writer: io.Discard}, nil } withTestClient(t, func(config *CmdConfig, tm *tcMocks) { tm.oauth.EXPECT().TokenInfo(gomock.Any()).Return(&do.OAuthTokenInfo{}, nil) @@ -136,7 +135,7 @@ func TestAuthForcesLowercase(t *testing.T) { return "", errors.New("should not have called this") } - cfgFileWriter = func() (io.WriteCloser, error) { return &nopWriteCloser{Writer: ioutil.Discard}, nil } + cfgFileWriter = func() (io.WriteCloser, error) { return &nopWriteCloser{Writer: io.Discard}, nil } withTestClient(t, func(config *CmdConfig, tm *tcMocks) { tm.oauth.EXPECT().TokenInfo(gomock.Any()).Return(&do.OAuthTokenInfo{}, nil) diff --git a/commands/certificates.go b/commands/certificates.go index b4311be47..dca418088 100644 --- a/commands/certificates.go +++ b/commands/certificates.go @@ -14,7 +14,7 @@ limitations under the License. package commands import ( - "io/ioutil" + "os" "github.com/digitalocean/doctl" "github.com/digitalocean/doctl/commands/displayers" @@ -217,7 +217,7 @@ func RunCertificateDelete(c *CmdConfig) error { } func readInputFromFile(path string) (string, error) { - fileBytes, err := ioutil.ReadFile(path) + fileBytes, err := os.ReadFile(path) if err != nil { return "", err } diff --git a/commands/certificates_test.go b/commands/certificates_test.go index 4757ad38a..4ce254dd5 100644 --- a/commands/certificates_test.go +++ b/commands/certificates_test.go @@ -1,7 +1,6 @@ package commands import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -106,21 +105,21 @@ func TestCertificatesCreate(t *testing.T) { t.Run(test.desc, func(t *testing.T) { withTestClient(t, func(config *CmdConfig, tm *tcMocks) { if test.privateKeyPath != "" { - pkErr := ioutil.WriteFile(test.privateKeyPath, []byte("-----BEGIN PRIVATE KEY-----"), 0600) + pkErr := os.WriteFile(test.privateKeyPath, []byte("-----BEGIN PRIVATE KEY-----"), 0600) assert.NoError(t, pkErr) defer os.Remove(test.privateKeyPath) } if test.certLeafPath != "" { - certErr := ioutil.WriteFile(test.certLeafPath, []byte("-----BEGIN CERTIFICATE-----"), 0600) + certErr := os.WriteFile(test.certLeafPath, []byte("-----BEGIN CERTIFICATE-----"), 0600) assert.NoError(t, certErr) defer os.Remove(test.certLeafPath) } if test.certChainPath != "" { - certErr := ioutil.WriteFile(test.certChainPath, []byte("-----BEGIN CERTIFICATE-----"), 0600) + certErr := os.WriteFile(test.certChainPath, []byte("-----BEGIN CERTIFICATE-----"), 0600) assert.NoError(t, certErr) defer os.Remove(test.certChainPath) diff --git a/commands/commands_test.go b/commands/commands_test.go index 3ec8b4da7..e5413e4ac 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -14,7 +14,7 @@ limitations under the License. package commands import ( - "io/ioutil" + "io" "sort" "testing" @@ -241,7 +241,7 @@ func withTestClient(t *testing.T, tFn testFn) { config := &CmdConfig{ NS: "test", Doit: testConfig, - Out: ioutil.Discard, + Out: io.Discard, // can stub this out, since the return is dictated by the mocks. initServices: func(c *CmdConfig) error { return nil }, diff --git a/commands/droplets.go b/commands/droplets.go index 14a938373..a3a0030f5 100644 --- a/commands/droplets.go +++ b/commands/droplets.go @@ -15,7 +15,7 @@ package commands import ( "fmt" - "io/ioutil" + "os" "sort" "strconv" "strings" @@ -413,7 +413,7 @@ func extractSSHKeys(keys []string) []godo.DropletCreateSSHKey { func extractUserData(userData, filename string) (string, error) { if userData == "" && filename != "" { - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { return "", err } diff --git a/commands/droplets_test.go b/commands/droplets_test.go index f1a79f197..20844a92b 100644 --- a/commands/droplets_test.go +++ b/commands/droplets_test.go @@ -15,7 +15,6 @@ package commands import ( "bytes" - "io/ioutil" "os" "strconv" "testing" @@ -163,9 +162,8 @@ coreos: command: start ` - tmpFile, err := ioutil.TempFile(os.TempDir(), "doctlDropletsTest-*.yml") + tmpFile, err := os.CreateTemp(t.TempDir(), "doctlDropletsTest-*.yml") assert.NoError(t, err) - defer os.Remove(tmpFile.Name()) _, err = tmpFile.WriteString(userData) assert.NoError(t, err) diff --git a/commands/invoices.go b/commands/invoices.go index ead7dd2c8..69a22c603 100644 --- a/commands/invoices.go +++ b/commands/invoices.go @@ -15,7 +15,7 @@ package commands import ( "fmt" - "io/ioutil" + "os" "github.com/digitalocean/doctl" "github.com/digitalocean/doctl/commands/displayers" @@ -145,7 +145,7 @@ func RunInvoicesGetPDF(c *CmdConfig) error { outputFile := getOutputFileArg("pdf", c.Args) - err = ioutil.WriteFile(outputFile, pdf, 0644) + err = os.WriteFile(outputFile, pdf, 0644) if err != nil { return err } @@ -167,7 +167,7 @@ func RunInvoicesGetCSV(c *CmdConfig) error { outputFile := getOutputFileArg("csv", c.Args) - err = ioutil.WriteFile(outputFile, csv, 0644) + err = os.WriteFile(outputFile, csv, 0644) if err != nil { return err } diff --git a/commands/invoices_test.go b/commands/invoices_test.go index 6f9f38635..68f61c933 100644 --- a/commands/invoices_test.go +++ b/commands/invoices_test.go @@ -14,7 +14,6 @@ limitations under the License. package commands import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -185,7 +184,7 @@ func TestInvoicesGetPDF(t *testing.T) { assert.NoError(t, err) // Assert the file exists - result, err := ioutil.ReadFile(fpath) + result, err := os.ReadFile(fpath) assert.NoError(t, err) assert.Equal(t, content, result) @@ -208,7 +207,7 @@ func TestInvoicesGetCSV(t *testing.T) { assert.NoError(t, err) // Assert the file exists - result, err := ioutil.ReadFile(fpath) + result, err := os.ReadFile(fpath) assert.NoError(t, err) assert.Equal(t, content, result) diff --git a/commands/serverless_test.go b/commands/serverless_test.go index 9d60c48e5..ee0125b17 100644 --- a/commands/serverless_test.go +++ b/commands/serverless_test.go @@ -18,7 +18,6 @@ import ( "bytes" "context" "errors" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -688,17 +687,12 @@ func TestGetCredentialDirectory(t *testing.T) { func TestPreserveCredsMovesExistingToStaging(t *testing.T) { withTestClient(t, func(config *CmdConfig, tm *tcMocks) { - tmp, err := ioutil.TempDir("", "test-dir") - require.NoError(t, err) - defer func() { - err := os.RemoveAll(tmp) - require.NoError(t, err, "error cleaning tmp dir") - }() + tmp := t.TempDir() // Set up "existing" creds in the "sandbox" dir serverlessDir := filepath.Join(tmp, "sandbox") serverlessCredsDir := filepath.Join(serverlessDir, "creds", "d5b388f2") - err = os.MkdirAll(serverlessCredsDir, os.FileMode(0755)) + err := os.MkdirAll(serverlessCredsDir, os.FileMode(0755)) require.NoError(t, err) serverlessCreds := filepath.Join(serverlessCredsDir, "credentials.json") creds, err := os.Create(serverlessCreds) @@ -726,17 +720,12 @@ func TestPreserveCredsMovesLegacyCreds(t *testing.T) { return "a7bbe7e8af7411ec912e47a270a2ee78a7bbe7e8af7411ec912e47a270a2ee78" } - tmp, err := ioutil.TempDir("", "test-dir") - require.NoError(t, err) - defer func() { - err := os.RemoveAll(tmp) - require.NoError(t, err, "error cleaning tmp dir") - }() + tmp := t.TempDir() // Set up "existing" legacy creds in the "sandbox" dir serverlessDir := filepath.Join(tmp, "sandbox") legacyCredsDir := filepath.Join(serverlessDir, ".nimbella") - err = os.MkdirAll(legacyCredsDir, os.FileMode(0755)) + err := os.MkdirAll(legacyCredsDir, os.FileMode(0755)) require.NoError(t, err) legacyCreds := filepath.Join(legacyCredsDir, "credentials.json") creds, err := os.Create(legacyCreds) diff --git a/commands/sshkeys.go b/commands/sshkeys.go index a24f86c73..d08cf9967 100644 --- a/commands/sshkeys.go +++ b/commands/sshkeys.go @@ -14,7 +14,7 @@ limitations under the License. package commands import ( - "io/ioutil" + "os" "github.com/digitalocean/doctl" "github.com/digitalocean/doctl/commands/displayers" @@ -149,7 +149,7 @@ func RunKeyImport(c *CmdConfig) error { keyName := c.Args[0] - keyFile, err := ioutil.ReadFile(keyPath) + keyFile, err := os.ReadFile(keyPath) if err != nil { return err } diff --git a/commands/sshkeys_test.go b/commands/sshkeys_test.go index 60022d1f5..879a4df9f 100644 --- a/commands/sshkeys_test.go +++ b/commands/sshkeys_test.go @@ -14,7 +14,6 @@ limitations under the License. package commands import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -141,7 +140,7 @@ func TestKeysUpdateByFingerprint(t *testing.T) { func TestSSHPublicKeyImportWithName(t *testing.T) { pubkey := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCn6eZ8ve0ha04rPRZuoPXK1AQ/h21qslWCzoDcOciXn5OcyafkZw+31k/afaBTeW62D8fXd8e/1xWbFfp/2GqmslYpNCTPrtpNhsE8I0yKjJ8FxX9FfsCOu/Sv83dWgSpiT7pNWVKarZjW9KdKKRQljq1i+H5pX3r5Q9I1v+66mYTe7qsKGas9KWy0vkGoNSqmTCl+d+Y0286chtqBqBjSCUCI8oLKPnJB86Lj344tFGmzDIsJKXMVHTL0dF8n3u6iWN4qiRU+JvkoIkI3v0JvyZXxhR2uPIS1yUAY2GC+2O5mfxydJQzBdtag5Uw8Y7H5yYR1gar/h16bAy5XzRvp testkey" path := filepath.Join(os.TempDir(), "key.pub") - err := ioutil.WriteFile(path, []byte(pubkey), 0600) + err := os.WriteFile(path, []byte(pubkey), 0600) assert.NoError(t, err) defer os.Remove(path) diff --git a/do/serverless.go b/do/serverless.go index 393ce46ee..9674133cb 100644 --- a/do/serverless.go +++ b/do/serverless.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -418,7 +417,7 @@ func (s *serverlessService) InstallServerless(leafCredsDir string, upgrading boo // will require an additional copy rather than a simple rename. os.Mkdir(filepath.Dir(serverlessDir), 0700) // in case using config dir and it doesn't exist yet - tmp, err := ioutil.TempDir(filepath.Dir(serverlessDir), "sbx-install") + tmp, err := os.MkdirTemp(filepath.Dir(serverlessDir), "sbx-install") if err != nil { return err } @@ -1162,7 +1161,7 @@ func readTopLevel(project *ServerlessProject) error { Config = "project.yml" Packages = "packages" ) - files, err := ioutil.ReadDir(project.ProjectPath) + files, err := os.ReadDir(project.ProjectPath) if err != nil { return err } @@ -1185,7 +1184,7 @@ func readTopLevel(project *ServerlessProject) error { func readProjectConfig(configPath string) (*ServerlessSpec, error) { spec := ServerlessSpec{} // reading config file content - content, err := ioutil.ReadFile(configPath) + content, err := os.ReadFile(configPath) if err != nil { return nil, err } @@ -1300,7 +1299,7 @@ func serverlessUptodate(serverlessDir string) bool { // Otherwise, returns the version string stored in the serverless directory. func GetCurrentServerlessVersion(serverlessDir string) string { versionFile := filepath.Join(serverlessDir, "version") - contents, err := ioutil.ReadFile(versionFile) + contents, err := os.ReadFile(versionFile) if err != nil { return "0" } diff --git a/integration/apps_test.go b/integration/apps_test.go index c861195bb..59476bb98 100644 --- a/integration/apps_test.go +++ b/integration/apps_test.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/http/httputil" @@ -249,12 +248,9 @@ var _ = suite("apps/create", func(t *testing.T, when spec.G, it spec.S) { }) it("creates an app", func() { - specFile, err := ioutil.TempFile("", "spec") + specFile, err := os.CreateTemp(t.TempDir(), "spec") require.NoError(t, err) - defer func() { - os.Remove(specFile.Name()) - specFile.Close() - }() + defer specFile.Close() err = json.NewEncoder(specFile).Encode(&testAppSpec) require.NoError(t, err) @@ -276,12 +272,10 @@ var _ = suite("apps/create", func(t *testing.T, when spec.G, it spec.S) { }) when("the wait flag is passed", func() { it("creates an app and polls for status", func() { - specFile, err := ioutil.TempFile("", "spec") + specFile, err := os.CreateTemp(t.TempDir(), "spec") require.NoError(t, err) - defer func() { - os.Remove(specFile.Name()) - specFile.Close() - }() + defer specFile.Close() + err = json.NewEncoder(specFile).Encode(&testAppSpec) require.NoError(t, err) cmd := exec.Command(builtBinaryPath, @@ -301,12 +295,10 @@ var _ = suite("apps/create", func(t *testing.T, when spec.G, it spec.S) { }) when("the upsert flag is passed", func() { it("creates an app or updates if already exists", func() { - specFile, err := ioutil.TempFile("", "spec") + specFile, err := os.CreateTemp(t.TempDir(), "spec") require.NoError(t, err) - defer func() { - os.Remove(specFile.Name()) - specFile.Close() - }() + defer specFile.Close() + err = json.NewEncoder(specFile).Encode(&testAppSpec) require.NoError(t, err) cmd := exec.Command(builtBinaryPath, @@ -400,12 +392,9 @@ var _ = suite("apps/create-upsert", func(t *testing.T, when spec.G, it spec.S) { }) it("uses upsert to update existing app", func() { - specFile, err := ioutil.TempFile("", "spec") + specFile, err := os.CreateTemp(t.TempDir(), "spec") require.NoError(t, err) - defer func() { - os.Remove(specFile.Name()) - specFile.Close() - }() + defer specFile.Close() err = json.NewEncoder(specFile).Encode(&testAppSpec) require.NoError(t, err) @@ -611,12 +600,9 @@ var _ = suite("apps/update", func(t *testing.T, when spec.G, it spec.S) { }) it("updates an app", func() { - specFile, err := ioutil.TempFile("", "spec") + specFile, err := os.CreateTemp(t.TempDir(), "spec") require.NoError(t, err) - defer func() { - os.Remove(specFile.Name()) - specFile.Close() - }() + defer specFile.Close() err = json.NewEncoder(specFile).Encode(&testAppSpec) require.NoError(t, err) @@ -639,12 +625,10 @@ var _ = suite("apps/update", func(t *testing.T, when spec.G, it spec.S) { }) when("the wait flag is passed", func() { it("updates an app and polls for status", func() { - specFile, err := ioutil.TempFile("", "spec") + specFile, err := os.CreateTemp(t.TempDir(), "spec") require.NoError(t, err) - defer func() { - os.Remove(specFile.Name()) - specFile.Close() - }() + defer specFile.Close() + err = json.NewEncoder(specFile).Encode(&testAppSpec) require.NoError(t, err) cmd := exec.Command(builtBinaryPath, diff --git a/integration/auth_remove_context_test.go b/integration/auth_remove_context_test.go index 60017a7b0..152e13654 100644 --- a/integration/auth_remove_context_test.go +++ b/integration/auth_remove_context_test.go @@ -4,7 +4,7 @@ package integration import ( - "io/ioutil" + "os" "os/exec" "path/filepath" "testing" @@ -32,7 +32,7 @@ auth-contexts: context: default `) - expect.NoError(ioutil.WriteFile(testConfig, testConfigBytes, 0644)) + expect.NoError(os.WriteFile(testConfig, testConfigBytes, 0644)) }) @@ -65,7 +65,7 @@ context: default _, err := cmd.CombinedOutput() expect.NoError(err) - fileBytes, err := ioutil.ReadFile(testConfig) + fileBytes, err := os.ReadFile(testConfig) expect.NoError(err) expect.NotContains(string(fileBytes), "first-token") }) @@ -85,7 +85,7 @@ context: default _, err := cmd.CombinedOutput() expect.NoError(err) - fileBytes, err := ioutil.ReadFile(testConfig) + fileBytes, err := os.ReadFile(testConfig) expect.NoError(err) expect.NotContains(string(fileBytes), "second-token") }) diff --git a/integration/auth_test.go b/integration/auth_test.go index de22ebad0..ab37f3fce 100644 --- a/integration/auth_test.go +++ b/integration/auth_test.go @@ -7,7 +7,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "net/http/httputil" @@ -101,7 +100,7 @@ var _ = suite("auth/init", func(t *testing.T, when spec.G, it spec.S) { expect.Contains(buf.String(), "Validating token...") expect.Contains(buf.String(), "✔") - fileBytes, err := ioutil.ReadFile(testConfig) + fileBytes, err := os.ReadFile(testConfig) expect.NoError(err) expect.Contains(string(fileBytes), "access-token: some-magic-token-that-is-64-characters-long-1a1a1a1a1a11a1a1a1a1") @@ -126,7 +125,7 @@ var _ = suite("auth/init", func(t *testing.T, when spec.G, it spec.S) { _, err := cmd.CombinedOutput() expect.NoError(err) - fileBytes, err := ioutil.ReadFile(testConfig) + fileBytes, err := os.ReadFile(testConfig) expect.NoError(err) expect.Contains(string(fileBytes), "access-token: some-magic-token") @@ -139,7 +138,7 @@ context: default tmpDir := t.TempDir() testConfig := filepath.Join(tmpDir, "test-config.yml") - expect.NoError(ioutil.WriteFile(testConfig, testConfigBytes, 0644)) + expect.NoError(os.WriteFile(testConfig, testConfigBytes, 0644)) cmd := exec.Command(builtBinaryPath, "-u", server.URL, @@ -153,7 +152,7 @@ context: default _, err := cmd.CombinedOutput() expect.NoError(err) - fileBytes, err := ioutil.ReadFile(testConfig) + fileBytes, err := os.ReadFile(testConfig) expect.NoError(err) expect.Contains(string(fileBytes), "access-token: some-magic-token") @@ -195,7 +194,7 @@ context: default location, err := getDefaultConfigLocation() expect.NoError(err) - fileBytes, err := ioutil.ReadFile(location) + fileBytes, err := os.ReadFile(location) expect.NoError(err) expect.Contains(string(fileBytes), "access-token: some-magic-token-that-is-64-characters-long-1a1a1a1a1a11a1a1a1a1") @@ -257,7 +256,7 @@ context: default tmpDir := t.TempDir() testConfig := filepath.Join(tmpDir, "test-config.yml") - expect.NoError(ioutil.WriteFile(testConfig, testConfigBytes, 0644)) + expect.NoError(os.WriteFile(testConfig, testConfigBytes, 0644)) cmd := exec.Command(builtBinaryPath, "-u", server.URL, @@ -270,7 +269,7 @@ context: default _, err := cmd.CombinedOutput() expect.NoError(err) - fileBytes, err := ioutil.ReadFile(testConfig) + fileBytes, err := os.ReadFile(testConfig) expect.NoError(err) expect.Contains(string(fileBytes), "context: next") @@ -302,7 +301,7 @@ context: default tmpDir := t.TempDir() testConfig := filepath.Join(tmpDir, "test-config.yml") - expect.NoError(ioutil.WriteFile(testConfig, testConfigBytes, 0644)) + expect.NoError(os.WriteFile(testConfig, testConfigBytes, 0644)) cmd := exec.Command(builtBinaryPath, "-u", server.URL, @@ -313,7 +312,7 @@ context: default _, err := cmd.CombinedOutput() expect.NoError(err) - fileBytes, err := ioutil.ReadFile(testConfig) + fileBytes, err := os.ReadFile(testConfig) expect.NoError(err) expect.Contains(string(fileBytes), "test@example.com: second-token") @@ -332,7 +331,7 @@ context: default tmpDir := t.TempDir() testConfig := filepath.Join(tmpDir, "test-config.yml") - expect.NoError(ioutil.WriteFile(testConfig, testConfigBytes, 0644)) + expect.NoError(os.WriteFile(testConfig, testConfigBytes, 0644)) cmd := exec.Command(builtBinaryPath, "-u", server.URL, diff --git a/integration/cdn_create_test.go b/integration/cdn_create_test.go index 47e39d4ab..af9dee3d3 100644 --- a/integration/cdn_create_test.go +++ b/integration/cdn_create_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "html/template" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -40,7 +40,7 @@ var _ = suite("compute/cdn/create", func(t *testing.T, when spec.G, it spec.S) { return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := struct { diff --git a/integration/cdn_flush_test.go b/integration/cdn_flush_test.go index d140a5f25..3cb20a66b 100644 --- a/integration/cdn_flush_test.go +++ b/integration/cdn_flush_test.go @@ -3,7 +3,7 @@ package integration import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -37,7 +37,7 @@ var _ = suite("compute/cdn/flush", func(t *testing.T, when spec.G, it spec.S) { return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := struct { diff --git a/integration/cdn_update_test.go b/integration/cdn_update_test.go index f04a61914..37ef83b22 100644 --- a/integration/cdn_update_test.go +++ b/integration/cdn_update_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -38,7 +38,7 @@ var _ = suite("compute/cdn/update", func(t *testing.T, when spec.G, it spec.S) { return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) requestBodies = append(requestBodies, string(reqBody)) diff --git a/integration/certificate_create_test.go b/integration/certificate_create_test.go index 718cdc456..93685ad7f 100644 --- a/integration/certificate_create_test.go +++ b/integration/certificate_create_test.go @@ -2,10 +2,11 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" + "os" "os/exec" "path/filepath" "strings" @@ -38,7 +39,7 @@ var _ = suite("compute/certificate/create", func(t *testing.T, when spec.G, it s return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) matchedRequest := certCustomCreateJSONReq @@ -85,7 +86,7 @@ var _ = suite("compute/certificate/create", func(t *testing.T, when spec.G, it s dir := t.TempDir() for _, f := range testFiles { - err := ioutil.WriteFile(filepath.Join(dir, f), []byte(f), 0600) + err := os.WriteFile(filepath.Join(dir, f), []byte(f), 0600) expect.NoError(err) } diff --git a/integration/compute_droplet_action_test.go b/integration/compute_droplet_action_test.go index 9f6d3e5a3..b9f54c9c1 100644 --- a/integration/compute_droplet_action_test.go +++ b/integration/compute_droplet_action_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -72,7 +72,7 @@ var _ = suite("compute/droplet-action", func(t *testing.T, when spec.G, it spec. } if matchRequest.body != "{}" { - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(matchRequest.body, string(reqBody)) diff --git a/integration/compute_floating_ip_action_test.go b/integration/compute_floating_ip_action_test.go index 446d8e1df..2bd2c7781 100644 --- a/integration/compute_floating_ip_action_test.go +++ b/integration/compute_floating_ip_action_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -50,7 +50,7 @@ var _ = suite("compute/floating-ip-action", func(t *testing.T, when spec.G, it s return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(`{"type":"unassign"}`, string(reqBody)) @@ -68,7 +68,7 @@ var _ = suite("compute/floating-ip-action", func(t *testing.T, when spec.G, it s return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(`{"droplet_id":1414,"type":"assign"}`, string(reqBody)) diff --git a/integration/compute_image_action_test.go b/integration/compute_image_action_test.go index 919281fa5..6bd5c081a 100644 --- a/integration/compute_image_action_test.go +++ b/integration/compute_image_action_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -50,7 +50,7 @@ var _ = suite("compute/image-action", func(t *testing.T, when spec.G, it spec.S) return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(`{"region":"saturn","type":"transfer"}`, string(reqBody)) diff --git a/integration/compute_reserved_ip_action_test.go b/integration/compute_reserved_ip_action_test.go index 55f00bb7c..a62c1d7dc 100644 --- a/integration/compute_reserved_ip_action_test.go +++ b/integration/compute_reserved_ip_action_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -50,7 +50,7 @@ var _ = suite("compute/reserved-ip-action", func(t *testing.T, when spec.G, it s return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(`{"type":"unassign"}`, string(reqBody)) @@ -68,7 +68,7 @@ var _ = suite("compute/reserved-ip-action", func(t *testing.T, when spec.G, it s return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(`{"droplet_id":1414,"type":"assign"}`, string(reqBody)) diff --git a/integration/compute_volume_action_test.go b/integration/compute_volume_action_test.go index 61c400b81..58efc2900 100644 --- a/integration/compute_volume_action_test.go +++ b/integration/compute_volume_action_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -37,7 +37,7 @@ var _ = suite("compute/volume-action", func(t *testing.T, when spec.G, it spec.S return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(`{"region":"moonbase","size_gigabytes":100,"type":"resize"}`, string(reqBody)) @@ -55,7 +55,7 @@ var _ = suite("compute/volume-action", func(t *testing.T, when spec.G, it spec.S return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(`{"droplet_id":11,"type":"attach"}`, string(reqBody)) @@ -73,7 +73,7 @@ var _ = suite("compute/volume-action", func(t *testing.T, when spec.G, it spec.S return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(`{"droplet_id":14,"type":"detach"}`, string(reqBody)) diff --git a/integration/database_create_fork_test.go b/integration/database_create_fork_test.go index 15aa152df..2a6f649ba 100644 --- a/integration/database_create_fork_test.go +++ b/integration/database_create_fork_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "html/template" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -40,7 +40,7 @@ var _ = suite("database/create/fork", func(t *testing.T, when spec.G, it spec.S) return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := struct { diff --git a/integration/database_create_restore_from_cluster.go b/integration/database_create_restore_from_cluster.go index 18b9543b5..dc0bad56a 100644 --- a/integration/database_create_restore_from_cluster.go +++ b/integration/database_create_restore_from_cluster.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "html/template" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -40,7 +40,7 @@ var _ = suite("database/create/backup-restore", func(t *testing.T, when spec.G, return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := struct { diff --git a/integration/database_create_test.go b/integration/database_create_test.go index c5775aa1d..2e87c3c63 100644 --- a/integration/database_create_test.go +++ b/integration/database_create_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "html/template" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -42,7 +42,7 @@ var _ = suite("database/create", func(t *testing.T, when spec.G, it spec.S) { return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := struct { diff --git a/integration/database_firewall_update_test.go b/integration/database_firewall_update_test.go index bb5ab7e14..9f2a0b442 100644 --- a/integration/database_firewall_update_test.go +++ b/integration/database_firewall_update_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -30,7 +30,7 @@ var _ = suite("database/firewalls", func(t *testing.T, when spec.G, it spec.S) { return } if req.Method == http.MethodPut { - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) t.Log(string(reqBody)) t.Log(databasesUpdateFirewallUpdateRequest) diff --git a/integration/database_sql_mode_test.go b/integration/database_sql_mode_test.go index ea68a3c8f..8f18f713f 100644 --- a/integration/database_sql_mode_test.go +++ b/integration/database_sql_mode_test.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -38,7 +38,7 @@ var _ = suite("database/sql-mode/set", func(t *testing.T, when spec.G, it spec.S return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(databaseGetSQLModeRequest, string(reqBody)) diff --git a/integration/database_user_create_test.go b/integration/database_user_create_test.go index 160149154..f158c8b9a 100644 --- a/integration/database_user_create_test.go +++ b/integration/database_user_create_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "html/template" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -39,7 +39,7 @@ var _ = suite("database/user/create", func(t *testing.T, when spec.G, it spec.S) return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := struct { diff --git a/integration/domain_create_test.go b/integration/domain_create_test.go index 3ef336dbe..1da8cd49d 100644 --- a/integration/domain_create_test.go +++ b/integration/domain_create_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -38,7 +38,7 @@ var _ = suite("compute/domain/create", func(t *testing.T, when spec.G, it spec.S return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(domainCreateRequest, string(reqBody)) diff --git a/integration/domain_records_create_test.go b/integration/domain_records_create_test.go index 624da5d7f..0b5e37def 100644 --- a/integration/domain_records_create_test.go +++ b/integration/domain_records_create_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -37,7 +37,7 @@ var _ = suite("compute/domain/records/create", func(t *testing.T, when spec.G, i return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(domainRecordsCreateRequest, string(reqBody)) @@ -55,7 +55,7 @@ var _ = suite("compute/domain/records/create", func(t *testing.T, when spec.G, i return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(domainRecordsCreateWithoutPortRequest, string(reqBody)) diff --git a/integration/domain_records_delete_test.go b/integration/domain_records_delete_test.go index d38891559..6166d86cd 100644 --- a/integration/domain_records_delete_test.go +++ b/integration/domain_records_delete_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -37,7 +37,7 @@ var _ = suite("compute/domain/records/delete", func(t *testing.T, when spec.G, i return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.Empty(string(reqBody)) @@ -55,7 +55,7 @@ var _ = suite("compute/domain/records/delete", func(t *testing.T, when spec.G, i return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.Empty(string(reqBody)) diff --git a/integration/domain_records_update_test.go b/integration/domain_records_update_test.go index c4c6d8d88..10bc2f75b 100644 --- a/integration/domain_records_update_test.go +++ b/integration/domain_records_update_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -37,7 +37,7 @@ var _ = suite("compute/domain/records/update", func(t *testing.T, when spec.G, i return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(domainRecordUpdateNameRequest, string(reqBody)) diff --git a/integration/droplet_create_test.go b/integration/droplet_create_test.go index 794898f8d..042c47ee1 100644 --- a/integration/droplet_create_test.go +++ b/integration/droplet_create_test.go @@ -3,7 +3,7 @@ package integration import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -44,7 +44,7 @@ var _ = suite("compute/droplet/create", func(t *testing.T, when spec.G, it spec. } var err error - reqBody, err = ioutil.ReadAll(req.Body) + reqBody, err = io.ReadAll(req.Body) expect.NoError(err) var dr dropletRequest diff --git a/integration/droplet_get_test.go b/integration/droplet_get_test.go index d9eb54f60..dcb6878d2 100644 --- a/integration/droplet_get_test.go +++ b/integration/droplet_get_test.go @@ -2,7 +2,6 @@ package integration import ( "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/http/httputil" @@ -30,7 +29,7 @@ var _ = suite("compute/droplet/get", func(t *testing.T, when spec.G, it spec.S) configPath = filepath.Join(dir, "config.yaml") - err := ioutil.WriteFile(configPath, []byte(dropletGetConfig), 0644) + err := os.WriteFile(configPath, []byte(dropletGetConfig), 0644) expect.NoError(err) server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { diff --git a/integration/droplet_neighbors_test.go b/integration/droplet_neighbors_test.go index e106585d3..43e5d2c3e 100644 --- a/integration/droplet_neighbors_test.go +++ b/integration/droplet_neighbors_test.go @@ -2,7 +2,6 @@ package integration import ( "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/http/httputil" @@ -30,7 +29,7 @@ var _ = suite("compute/droplet/neighbors", func(t *testing.T, when spec.G, it sp configPath = filepath.Join(dir, "config.yaml") - err := ioutil.WriteFile(configPath, []byte(dropletNeighborsConfig), 0644) + err := os.WriteFile(configPath, []byte(dropletNeighborsConfig), 0644) expect.NoError(err) server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { diff --git a/integration/droplet_tag_test.go b/integration/droplet_tag_test.go index 3030daf60..bc32cff4e 100644 --- a/integration/droplet_tag_test.go +++ b/integration/droplet_tag_test.go @@ -3,7 +3,7 @@ package integration import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -48,7 +48,7 @@ var _ = suite("compute/droplet/tag", func(t *testing.T, when spec.G, it spec.S) w.Write([]byte(`{"droplets":[{"name":"some-droplet-name", "id": 1337}]}`)) case "/v2/tags/my-tag/resources": - body, err := ioutil.ReadAll(req.Body) + body, err := io.ReadAll(req.Body) expect.NoError(err) var tagRequest tagRequest diff --git a/integration/firewall_create_test.go b/integration/firewall_create_test.go index 526a55afb..f394a02c4 100644 --- a/integration/firewall_create_test.go +++ b/integration/firewall_create_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -37,7 +37,7 @@ var _ = suite("compute/firewall/create", func(t *testing.T, when spec.G, it spec return } - body, err := ioutil.ReadAll(req.Body) + body, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(firewallCreateRequestBody, string(body)) diff --git a/integration/firewall_update_test.go b/integration/firewall_update_test.go index f635f17fe..058c7f64a 100644 --- a/integration/firewall_update_test.go +++ b/integration/firewall_update_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -37,7 +37,7 @@ var _ = suite("compute/firewall/update", func(t *testing.T, when spec.G, it spec return } - body, err := ioutil.ReadAll(req.Body) + body, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(firewallUpdateRequestBody, string(body)) diff --git a/integration/floating_ip_create_test.go b/integration/floating_ip_create_test.go index 5e127d268..af01235c1 100644 --- a/integration/floating_ip_create_test.go +++ b/integration/floating_ip_create_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -38,7 +38,7 @@ var _ = suite("compute/floating-ip/create", func(t *testing.T, when spec.G, it s return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) responseJSON := floatingIPCreateResponse diff --git a/integration/image_list_test.go b/integration/image_list_test.go index 49a19b9ee..295e0b7c2 100644 --- a/integration/image_list_test.go +++ b/integration/image_list_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -133,12 +133,12 @@ var _ = suite("compute/image/list", func(t *testing.T, when spec.G, it spec.S) { t.Fatal(err) } - stdoutString, err := ioutil.ReadAll(stdout) + stdoutString, err := io.ReadAll(stdout) if err != nil { t.Fatal(err) } - stderrString, err := ioutil.ReadAll(stderr) + stderrString, err := io.ReadAll(stderr) if err != nil { t.Fatal(err) } diff --git a/integration/image_update_test.go b/integration/image_update_test.go index 5f322d81b..23e67456b 100644 --- a/integration/image_update_test.go +++ b/integration/image_update_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -37,7 +37,7 @@ var _ = suite("compute/image/update", func(t *testing.T, when spec.G, it spec.S) return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(imageUpdateRequest, string(reqBody)) diff --git a/integration/init_test.go b/integration/init_test.go index ab417663f..ca108d89a 100644 --- a/integration/init_test.go +++ b/integration/init_test.go @@ -2,7 +2,6 @@ package integration import ( "fmt" - "io/ioutil" "os" "os/exec" "path" @@ -30,7 +29,7 @@ func TestRun(t *testing.T) { } func TestMain(m *testing.M) { - tmpDir, err := ioutil.TempDir("", "integration-doctl") + tmpDir, err := os.MkdirTemp("", "integration-doctl") if err != nil { panic("failed to create temp dir") } @@ -56,7 +55,7 @@ func TestMain(m *testing.M) { var contents []byte if _, err := os.Stat(location); !os.IsNotExist(err) { - contents, err = ioutil.ReadFile(location) + contents, err = os.ReadFile(location) if err != nil { panic("failed to copy config") } @@ -70,7 +69,7 @@ func TestMain(m *testing.M) { code := m.Run() if len(contents) != 0 { - err = ioutil.WriteFile(location, contents, 0644) + err = os.WriteFile(location, contents, 0644) if err != nil { panic("failed to restore contents of config") } diff --git a/integration/invoice_csv_test.go b/integration/invoice_csv_test.go index 65961ec4c..3d7c5b3e2 100644 --- a/integration/invoice_csv_test.go +++ b/integration/invoice_csv_test.go @@ -2,7 +2,6 @@ package integration import ( "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/http/httputil" @@ -59,7 +58,7 @@ var _ = suite("invoices/csv", func(t *testing.T, when spec.G, it spec.S) { expect.NoError(err, fmt.Sprintf("received error output: %s", output)) expect.Equal(strings.TrimSpace(invoiceCSVOutput), strings.TrimSpace(string(output))) - result, err := ioutil.ReadFile(fpath) + result, err := os.ReadFile(fpath) expect.NoError(err) expect.Equal([]byte(invoiceCSVResponse), result) diff --git a/integration/invoice_pdf_test.go b/integration/invoice_pdf_test.go index 9bfb65079..9be958e39 100644 --- a/integration/invoice_pdf_test.go +++ b/integration/invoice_pdf_test.go @@ -2,7 +2,6 @@ package integration import ( "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/http/httputil" @@ -59,7 +58,7 @@ var _ = suite("invoices/pdf", func(t *testing.T, when spec.G, it spec.S) { expect.NoError(err, fmt.Sprintf("received error output: %s", output)) expect.Equal(strings.TrimSpace(invoicePDFOutput), strings.TrimSpace(string(output))) - result, err := ioutil.ReadFile(fpath) + result, err := os.ReadFile(fpath) expect.NoError(err) expect.Equal([]byte(invoicePDFResponse), result) diff --git a/integration/kubernetes_clusters_create_test.go b/integration/kubernetes_clusters_create_test.go index 51ca98e2c..44b682f71 100644 --- a/integration/kubernetes_clusters_create_test.go +++ b/integration/kubernetes_clusters_create_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -44,7 +44,7 @@ var _ = suite("kubernetes/clusters/create", func(t *testing.T, when spec.G, it s w.WriteHeader(http.StatusMethodNotAllowed) return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) matchedRequest := kubeClustersCreateJSONReq @@ -89,12 +89,11 @@ var _ = suite("kubernetes/clusters/create", func(t *testing.T, when spec.G, it s when("not using node-pool", func() { it("creates a kube cluster with defaults", func() { - f, err := ioutil.TempFile("", "fake-kube-config") + f, err := os.CreateTemp(t.TempDir(), "fake-kube-config") expect.NoError(err) err = f.Close() expect.NoError(err) - defer os.Remove(f.Name()) cmd := exec.Command(builtBinaryPath, "-t", "some-magic-token", @@ -121,12 +120,11 @@ var _ = suite("kubernetes/clusters/create", func(t *testing.T, when spec.G, it s when("using node-pool", func() { it("creates a kube cluster with the node-pool", func() { - f, err := ioutil.TempFile("", "fake-kube-config") + f, err := os.CreateTemp(t.TempDir(), "fake-kube-config") expect.NoError(err) err = f.Close() expect.NoError(err) - defer os.Remove(f.Name()) cmd := exec.Command(builtBinaryPath, "-t", "some-magic-token", @@ -151,12 +149,11 @@ var _ = suite("kubernetes/clusters/create", func(t *testing.T, when spec.G, it s when("specifying size as well", func() { it("returns an error", func() { - f, err := ioutil.TempFile("", "fake-kube-config") + f, err := os.CreateTemp(t.TempDir(), "fake-kube-config") expect.NoError(err) err = f.Close() expect.NoError(err) - defer os.Remove(f.Name()) cmd := exec.Command(builtBinaryPath, "-t", "some-magic-token", diff --git a/integration/kubernetes_clusters_kubeconfig_save_test.go b/integration/kubernetes_clusters_kubeconfig_save_test.go index 1f46af5c4..18eda0831 100644 --- a/integration/kubernetes_clusters_kubeconfig_save_test.go +++ b/integration/kubernetes_clusters_kubeconfig_save_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -57,11 +57,9 @@ var _ = suite("kubernetes/clusters/kubeconfig/save", func(t *testing.T, when spe when("passing defaults", func() { it("creates a kubeconfig using exec-credentials", func() { - f, err := ioutil.TempFile("", "fake-kube-config") + f, err := os.CreateTemp(t.TempDir(), "fake-kube-config") expect.NoError(err) - defer os.Remove(f.Name()) - cmd := exec.Command(builtBinaryPath, "-t", "some-magic-token", "-u", server.URL, @@ -79,7 +77,7 @@ var _ = suite("kubernetes/clusters/kubeconfig/save", func(t *testing.T, when spe output, err := cmd.CombinedOutput() expect.NoError(err, fmt.Sprintf("received error output: %s", output)) - fileBytes, err := ioutil.ReadAll(f) + fileBytes, err := io.ReadAll(f) expect.NoError(err) err = f.Close() expect.NoError(err) @@ -89,11 +87,9 @@ var _ = suite("kubernetes/clusters/kubeconfig/save", func(t *testing.T, when spe when("passing expiry-seconds", func() { it("creates a kubeconfig using a token", func() { - f, err := ioutil.TempFile("", "fake-kube-config") + f, err := os.CreateTemp(t.TempDir(), "fake-kube-config") expect.NoError(err) - defer os.Remove(f.Name()) - cmd := exec.Command(builtBinaryPath, "-t", "some-magic-token", "-u", server.URL, @@ -112,7 +108,7 @@ var _ = suite("kubernetes/clusters/kubeconfig/save", func(t *testing.T, when spe output, err := cmd.CombinedOutput() expect.NoError(err, fmt.Sprintf("received error output: %s", output)) - fileBytes, err := ioutil.ReadAll(f) + fileBytes, err := io.ReadAll(f) expect.NoError(err) err = f.Close() expect.NoError(err) @@ -121,11 +117,9 @@ var _ = suite("kubernetes/clusters/kubeconfig/save", func(t *testing.T, when spe }) when("passing alias", func() { it("creates an alias for a config", func() { - f, err := ioutil.TempFile("", "fake-kube-config") + f, err := os.CreateTemp(t.TempDir(), "fake-kube-config") expect.NoError(err) - defer os.Remove(f.Name()) - cmd := exec.Command(builtBinaryPath, "-t", "some-magic-token", "-u", server.URL, @@ -145,7 +139,7 @@ var _ = suite("kubernetes/clusters/kubeconfig/save", func(t *testing.T, when spe expect.NoError(err, fmt.Sprintf("received error output: %s", output)) - fileBytes, err := ioutil.ReadAll(f) + fileBytes, err := io.ReadAll(f) expect.NoError(err) err = f.Close() expect.NoError(err) diff --git a/integration/lb_add_droplets_test.go b/integration/lb_add_droplets_test.go index 3d417951a..7166db4b8 100644 --- a/integration/lb_add_droplets_test.go +++ b/integration/lb_add_droplets_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -36,7 +36,7 @@ var _ = suite("compute/load-balancer/add-droplets", func(t *testing.T, when spec return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(lbAddDropletsRequest, string(reqBody)) diff --git a/integration/lb_add_forwarding_rules_test.go b/integration/lb_add_forwarding_rules_test.go index e8fa2026a..587dd3473 100644 --- a/integration/lb_add_forwarding_rules_test.go +++ b/integration/lb_add_forwarding_rules_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -36,7 +36,7 @@ var _ = suite("compute/load-balancer/add-forwarding-rules", func(t *testing.T, w return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(lbAddForwardingRulesRequest, string(reqBody)) diff --git a/integration/lb_create_test.go b/integration/lb_create_test.go index d44ccff10..3fb54f829 100644 --- a/integration/lb_create_test.go +++ b/integration/lb_create_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -40,7 +40,7 @@ var _ = suite("compute/load-balancer/create", func(t *testing.T, when spec.G, it return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(lbCreateRequest, string(reqBody)) diff --git a/integration/lb_remove_droplets_test.go b/integration/lb_remove_droplets_test.go index af8b2f618..9f81f3bed 100644 --- a/integration/lb_remove_droplets_test.go +++ b/integration/lb_remove_droplets_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -36,7 +36,7 @@ var _ = suite("compute/load-balancer/remove-droplets", func(t *testing.T, when s return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(lbRemoveDropletsRequest, string(reqBody)) diff --git a/integration/lb_remove_forwarding_rules_test.go b/integration/lb_remove_forwarding_rules_test.go index 2e06fba00..1fd982d04 100644 --- a/integration/lb_remove_forwarding_rules_test.go +++ b/integration/lb_remove_forwarding_rules_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -36,7 +36,7 @@ var _ = suite("compute/load-balancer/remove-forwarding-rules", func(t *testing.T return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(lbRemoveForwardingRulesRequest, string(reqBody)) diff --git a/integration/lb_update_test.go b/integration/lb_update_test.go index 76ba64efa..591e4af72 100644 --- a/integration/lb_update_test.go +++ b/integration/lb_update_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -39,7 +39,7 @@ var _ = suite("compute/load-balancer/update", func(t *testing.T, when spec.G, it return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(lbUpdateRequest, string(reqBody)) diff --git a/integration/projects_create_test.go b/integration/projects_create_test.go index 6b4013881..9cce591b2 100644 --- a/integration/projects_create_test.go +++ b/integration/projects_create_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "html/template" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -40,7 +40,7 @@ var _ = suite("projects/create", func(t *testing.T, when spec.G, it spec.S) { return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := struct { diff --git a/integration/projects_resources_assign_test.go b/integration/projects_resources_assign_test.go index 1b8b6e373..a3ee02349 100644 --- a/integration/projects_resources_assign_test.go +++ b/integration/projects_resources_assign_test.go @@ -3,7 +3,7 @@ package integration import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -38,7 +38,7 @@ var _ = suite("projects/resources/assign", func(t *testing.T, when spec.G, it sp return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := struct { diff --git a/integration/projects_update_test.go b/integration/projects_update_test.go index a42af12d2..23ec81bcd 100644 --- a/integration/projects_update_test.go +++ b/integration/projects_update_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "html/template" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -40,7 +40,7 @@ var _ = suite("projects/update", func(t *testing.T, when spec.G, it spec.S) { return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := struct { diff --git a/integration/registry_create_test.go b/integration/registry_create_test.go index ad2b22068..69865fc5c 100644 --- a/integration/registry_create_test.go +++ b/integration/registry_create_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -42,7 +42,7 @@ var _ = suite("registry/create", func(t *testing.T, when spec.G, it spec.S) { return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) var expectedJSON string diff --git a/integration/registry_garbagecollection_test.go b/integration/registry_garbagecollection_test.go index 884b02a03..78a88b857 100644 --- a/integration/registry_garbagecollection_test.go +++ b/integration/registry_garbagecollection_test.go @@ -3,7 +3,7 @@ package integration import ( "encoding/json" "html/template" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -126,7 +126,7 @@ var _ = suite("registry/garbage-collection", func(t *testing.T, when spec.G, it case "/v2/registry/" + validRegistryName + "/garbage-collection/" + validGCUUID: switch req.Method { case http.MethodPut: - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expectJSON := &strings.Builder{} diff --git a/integration/registry_login_test.go b/integration/registry_login_test.go index 08084992d..ddcd083d6 100644 --- a/integration/registry_login_test.go +++ b/integration/registry_login_test.go @@ -3,7 +3,6 @@ package integration import ( "encoding/json" "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/http/httputil" @@ -89,7 +88,7 @@ var _ = suite("registry/login", func(t *testing.T, when spec.G, it spec.S) { output, err := cmd.CombinedOutput() expect.NoError(err) - fileBytes, err := ioutil.ReadFile(config) + fileBytes, err := os.ReadFile(config) expect.NoError(err) var dc dockerConfig @@ -123,7 +122,7 @@ var _ = suite("registry/login", func(t *testing.T, when spec.G, it spec.S) { output, err := cmd.CombinedOutput() expect.NoError(err) - fileBytes, err := ioutil.ReadFile(config) + fileBytes, err := os.ReadFile(config) expect.NoError(err) var dc dockerConfig @@ -159,7 +158,7 @@ var _ = suite("registry/login", func(t *testing.T, when spec.G, it spec.S) { output, err := cmd.CombinedOutput() expect.NoError(err) - fileBytes, err := ioutil.ReadFile(config) + fileBytes, err := os.ReadFile(config) expect.NoError(err) var dc dockerConfig diff --git a/integration/registry_logout_test.go b/integration/registry_logout_test.go index 6c6abe0be..6ed555d47 100644 --- a/integration/registry_logout_test.go +++ b/integration/registry_logout_test.go @@ -2,7 +2,6 @@ package integration import ( "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/http/httputil" @@ -64,7 +63,7 @@ var _ = suite("registry/logout", func(t *testing.T, when spec.G, it spec.S) { tmpDir := t.TempDir() config := filepath.Join(tmpDir, "config.json") - err := ioutil.WriteFile(config, []byte(registryDockerCredentialsResponse), 0600) + err := os.WriteFile(config, []byte(registryDockerCredentialsResponse), 0600) expect.NoError(err) cmd := exec.Command(builtBinaryPath, @@ -80,7 +79,7 @@ var _ = suite("registry/logout", func(t *testing.T, when spec.G, it spec.S) { output, err := cmd.CombinedOutput() expect.NoError(err, string(output)) - fileBytes, err := ioutil.ReadFile(config) + fileBytes, err := os.ReadFile(config) expect.NoError(err) expect.Equal("Removing login credentials for registry.digitalocean.com\n", string(output)) diff --git a/integration/reserved_ip_create_test.go b/integration/reserved_ip_create_test.go index f44838e69..ad7a97efd 100644 --- a/integration/reserved_ip_create_test.go +++ b/integration/reserved_ip_create_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -38,7 +38,7 @@ var _ = suite("compute/reserved-ip/create", func(t *testing.T, when spec.G, it s return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) responseJSON := reservedIPCreateResponse diff --git a/integration/tags_apply_test.go b/integration/tags_apply_test.go index c21d626db..2c7ea7c12 100644 --- a/integration/tags_apply_test.go +++ b/integration/tags_apply_test.go @@ -3,7 +3,7 @@ package integration import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -58,7 +58,7 @@ var _ = suite("compute/tags/apply", func(t *testing.T, when spec.G, it spec.S) { return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := godo.TagResourcesRequest{} @@ -80,7 +80,7 @@ var _ = suite("compute/tags/apply", func(t *testing.T, when spec.G, it spec.S) { return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := godo.TagResourcesRequest{} diff --git a/integration/tags_delete_test.go b/integration/tags_delete_test.go index b0bb3ddcb..acc219b3f 100644 --- a/integration/tags_delete_test.go +++ b/integration/tags_delete_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -37,7 +37,7 @@ var _ = suite("compute/tags/delete", func(t *testing.T, when spec.G, it spec.S) return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.Empty(string(reqBody)) @@ -55,7 +55,7 @@ var _ = suite("compute/tags/delete", func(t *testing.T, when spec.G, it spec.S) return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.Empty(string(reqBody)) diff --git a/integration/tags_remove_test.go b/integration/tags_remove_test.go index 9dc453da9..cf3e5cf59 100644 --- a/integration/tags_remove_test.go +++ b/integration/tags_remove_test.go @@ -3,7 +3,7 @@ package integration import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -58,7 +58,7 @@ var _ = suite("compute/tags/remove", func(t *testing.T, when spec.G, it spec.S) return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := godo.UntagResourcesRequest{} @@ -80,7 +80,7 @@ var _ = suite("compute/tags/remove", func(t *testing.T, when spec.G, it spec.S) return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := godo.UntagResourcesRequest{} diff --git a/integration/volume_create_test.go b/integration/volume_create_test.go index 5450e85aa..684decf1f 100644 --- a/integration/volume_create_test.go +++ b/integration/volume_create_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -38,7 +38,7 @@ var _ = suite("compute/volume/create", func(t *testing.T, when spec.G, it spec.S return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(volumeCreateRequest, string(reqBody)) diff --git a/integration/volume_snapshot_test.go b/integration/volume_snapshot_test.go index 8f829423a..6e5fde70e 100644 --- a/integration/volume_snapshot_test.go +++ b/integration/volume_snapshot_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -42,7 +42,7 @@ var _ = suite("compute/volume/snapshot", func(t *testing.T, when spec.G, it spec return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) expect.JSONEq(volumeSnapshotRequest, string(reqBody)) diff --git a/integration/vpc_create_test.go b/integration/vpc_create_test.go index e66dad045..51dfc37af 100644 --- a/integration/vpc_create_test.go +++ b/integration/vpc_create_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "html/template" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -40,7 +40,7 @@ var _ = suite("vpcs/create", func(t *testing.T, when spec.G, it spec.S) { return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := struct { diff --git a/integration/vpc_update_test.go b/integration/vpc_update_test.go index faa8d095c..3d242ad26 100644 --- a/integration/vpc_update_test.go +++ b/integration/vpc_update_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "html/template" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -40,7 +40,7 @@ var _ = suite("vpcs/update", func(t *testing.T, when spec.G, it spec.S) { return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) expect.NoError(err) request := struct { diff --git a/internal/apps/apps.go b/internal/apps/apps.go index 986a9ddc7..bfe77954b 100644 --- a/internal/apps/apps.go +++ b/internal/apps/apps.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "github.com/digitalocean/godo" @@ -28,7 +27,7 @@ func ReadAppSpec(stdin io.Reader, path string) (*godo.AppSpec, error) { spec = specFile } - byt, err := ioutil.ReadAll(spec) + byt, err := io.ReadAll(spec) if err != nil { return nil, fmt.Errorf("reading app spec: %w", err) } diff --git a/internal/apps/apps_test.go b/internal/apps/apps_test.go index 6c5e67c1d..5576ed31f 100644 --- a/internal/apps/apps_test.go +++ b/internal/apps/apps_test.go @@ -3,7 +3,7 @@ package apps import ( "bytes" "io" - "io/ioutil" + "os" "testing" "github.com/digitalocean/godo" @@ -160,7 +160,7 @@ var validAppSpec = &godo.AppSpec{ func testTempFile(t *testing.T, data []byte) string { t.Helper() file := t.TempDir() + "/file" - err := ioutil.WriteFile(file, data, 0644) + err := os.WriteFile(file, data, 0644) require.NoError(t, err, "writing temp file") return file } diff --git a/internal/apps/builder/cnb_test.go b/internal/apps/builder/cnb_test.go index 326abdd76..31caf2f97 100644 --- a/internal/apps/builder/cnb_test.go +++ b/internal/apps/builder/cnb_test.go @@ -5,8 +5,8 @@ import ( "bytes" "context" "io" - "io/ioutil" "net" + "os" "path/filepath" "strings" "sync" @@ -25,7 +25,7 @@ import ( func TestCNBComponentBuild(t *testing.T) { ctx := context.Background() dockerSocketPath = filepath.Join(t.TempDir(), "docker.sock") - require.NoError(t, ioutil.WriteFile(dockerSocketPath, nil, 0644)) + require.NoError(t, os.WriteFile(dockerSocketPath, nil, 0644)) t.Run("no component", func(t *testing.T) { builder := &CNBComponentBuilder{} @@ -386,7 +386,7 @@ func TestCNBComponentBuild(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - nginxConf, err := ioutil.ReadAll(nginxConfR) + nginxConf, err := io.ReadAll(nginxConfR) require.NoError(t, err) require.Equal(t, ` server { @@ -425,7 +425,7 @@ server { wg.Add(1) go func() { defer wg.Done() - dockerfile, err := ioutil.ReadAll(dockerfileR) + dockerfile, err := io.ReadAll(dockerfileR) require.NoError(t, err) require.Equal(t, ` ARG nginx_image diff --git a/internal/apps/builder/docker.go b/internal/apps/builder/docker.go index b9edc1126..737954b70 100644 --- a/internal/apps/builder/docker.go +++ b/internal/apps/builder/docker.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -173,7 +172,7 @@ func (b *DockerComponentBuilder) buildStaticSiteImage(ctx context.Context) error lw := b.getLogWriter() template.Render(lw, `{{success checkmark}} building static site image with built assets from {{highlight .}}{{nl 2}}`, c.GetOutputDir()) - tmpDir, err := ioutil.TempDir("", "static-*") + tmpDir, err := os.MkdirTemp("", "static-*") if err != nil { return fmt.Errorf("creating temporary build directory: %w", err) } diff --git a/internal/apps/builder/docker_test.go b/internal/apps/builder/docker_test.go index 79ba2f8f4..c8893ab11 100644 --- a/internal/apps/builder/docker_test.go +++ b/internal/apps/builder/docker_test.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "path/filepath" "regexp" @@ -171,7 +170,7 @@ func TestDockerComponentBuild(t *testing.T) { }, NoCache: true, }).Return(types.ImageBuildResponse{ - Body: ioutil.NopCloser(strings.NewReader("")), + Body: io.NopCloser(strings.NewReader("")), }, nil) _, err := builder.Build(ctx) @@ -211,7 +210,7 @@ func TestDockerComponentBuild(t *testing.T) { err := os.Mkdir(filepath.Join(contextDir, "subdir"), 0775) require.NoError(t, err) // Dockerfile is outside of source_dir - err = ioutil.WriteFile(filepath.Join(contextDir, "Dockerfile"), []byte("FROM scratch"), 0664) + err = os.WriteFile(filepath.Join(contextDir, "Dockerfile"), []byte("FROM scratch"), 0664) require.NoError(t, err) builder := &DockerComponentBuilder{ @@ -394,7 +393,7 @@ func assertArchiveContents(t *testing.T, archive io.Reader, tcs map[string]func( t.Fatalf("unexpected file %s", name) } - content, err := ioutil.ReadAll(r) + content, err := io.ReadAll(r) require.NoError(t, err, "reading %s", name) filesFound[name] = struct{}{} diff --git a/internal/apps/config/appdev.go b/internal/apps/config/appdev.go index 51289f532..86069f279 100644 --- a/internal/apps/config/appdev.go +++ b/internal/apps/config/appdev.go @@ -3,7 +3,6 @@ package config import ( "bytes" "errors" - "io/ioutil" "os" "regexp" "time" @@ -85,7 +84,7 @@ func ensureStringInFile(file string, val string) error { return err } - b, err := ioutil.ReadFile(file) + b, err := os.ReadFile(file) if err != nil { return err } diff --git a/internal/apps/workspace/workspace.go b/internal/apps/workspace/workspace.go index 2f18251ed..ed8c5bfc1 100644 --- a/internal/apps/workspace/workspace.go +++ b/internal/apps/workspace/workspace.go @@ -5,7 +5,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -350,7 +349,7 @@ func ensureStringInFile(file string, val string) error { return err } - b, err := ioutil.ReadFile(file) + b, err := os.ReadFile(file) if err != nil { return err } diff --git a/internal/apps/workspace/workspace_test.go b/internal/apps/workspace/workspace_test.go index e486a6f1e..4f2fceea1 100644 --- a/internal/apps/workspace/workspace_test.go +++ b/internal/apps/workspace/workspace_test.go @@ -1,7 +1,6 @@ package workspace import ( - "io/ioutil" "os" "testing" @@ -55,7 +54,7 @@ func Test_ensureStringInFile(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - file, err := ioutil.TempFile("", "dev-config.*.yaml") + file, err := os.CreateTemp("", "dev-config.*.yaml") require.NoError(t, err, "creating temp file") file.Close() @@ -71,7 +70,7 @@ func Test_ensureStringInFile(t *testing.T) { err = ensureStringInFile(file.Name(), ensureValue) require.NoError(t, err, "ensuring string in file") - b, err := ioutil.ReadFile(file.Name()) + b, err := os.ReadFile(file.Name()) require.NoError(t, err) require.Equal(t, string(tc.expect), string(b)) }) diff --git a/pkg/extract/extract_test.go b/pkg/extract/extract_test.go index 550d32b4f..37e12814b 100644 --- a/pkg/extract/extract_test.go +++ b/pkg/extract/extract_test.go @@ -6,7 +6,6 @@ import ( "compress/gzip" "fmt" "io" - "io/ioutil" "os" "path/filepath" "testing" @@ -16,20 +15,12 @@ import ( ) func TestExtractTarGz(t *testing.T) { - tmp, err := ioutil.TempDir("", "test-materials") - require.NoError(t, err, "error creating tmp dir") - out, err := ioutil.TempDir("", "output") - require.NoError(t, err, "error creating out dir") - defer func() { - err := os.RemoveAll(tmp) - require.NoError(t, err, "error cleaning tmp dir") - err = os.RemoveAll(out) - require.NoError(t, err, "error cleaning out dir") - }() + tmp := t.TempDir() + out := t.TempDir() files := []string{"test.txt", "test/test.txt"} testTarGz := setUpTarGz(t, tmp, files) - err = Extract(testTarGz, out) + err := Extract(testTarGz, out) require.NoError(t, err, "error extracting archive") for _, f := range files { @@ -40,20 +31,12 @@ func TestExtractTarGz(t *testing.T) { } func TestExtractZip(t *testing.T) { - tmp, err := ioutil.TempDir("", "test-materials") - require.NoError(t, err, "error creating tmp dir") - out, err := ioutil.TempDir("", "output") - require.NoError(t, err, "error creating out dir") - defer func() { - err := os.RemoveAll(tmp) - require.NoError(t, err, "error cleaning tmp dir") - err = os.RemoveAll(out) - require.NoError(t, err, "error cleaning out dir") - }() + tmp := t.TempDir() + out := t.TempDir() files := []string{"test.txt", "test/test.txt"} testZip := setUpZip(t, tmp, files) - err = Extract(testZip, out) + err := Extract(testZip, out) require.NoError(t, err, "error extracting archive") for _, f := range files {