Skip to content

Commit

Permalink
Merge branch 'main' into chore/replace-deprecated-command-with-enviro…
Browse files Browse the repository at this point in the history
…nment-file
  • Loading branch information
andrewsomething authored Oct 3, 2023
2 parents bd05db6 + 68b97c8 commit 764b641
Show file tree
Hide file tree
Showing 84 changed files with 221 additions and 322 deletions.
3 changes: 1 addition & 2 deletions commands/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions commands/apps_dev_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package commands

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -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
}
28 changes: 9 additions & 19 deletions commands/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/url"
"os"
"testing"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -439,8 +432,8 @@ func TestRunAppsGetLogs(t *testing.T) {

tc := config.Doit.(*doctl.TestConfig)
tc.ListenFn = func(url *url.URL, token string, schemaFunc listen.SchemaFunc, out io.Writer) listen.ListenerService {
assert.Equal(t, token, "aa-bb-11-cc-33")
assert.Equal(t, url.String(), "wss://proxy-apps-prod-ams3-001.ondigitalocean.app/?token=aa-bb-11-cc-33")
assert.Equal(t, "aa-bb-11-cc-33", token)
assert.Equal(t, "wss://proxy-apps-prod-ams3-001.ondigitalocean.app/?token=aa-bb-11-cc-33", url.String())
return tm.listen
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions commands/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"bufio"
"bytes"
"io"
"io/ioutil"
"path/filepath"
"testing"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -98,7 +97,7 @@ func TestAuthInitConfig(t *testing.T) {
"unset": map[interface{}]interface{}{"dev-config": ""},
},
)
assert.Equal(t, devConfigSetting, expectedConfigSetting, "unexpected setting for 'dev.config'")
assert.Equal(t, expectedConfigSetting, devConfigSetting, "unexpected setting for 'dev.config'")
})
}

Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions commands/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
package commands

import (
"io/ioutil"
"os"

"github.com/digitalocean/doctl"
"github.com/digitalocean/doctl/commands/displayers"
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions commands/certificates_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package commands

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
package commands

import (
"io/ioutil"
"io"
"sort"
"testing"

Expand Down Expand Up @@ -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 },
Expand Down
4 changes: 2 additions & 2 deletions commands/droplets.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package commands

import (
"fmt"
"io/ioutil"
"os"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions commands/droplets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package commands

import (
"bytes"
"io/ioutil"
"os"
"strconv"
"testing"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions commands/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package commands

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

"github.com/digitalocean/doctl"
"github.com/digitalocean/doctl/commands/displayers"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions commands/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ limitations under the License.
package commands

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion commands/monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestAlertPolicyCreate_ValidTypes(t *testing.T) {
config.Doit.Set(config.NS, doctl.ArgAlertPolicySlackURLs, slackURLsStr)

err := RunCmdAlertPolicyCreate(config)
assert.Equal(t, err, tt.expectedErr)
assert.Equal(t, tt.expectedErr, err)
})
}
}
Expand Down
6 changes: 1 addition & 5 deletions commands/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,7 @@ func TestRegistryLogin(t *testing.T) {

config.Out = os.Stderr
err := RunRegistryLogin(config)
if test.err != nil {
assert.Error(t, test.err, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, test.err, err)
})
})
}
Expand Down
19 changes: 4 additions & 15 deletions commands/serverless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"context"
"errors"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions commands/sshkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
package commands

import (
"io/ioutil"
"os"

"github.com/digitalocean/doctl"
"github.com/digitalocean/doctl/commands/displayers"
Expand Down Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 764b641

Please sign in to comment.