Replace ioutil with io and os (#5498)

This commit is contained in:
Håvard Anda Estensen 2022-04-26 13:07:44 +02:00 committed by GitHub
parent 6edb4ecdbb
commit 58cb773e09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
155 changed files with 1165 additions and 1197 deletions

View file

@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -73,7 +72,7 @@ func CacheResponse(ttl time.Duration, dir string) ClientOption {
func copyStream(r io.ReadCloser) (io.ReadCloser, io.ReadCloser) {
b := &bytes.Buffer{}
nr := io.TeeReader(r, b)
return ioutil.NopCloser(b), &readCloser{
return io.NopCloser(b), &readCloser{
Reader: nr,
Closer: r,
}

View file

@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"path/filepath"
"testing"
@ -26,7 +25,7 @@ func Test_CacheResponse(t *testing.T) {
}
return &http.Response{
StatusCode: status,
Body: ioutil.NopCloser(bytes.NewBufferString(body)),
Body: io.NopCloser(bytes.NewBufferString(body)),
}, nil
},
}
@ -44,7 +43,7 @@ func Test_CacheResponse(t *testing.T) {
return "", err
}
defer res.Body.Close()
resBody, err := ioutil.ReadAll(res.Body)
resBody, err := io.ReadAll(res.Body)
if err != nil {
err = fmt.Errorf("ReadAll: %w", err)
}

View file

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"regexp"
@ -343,7 +342,7 @@ func (c Client) RESTWithNext(hostname string, method string, p string, body io.R
return "", nil
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
@ -379,7 +378,7 @@ func handleResponse(resp *http.Response, data interface{}) error {
return HandleHTTPError(resp)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
@ -408,7 +407,7 @@ func HandleHTTPError(resp *http.Response) error {
return httpError
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
httpError.Message = err.Error()
return httpError

View file

@ -3,7 +3,7 @@ package api
import (
"bytes"
"errors"
"io/ioutil"
"io"
"net/http"
"testing"
@ -35,7 +35,7 @@ func TestGraphQL(t *testing.T) {
assert.Equal(t, "hubot", response.Viewer.Login)
req := http.Requests[0]
reqBody, _ := ioutil.ReadAll(req.Body)
reqBody, _ := io.ReadAll(req.Body)
assert.Equal(t, `{"query":"QUERY","variables":{"name":"Mona"}}`, string(reqBody))
assert.Equal(t, "token OTOKEN", req.Header.Get("Authorization"))
}
@ -116,7 +116,7 @@ func TestRESTError(t *testing.T) {
return &http.Response{
Request: req,
StatusCode: 422,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"message": "OH NO"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"message": "OH NO"}`)),
Header: map[string][]string{
"Content-Type": {"application/json; charset=utf-8"},
},
@ -146,7 +146,7 @@ func TestHandleHTTPError_GraphQL502(t *testing.T) {
resp := &http.Response{
Request: req,
StatusCode: 502,
Body: ioutil.NopCloser(bytes.NewBufferString(`{ "data": null, "errors": [{ "message": "Something went wrong" }] }`)),
Body: io.NopCloser(bytes.NewBufferString(`{ "data": null, "errors": [{ "message": "Something went wrong" }] }`)),
Header: map[string][]string{"Content-Type": {"application/json"}},
}
err = HandleHTTPError(resp)
@ -164,7 +164,7 @@ func TestHTTPError_ScopesSuggestion(t *testing.T) {
return &http.Response{
Request: req,
StatusCode: s,
Body: ioutil.NopCloser(bytes.NewBufferString(`{}`)),
Body: io.NopCloser(bytes.NewBufferString(`{}`)),
Header: map[string][]string{
"Content-Type": {"application/json"},
"X-Oauth-Scopes": {haveScopes},

View file

@ -40,9 +40,9 @@ func run(args []string) error {
return fmt.Errorf("error: --doc-path not set")
}
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
rootCmd := root.NewCmdRoot(&cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
Browser: &browser{},
}, "", "")
rootCmd.InitDefaultHelpCmd()

View file

@ -1,7 +1,7 @@
package main
import (
"io/ioutil"
"os"
"strings"
"testing"
)
@ -14,7 +14,7 @@ func Test_run(t *testing.T) {
t.Fatalf("got error: %v", err)
}
manPage, err := ioutil.ReadFile(dir + "/gh-issue-create.1")
manPage, err := os.ReadFile(dir + "/gh-issue-create.1")
if err != nil {
t.Fatalf("error reading `gh-issue-create.1`: %v", err)
}
@ -22,7 +22,7 @@ func Test_run(t *testing.T) {
t.Fatal("man page corrupted")
}
markdownPage, err := ioutil.ReadFile(dir + "/gh_issue_create.md")
markdownPage, err := os.ReadFile(dir + "/gh_issue_create.md")
if err != nil {
t.Fatalf("error reading `gh_issue_create.md`: %v", err)
}

View file

@ -33,7 +33,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"reflect"
@ -115,7 +114,7 @@ func (a *API) GetUser(ctx context.Context) (*User, error) {
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}
@ -153,7 +152,7 @@ func (a *API) GetRepository(ctx context.Context, nwo string) (*Repository, error
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}
@ -366,7 +365,7 @@ func (a *API) GetCodespace(ctx context.Context, codespaceName string, includeCon
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}
@ -464,7 +463,7 @@ func (a *API) GetCodespacesMachines(ctx context.Context, repoID int, branch, loc
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}
@ -676,7 +675,7 @@ func (a *API) startCreate(ctx context.Context, params *CreateCodespaceParams) (*
r = io.TeeReader(resp.Body, bodyCopy)
)
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}
@ -688,7 +687,7 @@ func (a *API) startCreate(ctx context.Context, params *CreateCodespaceParams) (*
return nil, ue
}
resp.Body = ioutil.NopCloser(bodyCopy)
resp.Body = io.NopCloser(bodyCopy)
return nil, api.HandleHTTPError(resp)
@ -696,7 +695,7 @@ func (a *API) startCreate(ctx context.Context, params *CreateCodespaceParams) (*
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}
@ -840,7 +839,7 @@ func (a *API) EditCodespace(ctx context.Context, codespaceName string, params *E
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}
@ -888,7 +887,7 @@ func (a *API) GetCodespaceRepositoryContents(ctx context.Context, codespace *Cod
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}
@ -924,7 +923,7 @@ func (a *API) AuthorizedKeys(ctx context.Context, user string) ([]byte, error) {
return nil, fmt.Errorf("server returned %s", resp.Status)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}

View file

@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"strings"
@ -39,7 +39,7 @@ type PostCreateState struct {
// and calls the supplied poller for each batch of state changes.
// It runs until it encounters an error, including cancellation of the context.
func PollPostCreateStates(ctx context.Context, progress progressIndicator, apiClient apiClient, codespace *api.Codespace, poller func([]PostCreateState)) (err error) {
noopLogger := log.New(ioutil.Discard, "", 0)
noopLogger := log.New(io.Discard, "", 0)
session, err := ConnectToLiveshare(ctx, progress, noopLogger, apiClient, codespace)
if err != nil {

View file

@ -3,7 +3,7 @@ package config
import (
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"runtime"
@ -182,7 +182,7 @@ var ReadConfigFile = func(filename string) ([]byte, error) {
}
defer f.Close()
data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
return nil, err
}

View file

@ -3,7 +3,6 @@ package config
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@ -257,13 +256,13 @@ func Test_configFile_Write_toDisk(t *testing.T) {
}
expectedConfig := "pager: less\n"
if configBytes, err := ioutil.ReadFile(filepath.Join(configDir, "config.yml")); err != nil {
if configBytes, err := os.ReadFile(filepath.Join(configDir, "config.yml")); err != nil {
t.Error(err)
} else if string(configBytes) != expectedConfig {
t.Errorf("expected config.yml %q, got %q", expectedConfig, string(configBytes))
}
if configBytes, err := ioutil.ReadFile(filepath.Join(configDir, "hosts.yml")); err != nil {
if configBytes, err := os.ReadFile(filepath.Join(configDir, "hosts.yml")); err != nil {
t.Error(err)
} else if string(configBytes) != "" {
t.Errorf("unexpected hosts.yml: %q", string(configBytes))
@ -288,7 +287,7 @@ func Test_configFile_WriteHosts_toDisk(t *testing.T) {
}
expectedConfig := "github.com:\n user: monalisa\n oauth_token: TOKEN\n"
actualConfig, err := ioutil.ReadFile(filepath.Join(configDir, "hosts.yml"))
actualConfig, err := os.ReadFile(filepath.Join(configDir, "hosts.yml"))
assert.NoError(t, err)
assert.Equal(t, expectedConfig, string(actualConfig))
_, nonExistErr := os.Stat(filepath.Join(configDir, "config.yml"))
@ -310,7 +309,7 @@ func Test_autoMigrateConfigDir_noMigration_notExist(t *testing.T) {
err := autoMigrateConfigDir(migrateDir)
assert.Equal(t, errNotExist, err)
files, err := ioutil.ReadDir(migrateDir)
files, err := os.ReadDir(migrateDir)
assert.NoError(t, err)
assert.Equal(t, 0, len(files))
}
@ -332,7 +331,7 @@ func Test_autoMigrateConfigDir_noMigration_samePath(t *testing.T) {
err = autoMigrateConfigDir(migrateDir)
assert.Equal(t, errSamePath, err)
files, err := ioutil.ReadDir(migrateDir)
files, err := os.ReadDir(migrateDir)
assert.NoError(t, err)
assert.Equal(t, 0, len(files))
}
@ -353,17 +352,17 @@ func Test_autoMigrateConfigDir_migration(t *testing.T) {
err := os.MkdirAll(homeConfigDir, 0755)
assert.NoError(t, err)
f, err := ioutil.TempFile(homeConfigDir, "")
f, err := os.CreateTemp(homeConfigDir, "")
assert.NoError(t, err)
f.Close()
err = autoMigrateConfigDir(migrateConfigDir)
assert.NoError(t, err)
_, err = ioutil.ReadDir(homeConfigDir)
_, err = os.ReadDir(homeConfigDir)
assert.True(t, os.IsNotExist(err))
files, err := ioutil.ReadDir(migrateConfigDir)
files, err := os.ReadDir(migrateConfigDir)
assert.NoError(t, err)
assert.Equal(t, 1, len(files))
}
@ -452,7 +451,7 @@ func Test_autoMigrateStateDir_noMigration_notExist(t *testing.T) {
err := autoMigrateStateDir(migrateDir)
assert.Equal(t, errNotExist, err)
files, err := ioutil.ReadDir(migrateDir)
files, err := os.ReadDir(migrateDir)
assert.NoError(t, err)
assert.Equal(t, 0, len(files))
}
@ -474,7 +473,7 @@ func Test_autoMigrateStateDir_noMigration_samePath(t *testing.T) {
err = autoMigrateStateDir(migrateDir)
assert.Equal(t, errSamePath, err)
files, err := ioutil.ReadDir(migrateDir)
files, err := os.ReadDir(migrateDir)
assert.NoError(t, err)
assert.Equal(t, 0, len(files))
}
@ -495,17 +494,17 @@ func Test_autoMigrateStateDir_migration(t *testing.T) {
err := os.MkdirAll(homeConfigDir, 0755)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(homeConfigDir, "state.yml"), nil, 0755)
err = os.WriteFile(filepath.Join(homeConfigDir, "state.yml"), nil, 0755)
assert.NoError(t, err)
err = autoMigrateStateDir(migrateStateDir)
assert.NoError(t, err)
files, err := ioutil.ReadDir(homeConfigDir)
files, err := os.ReadDir(homeConfigDir)
assert.NoError(t, err)
assert.Equal(t, 0, len(files))
files, err = ioutil.ReadDir(migrateStateDir)
files, err = os.ReadDir(migrateStateDir)
assert.NoError(t, err)
assert.Equal(t, 1, len(files))
assert.Equal(t, "state.yml", files[0].Name())

View file

@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -116,7 +115,7 @@ func TestManPrintFlagsHidesShortDeprecated(t *testing.T) {
func TestGenManTree(t *testing.T) {
c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}
tmpdir, err := ioutil.TempDir("", "test-gen-man-tree")
tmpdir, err := os.MkdirTemp("", "test-gen-man-tree")
if err != nil {
t.Fatalf("Failed to create tmpdir: %s", err.Error())
}
@ -147,7 +146,7 @@ func assertLineFound(scanner *bufio.Scanner, expectedLine string) error {
}
func BenchmarkGenManToFile(b *testing.B) {
file, err := ioutil.TempFile(b.TempDir(), "")
file, err := os.CreateTemp(b.TempDir(), "")
if err != nil {
b.Fatal(err)
}

View file

@ -2,7 +2,6 @@ package docs
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -67,7 +66,7 @@ func TestGenMdNoHiddenParents(t *testing.T) {
func TestGenMdTree(t *testing.T) {
c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}
tmpdir, err := ioutil.TempDir("", "test-gen-md-tree")
tmpdir, err := os.MkdirTemp("", "test-gen-md-tree")
if err != nil {
t.Fatalf("Failed to create tmpdir: %v", err)
}
@ -83,7 +82,7 @@ func TestGenMdTree(t *testing.T) {
}
func BenchmarkGenMarkdownToFile(b *testing.B) {
file, err := ioutil.TempFile(b.TempDir(), "")
file, err := os.CreateTemp(b.TempDir(), "")
if err != nil {
b.Fatal(err)
}

View file

@ -2,7 +2,6 @@ package update
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
@ -65,7 +64,7 @@ func getLatestReleaseInfo(client *api.Client, repo string) (*ReleaseInfo, error)
}
func getStateEntry(stateFilePath string) (*StateEntry, error) {
content, err := ioutil.ReadFile(stateFilePath)
content, err := os.ReadFile(stateFilePath)
if err != nil {
return nil, err
}
@ -91,7 +90,7 @@ func setStateEntry(stateFilePath string, t time.Time, r ReleaseInfo) error {
return err
}
err = ioutil.WriteFile(stateFilePath, content, 0600)
err = os.WriteFile(stateFilePath, content, 0600)
return err
}

View file

@ -2,7 +2,6 @@ package update
import (
"fmt"
"io/ioutil"
"log"
"os"
"testing"
@ -117,7 +116,7 @@ func TestCheckForUpdate(t *testing.T) {
}
func tempFilePath() string {
file, err := ioutil.TempFile("", "")
file, err := os.CreateTemp("", "")
if err != nil {
log.Fatal(err)
}

View file

@ -2,7 +2,7 @@ package delete
import (
"bytes"
"io/ioutil"
"io"
"testing"
"github.com/MakeNowJust/heredoc"
@ -48,17 +48,17 @@ func TestAliasDelete(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer config.StubWriteConfig(ioutil.Discard, ioutil.Discard)()
defer config.StubWriteConfig(io.Discard, io.Discard)()
cfg := config.NewFromString(tt.config)
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
Config: func() (config.Config, error) {
return cfg, nil
},
@ -71,8 +71,8 @@ func TestAliasDelete(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {

View file

@ -2,7 +2,7 @@ package list
import (
"bytes"
"io/ioutil"
"io"
"testing"
"github.com/MakeNowJust/heredoc"
@ -46,17 +46,17 @@ func TestAliasList(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
// TODO: change underlying config implementation so Write is not
// automatically called when editing aliases in-memory
defer config.StubWriteConfig(ioutil.Discard, ioutil.Discard)()
defer config.StubWriteConfig(io.Discard, io.Discard)()
cfg := config.NewFromString(tt.config)
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
Config: func() (config.Config, error) {
return cfg, nil
},
@ -66,8 +66,8 @@ func TestAliasList(t *testing.T) {
cmd.SetArgs([]string{})
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err := cmd.ExecuteC()
if tt.wantErr {

View file

@ -2,7 +2,7 @@ package set
import (
"fmt"
"io/ioutil"
"io"
"strings"
"github.com/MakeNowJust/heredoc"
@ -162,7 +162,7 @@ func setRun(opts *SetOptions) error {
func getExpansion(opts *SetOptions) (string, error) {
if opts.Expansion == "-" {
stdin, err := ioutil.ReadAll(opts.IO.In)
stdin, err := io.ReadAll(opts.IO.In)
if err != nil {
return "", fmt.Errorf("failed to read from STDIN: %w", err)
}

View file

@ -2,7 +2,7 @@ package set
import (
"bytes"
"io/ioutil"
"io"
"testing"
"github.com/MakeNowJust/heredoc"
@ -18,14 +18,14 @@ import (
)
func runCommand(cfg config.Config, isTTY bool, cli string, in string) (*test.CmdOut, error) {
io, stdin, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, stdin, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
stdin.WriteString(in)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
Config: func() (config.Config, error) {
return cfg, nil
},
@ -59,8 +59,8 @@ func runCommand(cfg config.Config, isTTY bool, cli string, in string) (*test.Cmd
rootCmd.SetArgs(argv)
rootCmd.SetIn(stdin)
rootCmd.SetOut(ioutil.Discard)
rootCmd.SetErr(ioutil.Discard)
rootCmd.SetOut(io.Discard)
rootCmd.SetErr(io.Discard)
_, err = rootCmd.ExecuteC()
return &test.CmdOut{
@ -70,7 +70,7 @@ func runCommand(cfg config.Config, isTTY bool, cli string, in string) (*test.Cmd
}
func TestAliasSet_gh_command(t *testing.T) {
defer config.StubWriteConfig(ioutil.Discard, ioutil.Discard)()
defer config.StubWriteConfig(io.Discard, io.Discard)()
cfg := config.NewFromString(``)
@ -80,7 +80,7 @@ func TestAliasSet_gh_command(t *testing.T) {
func TestAliasSet_empty_aliases(t *testing.T) {
mainBuf := bytes.Buffer{}
defer config.StubWriteConfig(&mainBuf, ioutil.Discard)()
defer config.StubWriteConfig(&mainBuf, io.Discard)()
cfg := config.NewFromString(heredoc.Doc(`
aliases:
@ -107,7 +107,7 @@ editor: vim
func TestAliasSet_existing_alias(t *testing.T) {
mainBuf := bytes.Buffer{}
defer config.StubWriteConfig(&mainBuf, ioutil.Discard)()
defer config.StubWriteConfig(&mainBuf, io.Discard)()
cfg := config.NewFromString(heredoc.Doc(`
aliases:
@ -123,7 +123,7 @@ func TestAliasSet_existing_alias(t *testing.T) {
func TestAliasSet_space_args(t *testing.T) {
mainBuf := bytes.Buffer{}
defer config.StubWriteConfig(&mainBuf, ioutil.Discard)()
defer config.StubWriteConfig(&mainBuf, io.Discard)()
cfg := config.NewFromString(``)
@ -159,7 +159,7 @@ func TestAliasSet_arg_processing(t *testing.T) {
for _, c := range cases {
t.Run(c.Cmd, func(t *testing.T) {
mainBuf := bytes.Buffer{}
defer config.StubWriteConfig(&mainBuf, ioutil.Discard)()
defer config.StubWriteConfig(&mainBuf, io.Discard)()
cfg := config.NewFromString(``)
@ -178,7 +178,7 @@ func TestAliasSet_arg_processing(t *testing.T) {
func TestAliasSet_init_alias_cfg(t *testing.T) {
mainBuf := bytes.Buffer{}
defer config.StubWriteConfig(&mainBuf, ioutil.Discard)()
defer config.StubWriteConfig(&mainBuf, io.Discard)()
cfg := config.NewFromString(heredoc.Doc(`
editor: vim
@ -199,7 +199,7 @@ aliases:
func TestAliasSet_existing_aliases(t *testing.T) {
mainBuf := bytes.Buffer{}
defer config.StubWriteConfig(&mainBuf, ioutil.Discard)()
defer config.StubWriteConfig(&mainBuf, io.Discard)()
cfg := config.NewFromString(heredoc.Doc(`
aliases:
@ -221,7 +221,7 @@ func TestAliasSet_existing_aliases(t *testing.T) {
}
func TestAliasSet_invalid_command(t *testing.T) {
defer config.StubWriteConfig(ioutil.Discard, ioutil.Discard)()
defer config.StubWriteConfig(io.Discard, io.Discard)()
cfg := config.NewFromString(``)
@ -231,7 +231,7 @@ func TestAliasSet_invalid_command(t *testing.T) {
func TestShellAlias_flag(t *testing.T) {
mainBuf := bytes.Buffer{}
defer config.StubWriteConfig(&mainBuf, ioutil.Discard)()
defer config.StubWriteConfig(&mainBuf, io.Discard)()
cfg := config.NewFromString(``)
@ -251,7 +251,7 @@ func TestShellAlias_flag(t *testing.T) {
func TestShellAlias_bang(t *testing.T) {
mainBuf := bytes.Buffer{}
defer config.StubWriteConfig(&mainBuf, ioutil.Discard)()
defer config.StubWriteConfig(&mainBuf, io.Discard)()
cfg := config.NewFromString(``)
@ -269,7 +269,7 @@ func TestShellAlias_bang(t *testing.T) {
func TestShellAlias_from_stdin(t *testing.T) {
mainBuf := bytes.Buffer{}
defer config.StubWriteConfig(&mainBuf, ioutil.Discard)()
defer config.StubWriteConfig(&mainBuf, io.Discard)()
cfg := config.NewFromString(``)
@ -326,16 +326,15 @@ func TestShellAlias_getExpansion(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
io.SetStdinTTY(false)
ios, stdin, _, _ := iostreams.Test()
ios.SetStdinTTY(false)
_, err := stdin.WriteString(tt.stdin)
assert.NoError(t, err)
expansion, err := getExpansion(&SetOptions{
Expansion: tt.expansionArg,
IO: io,
IO: ios,
})
assert.NoError(t, err)

View file

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"regexp"
@ -80,7 +79,7 @@ func NewCmdApi(f *cmdutil.Factory, runF func(*ApiOptions) error) *cobra.Command
The default HTTP request method is "GET" normally and "POST" if any parameters
were added. Override the method with %[1]s--method%[1]s.
Pass one or more %[1]s-f/--raw-field%[1]s values in "key=value" format to add static string
Pass one or more %[1]s-f/--raw-field%[1]s values in "key=value" format to add static string
parameters to the request payload. To add non-string or otherwise dynamic values, see
%[1]s--field%[1]s below. Note that adding request parameters will automatically switch the
request method to POST. To send the parameters as a GET query string instead, use
@ -275,7 +274,7 @@ func apiRun(opts *ApiOptions) error {
headersOutputStream := opts.IO.Out
if opts.Silent {
opts.IO.Out = ioutil.Discard
opts.IO.Out = io.Discard
} else {
if err := opts.IO.StartPager(); err == nil {
defer opts.IO.StopPager()
@ -536,7 +535,7 @@ func openUserFile(fn string, stdin io.ReadCloser) (io.ReadCloser, int64, error)
func parseErrorResponse(r io.Reader, statusCode int) (io.Reader, string, error) {
bodyCopy := &bytes.Buffer{}
b, err := ioutil.ReadAll(io.TeeReader(r, bodyCopy))
b, err := io.ReadAll(io.TeeReader(r, bodyCopy))
if err != nil {
return r, "", err
}

View file

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
@ -368,7 +368,7 @@ func Test_apiRun(t *testing.T) {
name: "success",
httpResponse: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`bam!`)),
Body: io.NopCloser(bytes.NewBufferString(`bam!`)),
},
err: nil,
stdout: `bam!`,
@ -383,7 +383,7 @@ func Test_apiRun(t *testing.T) {
Proto: "HTTP/1.1",
Status: "200 Okey-dokey",
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`body`)),
Body: io.NopCloser(bytes.NewBufferString(`body`)),
Header: http.Header{"Content-Type": []string{"text/plain"}},
},
err: nil,
@ -404,7 +404,7 @@ func Test_apiRun(t *testing.T) {
name: "REST error",
httpResponse: &http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"message": "THIS IS FINE"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"message": "THIS IS FINE"}`)),
Header: http.Header{"Content-Type": []string{"application/json; charset=utf-8"}},
},
err: cmdutil.SilentError,
@ -415,7 +415,7 @@ func Test_apiRun(t *testing.T) {
name: "REST string errors",
httpResponse: &http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"errors": ["ALSO", "FINE"]}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"errors": ["ALSO", "FINE"]}`)),
Header: http.Header{"Content-Type": []string{"application/json; charset=utf-8"}},
},
err: cmdutil.SilentError,
@ -429,7 +429,7 @@ func Test_apiRun(t *testing.T) {
},
httpResponse: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"errors": [{"message":"AGAIN"}, {"message":"FINE"}]}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"errors": [{"message":"AGAIN"}, {"message":"FINE"}]}`)),
Header: http.Header{"Content-Type": []string{"application/json; charset=utf-8"}},
},
err: cmdutil.SilentError,
@ -440,7 +440,7 @@ func Test_apiRun(t *testing.T) {
name: "failure",
httpResponse: &http.Response{
StatusCode: 502,
Body: ioutil.NopCloser(bytes.NewBufferString(`gateway timeout`)),
Body: io.NopCloser(bytes.NewBufferString(`gateway timeout`)),
},
err: cmdutil.SilentError,
stdout: `gateway timeout`,
@ -453,7 +453,7 @@ func Test_apiRun(t *testing.T) {
},
httpResponse: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`body`)),
Body: io.NopCloser(bytes.NewBufferString(`body`)),
},
err: nil,
stdout: ``,
@ -469,7 +469,7 @@ func Test_apiRun(t *testing.T) {
Proto: "HTTP/1.1",
Status: "200 Okey-dokey",
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`body`)),
Body: io.NopCloser(bytes.NewBufferString(`body`)),
Header: http.Header{"Content-Type": []string{"text/plain"}},
},
err: nil,
@ -483,7 +483,7 @@ func Test_apiRun(t *testing.T) {
},
httpResponse: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"status":"not a cat"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"status":"not a cat"}`)),
Header: http.Header{"Content-Type": []string{"application/json"}},
},
err: nil,
@ -497,7 +497,7 @@ func Test_apiRun(t *testing.T) {
},
httpResponse: &http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"message": "THIS IS FINE"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"message": "THIS IS FINE"}`)),
Header: http.Header{"Content-Type": []string{"application/json; charset=utf-8"}},
},
err: cmdutil.SilentError,
@ -511,7 +511,7 @@ func Test_apiRun(t *testing.T) {
},
httpResponse: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`[{"name":"Mona"},{"name":"Hubot"}]`)),
Body: io.NopCloser(bytes.NewBufferString(`[{"name":"Mona"},{"name":"Hubot"}]`)),
Header: http.Header{"Content-Type": []string{"application/json"}},
},
err: nil,
@ -525,7 +525,7 @@ func Test_apiRun(t *testing.T) {
},
httpResponse: &http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"message": "THIS IS FINE"}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"message": "THIS IS FINE"}`)),
Header: http.Header{"Content-Type": []string{"application/json; charset=utf-8"}},
},
err: cmdutil.SilentError,
@ -536,9 +536,9 @@ func Test_apiRun(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
tt.options.IO = io
tt.options.IO = ios
tt.options.Config = func() (config.Config, error) { return config.NewBlankConfig(), nil }
tt.options.HttpClient = func() (*http.Client, error) {
var tr roundTripper = func(req *http.Request) (*http.Response, error) {
@ -565,33 +565,33 @@ func Test_apiRun(t *testing.T) {
}
func Test_apiRun_paginationREST(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
requestCount := 0
responses := []*http.Response{
{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"page":1}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"page":1}`)),
Header: http.Header{
"Link": []string{`<https://api.github.com/repositories/1227/issues?page=2>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
},
},
{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"page":2}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"page":2}`)),
Header: http.Header{
"Link": []string{`<https://api.github.com/repositories/1227/issues?page=3>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
},
},
{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"page":3}`)),
Body: io.NopCloser(bytes.NewBufferString(`{"page":3}`)),
Header: http.Header{},
},
}
options := ApiOptions{
IO: io,
IO: ios,
HttpClient: func() (*http.Client, error) {
var tr roundTripper = func(req *http.Request) (*http.Response, error) {
resp := responses[requestCount]
@ -624,14 +624,14 @@ func Test_apiRun_paginationREST(t *testing.T) {
}
func Test_apiRun_paginationGraphQL(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
requestCount := 0
responses := []*http.Response{
{
StatusCode: 200,
Header: http.Header{"Content-Type": []string{`application/json`}},
Body: ioutil.NopCloser(bytes.NewBufferString(`{
Body: io.NopCloser(bytes.NewBufferString(`{
"data": {
"nodes": ["page one"],
"pageInfo": {
@ -644,7 +644,7 @@ func Test_apiRun_paginationGraphQL(t *testing.T) {
{
StatusCode: 200,
Header: http.Header{"Content-Type": []string{`application/json`}},
Body: ioutil.NopCloser(bytes.NewBufferString(`{
Body: io.NopCloser(bytes.NewBufferString(`{
"data": {
"nodes": ["page two"],
"pageInfo": {
@ -657,7 +657,7 @@ func Test_apiRun_paginationGraphQL(t *testing.T) {
}
options := ApiOptions{
IO: io,
IO: ios,
HttpClient: func() (*http.Client, error) {
var tr roundTripper = func(req *http.Request) (*http.Response, error) {
resp := responses[requestCount]
@ -687,14 +687,14 @@ func Test_apiRun_paginationGraphQL(t *testing.T) {
Variables map[string]interface{}
}
bb, err := ioutil.ReadAll(responses[0].Request.Body)
bb, err := io.ReadAll(responses[0].Request.Body)
require.NoError(t, err)
err = json.Unmarshal(bb, &requestData)
require.NoError(t, err)
_, hasCursor := requestData.Variables["endCursor"].(string)
assert.Equal(t, false, hasCursor)
bb, err = ioutil.ReadAll(responses[1].Request.Body)
bb, err = io.ReadAll(responses[1].Request.Body)
require.NoError(t, err)
err = json.Unmarshal(bb, &requestData)
require.NoError(t, err)
@ -704,15 +704,15 @@ func Test_apiRun_paginationGraphQL(t *testing.T) {
}
func Test_apiRun_paginated_template(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
requestCount := 0
responses := []*http.Response{
{
StatusCode: 200,
Header: http.Header{"Content-Type": []string{`application/json`}},
Body: ioutil.NopCloser(bytes.NewBufferString(`{
Body: io.NopCloser(bytes.NewBufferString(`{
"data": {
"nodes": [
{
@ -730,7 +730,7 @@ func Test_apiRun_paginated_template(t *testing.T) {
{
StatusCode: 200,
Header: http.Header{"Content-Type": []string{`application/json`}},
Body: ioutil.NopCloser(bytes.NewBufferString(`{
Body: io.NopCloser(bytes.NewBufferString(`{
"data": {
"nodes": [
{
@ -748,7 +748,7 @@ func Test_apiRun_paginated_template(t *testing.T) {
}
options := ApiOptions{
IO: io,
IO: ios,
HttpClient: func() (*http.Client, error) {
var tr roundTripper = func(req *http.Request) (*http.Response, error) {
resp := responses[requestCount]
@ -782,14 +782,14 @@ func Test_apiRun_paginated_template(t *testing.T) {
Variables map[string]interface{}
}
bb, err := ioutil.ReadAll(responses[0].Request.Body)
bb, err := io.ReadAll(responses[0].Request.Body)
require.NoError(t, err)
err = json.Unmarshal(bb, &requestData)
require.NoError(t, err)
_, hasCursor := requestData.Variables["endCursor"].(string)
assert.Equal(t, false, hasCursor)
bb, err = ioutil.ReadAll(responses[1].Request.Body)
bb, err = io.ReadAll(responses[1].Request.Body)
require.NoError(t, err)
err = json.Unmarshal(bb, &requestData)
require.NoError(t, err)
@ -825,14 +825,14 @@ func Test_apiRun_inputFile(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
ios, stdin, _, _ := iostreams.Test()
resp := &http.Response{StatusCode: 204}
inputFile := tt.inputFile
if tt.inputFile == "-" {
_, _ = stdin.Write(tt.inputContents)
} else {
f, err := ioutil.TempFile(tempDir, tt.inputFile)
f, err := os.CreateTemp(tempDir, tt.inputFile)
if err != nil {
t.Fatal(err)
}
@ -847,11 +847,11 @@ func Test_apiRun_inputFile(t *testing.T) {
RequestInputFile: inputFile,
RawFields: []string{"a=b", "c=d"},
IO: io,
IO: ios,
HttpClient: func() (*http.Client, error) {
var tr roundTripper = func(req *http.Request) (*http.Response, error) {
var err error
if bodyBytes, err = ioutil.ReadAll(req.Body); err != nil {
if bodyBytes, err = io.ReadAll(req.Body); err != nil {
return nil, err
}
resp.Request = req
@ -879,11 +879,11 @@ func Test_apiRun_inputFile(t *testing.T) {
}
func Test_apiRun_cache(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
requestCount := 0
options := ApiOptions{
IO: io,
IO: ios,
HttpClient: func() (*http.Client, error) {
var tr roundTripper = func(req *http.Request) (*http.Response, error) {
requestCount++
@ -918,11 +918,11 @@ func Test_apiRun_cache(t *testing.T) {
}
func Test_parseFields(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
ios, stdin, _, _ := iostreams.Test()
fmt.Fprint(stdin, "pasted contents")
opts := ApiOptions{
IO: io,
IO: ios,
RawFields: []string{
"robot=Hubot",
"destroyer=false",
@ -954,7 +954,7 @@ func Test_parseFields(t *testing.T) {
}
func Test_magicFieldValue(t *testing.T) {
f, err := ioutil.TempFile(t.TempDir(), "gh-test")
f, err := os.CreateTemp(t.TempDir(), "gh-test")
if err != nil {
t.Fatal(err)
}
@ -962,7 +962,7 @@ func Test_magicFieldValue(t *testing.T) {
fmt.Fprint(f, "file contents")
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
type args struct {
v string
@ -1003,7 +1003,7 @@ func Test_magicFieldValue(t *testing.T) {
args: args{
v: ":owner",
opts: &ApiOptions{
IO: io,
IO: ios,
BaseRepo: func() (ghrepo.Interface, error) {
return ghrepo.New("hubot", "robot-uprising"), nil
},
@ -1017,7 +1017,7 @@ func Test_magicFieldValue(t *testing.T) {
args: args{
v: "{owner}",
opts: &ApiOptions{
IO: io,
IO: ios,
BaseRepo: func() (ghrepo.Interface, error) {
return ghrepo.New("hubot", "robot-uprising"), nil
},
@ -1030,7 +1030,7 @@ func Test_magicFieldValue(t *testing.T) {
name: "file",
args: args{
v: "@" + f.Name(),
opts: &ApiOptions{IO: io},
opts: &ApiOptions{IO: ios},
},
want: []byte("file contents"),
wantErr: false,
@ -1039,7 +1039,7 @@ func Test_magicFieldValue(t *testing.T) {
name: "file error",
args: args{
v: "@",
opts: &ApiOptions{IO: io},
opts: &ApiOptions{IO: ios},
},
want: nil,
wantErr: true,
@ -1061,7 +1061,7 @@ func Test_magicFieldValue(t *testing.T) {
}
func Test_openUserFile(t *testing.T) {
f, err := ioutil.TempFile(t.TempDir(), "gh-test")
f, err := os.CreateTemp(t.TempDir(), "gh-test")
if err != nil {
t.Fatal(err)
}
@ -1075,7 +1075,7 @@ func Test_openUserFile(t *testing.T) {
}
defer file.Close()
fb, err := ioutil.ReadAll(file)
fb, err := io.ReadAll(file)
if err != nil {
t.Fatal(err)
}
@ -1272,14 +1272,14 @@ func Test_previewNamesToMIMETypes(t *testing.T) {
}
func Test_processResponse_template(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
resp := http.Response{
StatusCode: 200,
Header: map[string][]string{
"Content-Type": {"application/json"},
},
Body: ioutil.NopCloser(strings.NewReader(`[
Body: io.NopCloser(strings.NewReader(`[
{
"title": "First title",
"labels": [{"name":"bug"}, {"name":"help wanted"}]
@ -1295,11 +1295,11 @@ func Test_processResponse_template(t *testing.T) {
}
opts := ApiOptions{
IO: io,
IO: ios,
Template: `{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " }}){{"\n"}}{{end}}`,
}
template := export.NewTemplate(io, opts.Template)
_, err := processResponse(&resp, &opts, ioutil.Discard, &template)
template := export.NewTemplate(ios, opts.Template)
_, err := processResponse(&resp, &opts, io.Discard, &template)
require.NoError(t, err)
err = template.End()
@ -1385,7 +1385,7 @@ func Test_parseErrorResponse(t *testing.T) {
if (err != nil) != tt.wantErr {
t.Errorf("parseErrorResponse() error = %v, wantErr %v", err, tt.wantErr)
}
if gotString, _ := ioutil.ReadAll(got); tt.args.input != string(gotString) {
if gotString, _ := io.ReadAll(got); tt.args.input != string(gotString) {
t.Errorf("parseErrorResponse() got = %q, want %q", string(gotString), tt.args.input)
}
if got1 != tt.wantErrMsg {

View file

@ -2,7 +2,7 @@ package api
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"
@ -281,7 +281,7 @@ func Test_httpRequest(t *testing.T) {
}
if tt.want.body != "" {
bb, err := ioutil.ReadAll(req.Body)
bb, err := io.ReadAll(req.Body)
if err != nil {
t.Errorf("Request.Body ReadAll error = %v", err)
return

View file

@ -217,10 +217,10 @@ func Test_helperRun(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, stdout, stderr := iostreams.Test()
ios, stdin, stdout, stderr := iostreams.Test()
fmt.Fprint(stdin, tt.input)
opts := &tt.opts
opts.IO = io
opts.IO = ios
if err := helperRun(opts); (err != nil) != tt.wantErr {
t.Fatalf("helperRun() error = %v, wantErr %v", err, tt.wantErr)
}

View file

@ -3,7 +3,7 @@ package login
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
@ -82,7 +82,7 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm
if tokenStdin {
defer opts.IO.In.Close()
token, err := ioutil.ReadAll(opts.IO.In)
token, err := io.ReadAll(opts.IO.In)
if err != nil {
return fmt.Errorf("failed to read token from standard input: %w", err)
}

View file

@ -168,13 +168,13 @@ func Test_NewCmdLogin(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
ios, stdin, _, _ := iostreams.Test()
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
io.SetStdoutTTY(true)
io.SetStdinTTY(tt.stdinTTY)
ios.SetStdoutTTY(true)
ios.SetStdinTTY(tt.stdinTTY)
if tt.stdin != "" {
stdin.WriteString(tt.stdin)
}
@ -309,17 +309,17 @@ func Test_loginRun_nontty(t *testing.T) {
}
for _, tt := range tests {
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
io.SetStdinTTY(false)
io.SetStdoutTTY(false)
ios.SetStdinTTY(false)
ios.SetStdoutTTY(false)
tt.opts.Config = func() (config.Config, error) {
cfg := config.NewBlankConfig()
return config.InheritEnv(cfg), nil
}
tt.opts.IO = io
tt.opts.IO = ios
t.Run(tt.name, func(t *testing.T) {
reg := &httpmock.Registry{}
tt.opts.HttpClient = func() (*http.Client, error) {
@ -513,13 +513,13 @@ func Test_loginRun_Survey(t *testing.T) {
if tt.opts == nil {
tt.opts = &LoginOptions{}
}
io, _, _, stderr := iostreams.Test()
ios, _, _, stderr := iostreams.Test()
io.SetStdinTTY(true)
io.SetStderrTTY(true)
io.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
ios.SetStdoutTTY(true)
tt.opts.IO = io
tt.opts.IO = ios
cfg := config.NewBlankConfig()

View file

@ -54,12 +54,12 @@ func Test_NewCmdLogout(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
io.SetStdinTTY(tt.tty)
io.SetStdoutTTY(tt.tty)
ios.SetStdinTTY(tt.tty)
ios.SetStdoutTTY(tt.tty)
argv, err := shlex.Split(tt.cli)
assert.NoError(t, err)
@ -141,12 +141,12 @@ func Test_logoutRun_tty(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, stderr := iostreams.Test()
ios, _, _, stderr := iostreams.Test()
io.SetStdinTTY(true)
io.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStdoutTTY(true)
tt.opts.IO = io
tt.opts.IO = ios
cfg := config.NewBlankConfig()
tt.opts.Config = func() (config.Config, error) {
return cfg, nil
@ -229,12 +229,12 @@ func Test_logoutRun_nontty(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, stderr := iostreams.Test()
ios, _, _, stderr := iostreams.Test()
io.SetStdinTTY(false)
io.SetStdoutTTY(false)
ios.SetStdinTTY(false)
ios.SetStdoutTTY(false)
tt.opts.IO = io
tt.opts.IO = ios
cfg := config.NewBlankConfig()
tt.opts.Config = func() (config.Config, error) {
return cfg, nil

View file

@ -2,7 +2,7 @@ package refresh
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -89,13 +89,13 @@ func Test_NewCmdRefresh(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
io.SetStdinTTY(tt.tty)
io.SetStdoutTTY(tt.tty)
io.SetNeverPrompt(tt.neverPrompt)
ios.SetStdinTTY(tt.tty)
ios.SetStdoutTTY(tt.tty)
ios.SetNeverPrompt(tt.neverPrompt)
argv, err := shlex.Split(tt.cli)
assert.NoError(t, err)
@ -238,12 +238,12 @@ func Test_refreshRun(t *testing.T) {
return nil
}
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
io.SetStdinTTY(!tt.nontty)
io.SetStdoutTTY(!tt.nontty)
ios.SetStdinTTY(!tt.nontty)
ios.SetStdoutTTY(!tt.nontty)
tt.opts.IO = io
tt.opts.IO = ios
cfg := config.NewBlankConfig()
tt.opts.Config = func() (config.Config, error) {
return cfg, nil
@ -263,7 +263,7 @@ func Test_refreshRun(t *testing.T) {
return &http.Response{
Request: req,
StatusCode: statusCode,
Body: ioutil.NopCloser(strings.NewReader(``)),
Body: io.NopCloser(strings.NewReader(``)),
Header: http.Header{
"X-Oauth-Scopes": {tt.oldScopes},
},

View file

@ -102,12 +102,12 @@ func Test_setupGitRun(t *testing.T) {
}
}
io, _, _, stderr := iostreams.Test()
ios, _, _, stderr := iostreams.Test()
io.SetStdinTTY(true)
io.SetStderrTTY(true)
io.SetStdoutTTY(true)
tt.opts.IO = io
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
ios.SetStdoutTTY(true)
tt.opts.IO = ios
err := setupGitRun(tt.opts)
if tt.expectedErr != "" {

View file

@ -2,8 +2,8 @@ package shared
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"
@ -36,7 +36,7 @@ func (c tinyConfig) WriteHosts() error {
func TestLogin_ssh(t *testing.T) {
dir := t.TempDir()
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
tr := httpmock.Registry{}
defer tr.Verify(t)
@ -72,13 +72,13 @@ func TestLogin_ssh(t *testing.T) {
}
assert.Equal(t, expected, args)
// simulate that the public key file has been generated
_ = ioutil.WriteFile(keyFile+".pub", []byte("PUBKEY"), 0600)
_ = os.WriteFile(keyFile+".pub", []byte("PUBKEY"), 0600)
})
cfg := tinyConfig{}
err := Login(&LoginOptions{
IO: io,
IO: ios,
Config: &cfg,
HTTPClient: &http.Client{Transport: &tr},
Hostname: "example.com",

View file

@ -3,7 +3,6 @@ package shared
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
@ -50,7 +49,7 @@ func GetScopes(httpClient httpClient, hostname, authToken string) (string, error
defer func() {
// Ensure the response body is fully read and closed
// before we reconnect, so that we reuse the same TCPconnection.
_, _ = io.Copy(ioutil.Discard, res.Body)
_, _ = io.Copy(io.Discard, res.Body)
res.Body.Close()
}()

View file

@ -2,7 +2,7 @@ package shared
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"
@ -58,7 +58,7 @@ func Test_HasMinimumScopes(t *testing.T) {
return &http.Response{
Request: req,
StatusCode: 200,
Body: ioutil.NopCloser(&bytes.Buffer{}),
Body: io.NopCloser(&bytes.Buffer{}),
Header: map[string][]string{
"X-Oauth-Scopes": {tt.header},
},

View file

@ -208,13 +208,13 @@ func Test_statusRun(t *testing.T) {
tt.opts = &StatusOptions{}
}
io, _, _, stderr := iostreams.Test()
ios, _, _, stderr := iostreams.Test()
io.SetStdinTTY(true)
io.SetStderrTTY(true)
io.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
ios.SetStdoutTTY(true)
tt.opts.IO = io
tt.opts.IO = ios
cfg := config.NewBlankConfig()

View file

@ -2,7 +2,7 @@ package browse
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
@ -126,8 +126,8 @@ func TestNewCmdBrowse(t *testing.T) {
argv, err := shlex.Split(tt.cli)
assert.NoError(t, err)
cmd.SetArgs(argv)
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantsErr {
@ -418,7 +418,7 @@ func Test_runBrowse(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
browser := cmdutil.TestBrowser{}
reg := httpmock.Registry{}
@ -428,7 +428,7 @@ func Test_runBrowse(t *testing.T) {
}
opts := tt.opts
opts.IO = io
opts.IO = ios
opts.BaseRepo = func() (ghrepo.Interface, error) {
return tt.baseRepo, nil
}

View file

@ -63,11 +63,11 @@ func TestApp_VSCode(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b := &cmdutil.TestBrowser{}
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
a := &App{
browser: b,
apiClient: testCodeApiMock(),
io: io,
io: ios,
}
if err := a.VSCode(context.Background(), tt.args.codespaceName, tt.args.useInsiders, tt.args.useWeb); (err != nil) != tt.wantErr {
t.Errorf("App.VSCode() error = %v, wantErr %v", err, tt.wantErr)
@ -96,8 +96,8 @@ func TestPendingOperationDisallowsCode(t *testing.T) {
}
func testingCodeApp() *App {
io, _, _, _ := iostreams.Test()
return NewApp(io, nil, testCodeApiMock(), nil)
ios, _, _, _ := iostreams.Test()
return NewApp(ios, nil, testCodeApiMock(), nil)
}
func testCodeApiMock() *apiClientMock {

View file

@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"sort"
@ -256,7 +255,7 @@ func noArgsConstraint(cmd *cobra.Command, args []string) error {
}
func noopLogger() *log.Logger {
return log.New(ioutil.Discard, "", 0)
return log.New(io.Discard, "", 0)
}
type codespace struct {

View file

@ -311,13 +311,13 @@ Alternatively, you can run "create" with the "--default-permissions" option to c
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
a := &App{
io: io,
io: ios,
apiClient: tt.fields.apiClient,
}

View file

@ -187,10 +187,10 @@ func TestDelete(t *testing.T) {
},
}
io, _, stdout, stderr := iostreams.Test()
io.SetStdinTTY(true)
io.SetStdoutTTY(true)
app := NewApp(io, nil, apiMock, nil)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdinTTY(true)
ios.SetStdoutTTY(true)
app := NewApp(ios, nil, apiMock, nil)
err := app.Delete(context.Background(), opts)
if (err != nil) != tt.wantErr {
t.Errorf("delete() error = %v, wantErr %v", err, tt.wantErr)

View file

@ -42,6 +42,6 @@ func testingLogsApp() *App {
},
}
io, _, _, _ := iostreams.Test()
return NewApp(io, nil, apiMock, nil)
ios, _, _, _ := iostreams.Test()
return NewApp(ios, nil, apiMock, nil)
}

View file

@ -191,10 +191,10 @@ func runUpdateVisibilityTest(t *testing.T, portVisibilities []portVisibility, ev
},
}
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
a := &App{
io: io,
io: ios,
apiClient: mockApi,
}
@ -264,7 +264,7 @@ func testingPortsApp() *App {
},
}
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
return NewApp(io, nil, apiMock, nil)
return NewApp(ios, nil, apiMock, nil)
}

View file

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"testing"
@ -45,14 +44,14 @@ func TestApp_Select(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdinTTY(true)
io.SetStdoutTTY(true)
a := NewApp(io, nil, testSelectApiMock(), nil)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdinTTY(true)
ios.SetStdoutTTY(true)
a := NewApp(ios, nil, testSelectApiMock(), nil)
opts := selectOptions{}
if tt.outputToFile {
file, err := ioutil.TempFile("", "codespace-selection-test")
file, err := os.CreateTemp("", "codespace-selection-test")
if err != nil {
t.Fatal(err)
}

View file

@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"os"
@ -441,7 +440,7 @@ type fileLogger struct {
func newFileLogger(file string) (fl *fileLogger, err error) {
var f *os.File
if file == "" {
f, err = ioutil.TempFile("", "")
f, err = os.CreateTemp("", "")
if err != nil {
return nil, fmt.Errorf("failed to create tmp file: %w", err)
}

View file

@ -42,6 +42,6 @@ func testingSSHApp() *App {
},
}
io, _, _, _ := iostreams.Test()
return NewApp(io, nil, apiMock, nil)
ios, _, _, _ := iostreams.Test()
return NewApp(ios, nil, apiMock, nil)
}

View file

@ -44,8 +44,8 @@ func TestNewCmdCompletion(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
completeCmd := NewCmdCompletion(io)
ios, _, stdout, stderr := iostreams.Test()
completeCmd := NewCmdCompletion(ios)
rootCmd := &cobra.Command{Use: "gh"}
rootCmd.AddCommand(completeCmd)

View file

@ -107,8 +107,8 @@ func Test_getRun(t *testing.T) {
}
for _, tt := range tests {
io, _, stdout, stderr := iostreams.Test()
tt.input.IO = io
ios, _, stdout, stderr := iostreams.Test()
tt.input.IO = ios
t.Run(tt.name, func(t *testing.T) {
err := getRun(tt.input)

View file

@ -97,8 +97,8 @@ browser=brave
}
for _, tt := range tests {
io, _, stdout, _ := iostreams.Test()
tt.input.IO = io
ios, _, stdout, _ := iostreams.Test()
tt.input.IO = ios
tt.input.Config = func() (config.Config, error) {
return tt.config, nil
}

View file

@ -132,8 +132,8 @@ func Test_setRun(t *testing.T) {
},
}
for _, tt := range tests {
io, _, stdout, stderr := iostreams.Test()
tt.input.IO = io
ios, _, stdout, stderr := iostreams.Test()
tt.input.IO = ios
t.Run(tt.name, func(t *testing.T) {
err := setRun(tt.input)

View file

@ -2,7 +2,7 @@ package extension
import (
"errors"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
@ -551,8 +551,8 @@ func TestNewCmdExtension(t *testing.T) {
cmd := NewCmdExtension(&f)
cmd.SetArgs(tt.args)
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err := cmd.ExecuteC()
if tt.wantErr {

View file

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
@ -103,7 +102,7 @@ func fetchLatestRelease(httpClient *http.Client, baseRepo ghrepo.Interface) (*re
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
@ -140,7 +139,7 @@ func fetchReleaseFromTag(httpClient *http.Client, baseRepo ghrepo.Interface, tag
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
@ -177,7 +176,7 @@ func fetchCommitSHA(httpClient *http.Client, baseRepo ghrepo.Interface, targetRe
return "", api.HandleHTTPError(resp)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}

View file

@ -7,7 +7,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"net/http"
"os"
"os/exec"
@ -40,7 +39,7 @@ type Manager struct {
dryRunMode bool
}
func NewManager(io *iostreams.IOStreams) *Manager {
func NewManager(ios *iostreams.IOStreams) *Manager {
return &Manager{
dataDir: config.DataDir,
lookPath: safeexec.LookPath,
@ -53,7 +52,7 @@ func NewManager(io *iostreams.IOStreams) *Manager {
}
return fmt.Sprintf("%s-%s", runtime.GOOS, runtime.GOARCH), ext
},
io: io,
io: ios,
}
}
@ -126,7 +125,7 @@ func (m *Manager) List() []extensions.Extension {
func (m *Manager) list(includeMetadata bool) ([]Extension, error) {
dir := m.installDir()
entries, err := ioutil.ReadDir(dir)
entries, err := os.ReadDir(dir)
if err != nil {
return nil, err
}
@ -160,11 +159,11 @@ func (m *Manager) list(includeMetadata bool) ([]Extension, error) {
return results, nil
}
func (m *Manager) parseExtensionFile(fi fs.FileInfo) (Extension, error) {
func (m *Manager) parseExtensionFile(fi fs.DirEntry) (Extension, error) {
ext := Extension{isLocal: true}
id := m.installDir()
exePath := filepath.Join(id, fi.Name(), fi.Name())
if !isSymlink(fi.Mode()) {
if !isSymlink(fi.Type()) {
// if this is a regular file, its contents is the local directory of the extension
p, err := readPathFromFile(filepath.Join(id, fi.Name()))
if err != nil {
@ -176,7 +175,7 @@ func (m *Manager) parseExtensionFile(fi fs.FileInfo) (Extension, error) {
return ext, nil
}
func (m *Manager) parseExtensionDir(fi fs.FileInfo) (Extension, error) {
func (m *Manager) parseExtensionDir(fi fs.DirEntry) (Extension, error) {
id := m.installDir()
if _, err := os.Stat(filepath.Join(id, fi.Name(), manifestName)); err == nil {
return m.parseBinaryExtensionDir(fi)
@ -185,7 +184,7 @@ func (m *Manager) parseExtensionDir(fi fs.FileInfo) (Extension, error) {
return m.parseGitExtensionDir(fi)
}
func (m *Manager) parseBinaryExtensionDir(fi fs.FileInfo) (Extension, error) {
func (m *Manager) parseBinaryExtensionDir(fi fs.DirEntry) (Extension, error) {
id := m.installDir()
exePath := filepath.Join(id, fi.Name(), fi.Name())
ext := Extension{path: exePath, kind: BinaryKind}
@ -207,7 +206,7 @@ func (m *Manager) parseBinaryExtensionDir(fi fs.FileInfo) (Extension, error) {
return ext, nil
}
func (m *Manager) parseGitExtensionDir(fi fs.FileInfo) (Extension, error) {
func (m *Manager) parseGitExtensionDir(fi fs.DirEntry) (Extension, error) {
id := m.installDir()
exePath := filepath.Join(id, fi.Name(), fi.Name())
remoteUrl := m.getRemoteUrl(fi.Name())

View file

@ -3,7 +3,6 @@ package extension
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
@ -48,7 +47,7 @@ func TestHelperProcess(t *testing.T) {
os.Exit(0)
}
func newTestManager(dir string, client *http.Client, io *iostreams.IOStreams) *Manager {
func newTestManager(dir string, client *http.Client, ios *iostreams.IOStreams) *Manager {
return &Manager{
dataDir: func() string { return dir },
lookPath: func(exe string) (string, error) { return exe, nil },
@ -56,15 +55,15 @@ func newTestManager(dir string, client *http.Client, io *iostreams.IOStreams) *M
newCommand: func(exe string, args ...string) *exec.Cmd {
args = append([]string{os.Args[0], "-test.run=TestHelperProcess", "--", exe}, args...)
cmd := exec.Command(args[0], args[1:]...)
if io != nil {
cmd.Stdout = io.Out
cmd.Stderr = io.ErrOut
if ios != nil {
cmd.Stdout = ios.Out
cmd.Stderr = ios.ErrOut
}
cmd.Env = []string{"GH_WANT_HELPER_PROCESS=1"}
return cmd
},
config: config.NewBlankConfig(),
io: io,
io: ios,
client: client,
platform: func() (string, string) {
return "windows-amd64", ".exe"
@ -187,7 +186,7 @@ func TestManager_Remove(t *testing.T) {
err := m.Remove("hello")
assert.NoError(t, err)
items, err := ioutil.ReadDir(filepath.Join(tempDir, "extensions"))
items, err := os.ReadDir(filepath.Join(tempDir, "extensions"))
assert.NoError(t, err)
assert.Equal(t, 1, len(items))
assert.Equal(t, "gh-two", items[0].Name())
@ -195,8 +194,8 @@ func TestManager_Remove(t *testing.T) {
func TestManager_Upgrade_NoExtensions(t *testing.T) {
tempDir := t.TempDir()
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, ios)
err := m.Upgrade("", false)
assert.EqualError(t, err, "no extensions installed")
assert.Equal(t, "", stdout.String())
@ -206,8 +205,8 @@ func TestManager_Upgrade_NoExtensions(t *testing.T) {
func TestManager_Upgrade_NoMatchingExtension(t *testing.T) {
tempDir := t.TempDir()
assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-hello", "gh-hello")))
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, ios)
err := m.Upgrade("invalid", false)
assert.EqualError(t, err, `no extension matched "invalid"`)
assert.Equal(t, "", stdout.String())
@ -219,8 +218,8 @@ func TestManager_UpgradeExtensions(t *testing.T) {
assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-hello", "gh-hello")))
assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-two", "gh-two")))
assert.NoError(t, stubLocalExtension(tempDir, filepath.Join(tempDir, "extensions", "gh-local", "gh-local")))
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, ios)
exts, err := m.list(false)
assert.NoError(t, err)
assert.Equal(t, 3, len(exts))
@ -249,8 +248,8 @@ func TestManager_UpgradeExtensions_DryRun(t *testing.T) {
assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-hello", "gh-hello")))
assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-two", "gh-two")))
assert.NoError(t, stubLocalExtension(tempDir, filepath.Join(tempDir, "extensions", "gh-local", "gh-local")))
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, ios)
m.EnableDryRunMode()
exts, err := m.list(false)
assert.NoError(t, err)
@ -275,8 +274,8 @@ func TestManager_UpgradeExtension_LocalExtension(t *testing.T) {
tempDir := t.TempDir()
assert.NoError(t, stubLocalExtension(tempDir, filepath.Join(tempDir, "extensions", "gh-local", "gh-local")))
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, ios)
exts, err := m.list(false)
assert.NoError(t, err)
assert.Equal(t, 1, len(exts))
@ -290,8 +289,8 @@ func TestManager_UpgradeExtension_LocalExtension_DryRun(t *testing.T) {
tempDir := t.TempDir()
assert.NoError(t, stubLocalExtension(tempDir, filepath.Join(tempDir, "extensions", "gh-local", "gh-local")))
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, ios)
m.EnableDryRunMode()
exts, err := m.list(false)
assert.NoError(t, err)
@ -305,8 +304,8 @@ func TestManager_UpgradeExtension_LocalExtension_DryRun(t *testing.T) {
func TestManager_UpgradeExtension_GitExtension(t *testing.T) {
tempDir := t.TempDir()
assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-remote", "gh-remote")))
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, ios)
exts, err := m.list(false)
assert.NoError(t, err)
assert.Equal(t, 1, len(exts))
@ -327,8 +326,8 @@ func TestManager_UpgradeExtension_GitExtension(t *testing.T) {
func TestManager_UpgradeExtension_GitExtension_DryRun(t *testing.T) {
tempDir := t.TempDir()
assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-remote", "gh-remote")))
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, ios)
m.EnableDryRunMode()
exts, err := m.list(false)
assert.NoError(t, err)
@ -346,8 +345,8 @@ func TestManager_UpgradeExtension_GitExtension_Force(t *testing.T) {
tempDir := t.TempDir()
extensionDir := filepath.Join(tempDir, "extensions", "gh-remote")
assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-remote", "gh-remote")))
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, nil, ios)
exts, err := m.list(false)
assert.NoError(t, err)
assert.Equal(t, 1, len(exts))
@ -369,12 +368,12 @@ func TestManager_UpgradeExtension_GitExtension_Force(t *testing.T) {
func TestManager_MigrateToBinaryExtension(t *testing.T) {
tempDir := t.TempDir()
assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-remote", "gh-remote")))
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
reg := httpmock.Registry{}
defer reg.Verify(t)
client := http.Client{Transport: &reg}
m := newTestManager(tempDir, &client, io)
m := newTestManager(tempDir, &client, ios)
exts, err := m.list(false)
assert.NoError(t, err)
assert.Equal(t, 1, len(exts))
@ -458,8 +457,8 @@ func TestManager_UpgradeExtension_BinaryExtension(t *testing.T) {
Tag: "v1.0.1",
}))
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, &http.Client{Transport: &reg}, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, &http.Client{Transport: &reg}, ios)
reg.Register(
httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
httpmock.JSONResponse(
@ -520,8 +519,8 @@ func TestManager_UpgradeExtension_BinaryExtension_DryRun(t *testing.T) {
Tag: "v1.0.1",
}))
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, &http.Client{Transport: &reg}, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, &http.Client{Transport: &reg}, ios)
m.EnableDryRunMode()
reg.Register(
httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
@ -573,8 +572,8 @@ func TestManager_UpgradeExtension_BinaryExtension_Pinned(t *testing.T) {
IsPinned: true,
}))
io, _, _, _ := iostreams.Test()
m := newTestManager(tempDir, nil, io)
ios, _, _, _ := iostreams.Test()
m := newTestManager(tempDir, nil, ios)
exts, err := m.list(false)
assert.Nil(t, err)
assert.Equal(t, 1, len(exts))
@ -590,8 +589,8 @@ func TestManager_UpgradeExtenion_GitExtension_Pinned(t *testing.T) {
extDir := filepath.Join(tempDir, "extensions", "gh-remote")
assert.NoError(t, stubPinnedExtension(filepath.Join(extDir, "gh-remote"), "abcd1234"))
io, _, _, _ := iostreams.Test()
m := newTestManager(tempDir, nil, io)
ios, _, _, _ := iostreams.Test()
m := newTestManager(tempDir, nil, ios)
exts, err := m.list(false)
assert.NoError(t, err)
assert.Equal(t, 1, len(exts))
@ -611,8 +610,8 @@ func TestManager_Install_git(t *testing.T) {
defer reg.Verify(t)
client := http.Client{Transport: &reg}
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, &client, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(tempDir, &client, ios)
reg.Register(
httpmock.REST("GET", "repos/owner/gh-some-ext/releases/latest"),
@ -644,8 +643,8 @@ func TestManager_Install_git_pinned(t *testing.T) {
defer reg.Verify(t)
client := http.Client{Transport: &reg}
io, _, _, stderr := iostreams.Test()
m := newTestManager(tempDir, &client, io)
ios, _, _, stderr := iostreams.Test()
m := newTestManager(tempDir, &client, ios)
reg.Register(
httpmock.REST("GET", "repos/owner/gh-cool-ext/releases/latest"),
@ -705,10 +704,10 @@ func TestManager_Install_binary_pinned(t *testing.T) {
httpmock.REST("GET", "release/cool"),
httpmock.StringResponse("FAKE BINARY"))
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
tempDir := t.TempDir()
m := newTestManager(tempDir, &http.Client{Transport: &reg}, io)
m := newTestManager(tempDir, &http.Client{Transport: &reg}, ios)
err := m.Install(repo, "v1.6.3-pre")
assert.NoError(t, err)
@ -769,10 +768,10 @@ func TestManager_Install_binary_unsupported(t *testing.T) {
},
}))
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
tempDir := t.TempDir()
m := newTestManager(tempDir, &client, io)
m := newTestManager(tempDir, &client, ios)
err := m.Install(repo, "")
assert.EqualError(t, err, "gh-bin-ext unsupported for windows-amd64. Open an issue: `gh issue create -R owner/gh-bin-ext -t'Support windows-amd64'`")
@ -814,10 +813,10 @@ func TestManager_Install_binary(t *testing.T) {
httpmock.REST("GET", "release/cool"),
httpmock.StringResponse("FAKE BINARY"))
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
tempDir := t.TempDir()
m := newTestManager(tempDir, &http.Client{Transport: &reg}, io)
m := newTestManager(tempDir, &http.Client{Transport: &reg}, ios)
err := m.Install(repo, "")
assert.NoError(t, err)
@ -847,12 +846,12 @@ func TestManager_Install_binary(t *testing.T) {
func TestManager_Create(t *testing.T) {
chdirTemp(t)
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(".", nil, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(".", nil, ios)
err := m.Create("gh-test", extensions.GitTemplateType)
assert.NoError(t, err)
files, err := ioutil.ReadDir("gh-test")
files, err := os.ReadDir("gh-test")
assert.NoError(t, err)
assert.Equal(t, []string{"gh-test"}, fileNames(files))
@ -871,13 +870,13 @@ func TestManager_Create_go_binary(t *testing.T) {
httpmock.GraphQL(`query UserCurrent\b`),
httpmock.StringResponse(`{"data":{"viewer":{"login":"jillv"}}}`))
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(".", &http.Client{Transport: &reg}, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(".", &http.Client{Transport: &reg}, ios)
err := m.Create("gh-test", extensions.GoBinTemplateType)
require.NoError(t, err)
files, err := ioutil.ReadDir("gh-test")
files, err := os.ReadDir("gh-test")
require.NoError(t, err)
assert.Equal(t, []string{".github", ".gitignore", "main.go"}, fileNames(files))
@ -888,7 +887,7 @@ func TestManager_Create_go_binary(t *testing.T) {
/gh-test.exe
`), string(gitignore))
files, err = ioutil.ReadDir(filepath.Join("gh-test", ".github", "workflows"))
files, err = os.ReadDir(filepath.Join("gh-test", ".github", "workflows"))
require.NoError(t, err)
assert.Equal(t, []string{"release.yml"}, fileNames(files))
@ -904,21 +903,21 @@ func TestManager_Create_go_binary(t *testing.T) {
func TestManager_Create_other_binary(t *testing.T) {
chdirTemp(t)
io, _, stdout, stderr := iostreams.Test()
m := newTestManager(".", nil, io)
ios, _, stdout, stderr := iostreams.Test()
m := newTestManager(".", nil, ios)
err := m.Create("gh-test", extensions.OtherBinTemplateType)
assert.NoError(t, err)
files, err := ioutil.ReadDir("gh-test")
files, err := os.ReadDir("gh-test")
assert.NoError(t, err)
assert.Equal(t, 2, len(files))
files, err = ioutil.ReadDir(filepath.Join("gh-test", ".github", "workflows"))
files, err = os.ReadDir(filepath.Join("gh-test", ".github", "workflows"))
assert.NoError(t, err)
assert.Equal(t, []string{"release.yml"}, fileNames(files))
files, err = ioutil.ReadDir(filepath.Join("gh-test", "script"))
files, err = os.ReadDir(filepath.Join("gh-test", "script"))
assert.NoError(t, err)
assert.Equal(t, []string{"build.sh"}, fileNames(files))
@ -942,7 +941,7 @@ func chdirTemp(t *testing.T) {
})
}
func fileNames(files []os.FileInfo) []string {
func fileNames(files []os.DirEntry) []string {
names := make([]string, len(files))
for i, f := range files {
names[i] = f.Name()
@ -981,7 +980,7 @@ func stubPinnedExtension(path string, pinnedVersion string) error {
}
func stubLocalExtension(tempDir, path string) error {
extDir, err := ioutil.TempDir(tempDir, "local-ext")
extDir, err := os.MkdirTemp(tempDir, "local-ext")
if err != nil {
return err
}

View file

@ -190,8 +190,8 @@ func TestNewHTTPClient(t *testing.T) {
os.Setenv("GH_DEBUG", oldGhDebug)
})
io, _, _, stderr := iostreams.Test()
client, err := NewHTTPClient(io, tt.args.config, tt.args.appVersion, tt.args.setAccept)
ios, _, _, stderr := iostreams.Test()
client, err := NewHTTPClient(ios, tt.args.config, tt.args.appVersion, tt.args.setAccept)
require.NoError(t, err)
req, err := http.NewRequest("GET", ts.URL, nil)

View file

@ -16,9 +16,9 @@ import (
)
func runCloneCommand(httpClient *http.Client, cli string) (*test.CmdOut, error) {
io, stdin, stdout, stderr := iostreams.Test()
ios, stdin, stdout, stderr := iostreams.Test()
fac := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return httpClient, nil
},

View file

@ -6,8 +6,8 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"regexp"
"sort"
@ -193,7 +193,7 @@ func processFiles(stdin io.ReadCloser, filenameOverride string, filenames []stri
} else {
filename = fmt.Sprintf("gistfile%d.txt", i)
}
content, err = ioutil.ReadAll(stdin)
content, err = io.ReadAll(stdin)
if err != nil {
return fs, fmt.Errorf("failed to read from stdin: %w", err)
}
@ -211,7 +211,7 @@ func processFiles(stdin io.ReadCloser, filenameOverride string, filenames []stri
return nil, fmt.Errorf("failed to upload %s: binary file not supported", f)
}
content, err = ioutil.ReadFile(f)
content, err = os.ReadFile(f)
if err != nil {
return fs, fmt.Errorf("failed to read file %s: %w", f, err)
}

View file

@ -3,8 +3,9 @@ package create
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
@ -22,7 +23,7 @@ import (
func Test_processFiles(t *testing.T) {
fakeStdin := strings.NewReader("hey cool how is it going")
files, err := processFiles(ioutil.NopCloser(fakeStdin), "", []string{"-"})
files, err := processFiles(io.NopCloser(fakeStdin), "", []string{"-"})
if err != nil {
t.Fatalf("unexpected error processing files: %s", err)
}
@ -126,9 +127,9 @@ func TestNewCmdCreate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
if tt.factory != nil {
@ -164,9 +165,9 @@ func TestNewCmdCreate(t *testing.T) {
func Test_createRun(t *testing.T) {
tempDir := t.TempDir()
fixtureFile := filepath.Join(tempDir, "fixture.txt")
assert.NoError(t, ioutil.WriteFile(fixtureFile, []byte("{}"), 0644))
assert.NoError(t, os.WriteFile(fixtureFile, []byte("{}"), 0644))
emptyFile := filepath.Join(tempDir, "empty.txt")
assert.NoError(t, ioutil.WriteFile(emptyFile, []byte(" \t\n"), 0644))
assert.NoError(t, os.WriteFile(emptyFile, []byte(" \t\n"), 0644))
tests := []struct {
name string
@ -333,8 +334,8 @@ func Test_createRun(t *testing.T) {
return config.NewBlankConfig(), nil
}
io, stdin, stdout, stderr := iostreams.Test()
tt.opts.IO = io
ios, stdin, stdout, stderr := iostreams.Test()
tt.opts.IO = ios
browser := &cmdutil.TestBrowser{}
tt.opts.Browser = browser
@ -348,7 +349,7 @@ func Test_createRun(t *testing.T) {
if err := createRun(tt.opts); (err != nil) != tt.wantErr {
t.Errorf("createRun() error = %v, wantErr %v", err, tt.wantErr)
}
bodyBytes, _ := ioutil.ReadAll(reg.Requests[0].Body)
bodyBytes, _ := io.ReadAll(reg.Requests[0].Body)
reqBody := make(map[string]interface{})
err := json.Unmarshal(bodyBytes, &reqBody)
if err != nil {

View file

@ -3,8 +3,9 @@ package edit
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
"testing"
@ -110,7 +111,7 @@ func TestNewCmdEdit(t *testing.T) {
func Test_editRun(t *testing.T) {
fileToAdd := filepath.Join(t.TempDir(), "gist-test.txt")
err := ioutil.WriteFile(fileToAdd, []byte("hello"), 0600)
err := os.WriteFile(fileToAdd, []byte("hello"), 0600)
require.NoError(t, err)
tests := []struct {
@ -473,11 +474,11 @@ func Test_editRun(t *testing.T) {
tt.opts.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: reg}, nil
}
io, stdin, stdout, stderr := iostreams.Test()
ios, stdin, stdout, stderr := iostreams.Test()
stdin.WriteString(tt.stdin)
io.SetStdoutTTY(!tt.nontty)
io.SetStdinTTY(!tt.nontty)
tt.opts.IO = io
ios.SetStdoutTTY(!tt.nontty)
ios.SetStdinTTY(!tt.nontty)
tt.opts.IO = ios
tt.opts.Selector = "1234"
tt.opts.Config = func() (config.Config, error) {
@ -499,7 +500,7 @@ func Test_editRun(t *testing.T) {
assert.NoError(t, err)
if tt.wantParams != nil {
bodyBytes, _ := ioutil.ReadAll(reg.Requests[2].Body)
bodyBytes, _ := io.ReadAll(reg.Requests[2].Body)
reqBody := make(map[string]interface{})
err = json.Unmarshal(bodyBytes, &reqBody)
if err != nil {

View file

@ -365,9 +365,9 @@ func Test_listRun(t *testing.T) {
return config.NewBlankConfig(), nil
}
io, _, stdout, _ := iostreams.Test()
io.SetStdoutTTY(!tt.nontty)
tt.opts.IO = io
ios, _, stdout, _ := iostreams.Test()
ios.SetStdoutTTY(!tt.nontty)
tt.opts.IO = ios
if tt.opts.Limit == 0 {
tt.opts.Limit = 10

View file

@ -78,11 +78,11 @@ func TestNewCmdView(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
io.SetStdoutTTY(tt.tty)
ios, _, _, _ := iostreams.Test()
ios.SetStdoutTTY(tt.tty)
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
argv, err := shlex.Split(tt.cli)
@ -371,9 +371,9 @@ func Test_viewRun(t *testing.T) {
return config.NewBlankConfig(), nil
}
io, _, stdout, _ := iostreams.Test()
io.SetStdoutTTY(true)
tt.opts.IO = io
ios, _, stdout, _ := iostreams.Test()
ios.SetStdoutTTY(true)
tt.opts.IO = ios
t.Run(tt.name, func(t *testing.T) {
err := viewRun(tt.opts)
@ -451,7 +451,7 @@ func Test_promptGists(t *testing.T) {
},
}
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
for _, tt := range tests {
reg := &httpmock.Registry{}
@ -474,7 +474,7 @@ func Test_promptGists(t *testing.T) {
tt.askStubs(as)
}
gistID, err := promptGists(client, "github.com", io.ColorScheme())
gistID, err := promptGists(client, "github.com", ios.ColorScheme())
assert.NoError(t, err)
assert.Equal(t, tt.wantOut, gistID)
reg.Verify(t)

View file

@ -11,10 +11,10 @@ import (
)
func Test_runAdd(t *testing.T) {
io, stdin, stdout, stderr := iostreams.Test()
io.SetStdinTTY(false)
io.SetStdoutTTY(true)
io.SetStderrTTY(true)
ios, stdin, stdout, stderr := iostreams.Test()
ios.SetStdinTTY(false)
ios.SetStdoutTTY(true)
ios.SetStderrTTY(true)
stdin.WriteString("PUBKEY")
@ -26,7 +26,7 @@ func Test_runAdd(t *testing.T) {
httpmock.StringResponse(`{}`))
err := runAdd(&AddOptions{
IO: io,
IO: ios,
Config: func() (config.Config, error) {
return config.NewBlankConfig(), nil
},

View file

@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
"github.com/cli/cli/v2/api"
@ -17,7 +16,7 @@ var scopesError = errors.New("insufficient OAuth scopes")
func gpgKeyUpload(httpClient *http.Client, hostname string, keyFile io.Reader) error {
url := ghinstance.RESTPrefix(hostname) + "user/gpg_keys"
keyBytes, err := ioutil.ReadAll(keyFile)
keyBytes, err := io.ReadAll(keyFile)
if err != nil {
return err
}
@ -53,7 +52,7 @@ func gpgKeyUpload(httpClient *http.Client, hostname string, keyFile io.Reader) e
return err
}
_, err = io.Copy(ioutil.Discard, resp.Body)
_, err = io.Copy(io.Discard, resp.Body)
if err != nil {
return err
}

View file

@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"time"
@ -60,7 +60,7 @@ func userKeys(httpClient *http.Client, host, userHandle string) ([]gpgKey, error
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

View file

@ -56,12 +56,12 @@ func TestListRun(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
opts := tt.opts
opts.IO = io
opts.IO = ios
opts.Config = func() (config.Config, error) { return config.NewBlankConfig(), nil }
err := listRun(&opts)
if tt.wantErr {

View file

@ -2,7 +2,7 @@ package close
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"regexp"
"testing"
@ -18,13 +18,13 @@ import (
)
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -45,8 +45,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -3,8 +3,8 @@ package comment
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"
@ -20,7 +20,7 @@ import (
func TestNewCmdComment(t *testing.T) {
tmpFile := filepath.Join(t.TempDir(), "my-body.md")
err := ioutil.WriteFile(tmpFile, []byte("a body from file"), 0600)
err := os.WriteFile(tmpFile, []byte("a body from file"), 0600)
require.NoError(t, err)
tests := []struct {
@ -141,17 +141,17 @@ func TestNewCmdComment(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStdinTTY(true)
io.SetStderrTTY(true)
ios, stdin, _, _ := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
if tt.stdin != "" {
_, _ = stdin.WriteString(tt.stdin)
}
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
Browser: &cmdutil.TestBrowser{},
}
@ -246,10 +246,10 @@ func Test_commentRun(t *testing.T) {
},
}
for _, tt := range tests {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStdinTTY(true)
io.SetStderrTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
reg := &httpmock.Registry{}
defer reg.Verify(t)
@ -257,7 +257,7 @@ func Test_commentRun(t *testing.T) {
tt.httpStubs(t, reg)
}
tt.input.IO = io
tt.input.IO = ios
tt.input.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: reg}, nil
}

View file

@ -4,8 +4,9 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
@ -27,7 +28,7 @@ import (
func TestNewCmdCreate(t *testing.T) {
tmpFile := filepath.Join(t.TempDir(), "my-body.md")
err := ioutil.WriteFile(tmpFile, []byte("a body from file"), 0600)
err := os.WriteFile(tmpFile, []byte("a body from file"), 0600)
require.NoError(t, err)
tests := []struct {
@ -93,16 +94,16 @@ func TestNewCmdCreate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, stdout, stderr := iostreams.Test()
ios, stdin, stdout, stderr := iostreams.Test()
if tt.stdin != "" {
_, _ = stdin.WriteString(tt.stdin)
} else if tt.tty {
io.SetStdinTTY(true)
io.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStdoutTTY(true)
}
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *CreateOptions
@ -114,8 +115,8 @@ func TestNewCmdCreate(t *testing.T) {
args, err := shlex.Split(tt.cli)
require.NoError(t, err)
cmd.SetArgs(args)
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantsErr {
assert.Error(t, err)
@ -256,10 +257,10 @@ func Test_createRun(t *testing.T) {
tt.httpStubs(httpReg)
}
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
opts := &tt.opts
opts.IO = io
opts.IO = ios
opts.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: httpReg}, nil
}
@ -291,14 +292,14 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
}
func runCommandWithRootDirOverridden(rt http.RoundTripper, isTTY bool, cli string, rootDir string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
browser := &cmdutil.TestBrowser{}
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -323,8 +324,8 @@ func runCommandWithRootDirOverridden(rt http.RoundTripper, isTTY bool, cli strin
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{
@ -407,7 +408,7 @@ func TestIssueCreate_recover(t *testing.T) {
as.StubPrompt("Body").AnswerDefault()
as.StubPrompt("What's next?").AnswerWith("Submit")
tmpfile, err := ioutil.TempFile(t.TempDir(), "testrecover*")
tmpfile, err := os.CreateTemp(t.TempDir(), "testrecover*")
assert.NoError(t, err)
defer tmpfile.Close()

View file

@ -2,7 +2,7 @@ package delete
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"regexp"
"testing"
@ -19,13 +19,13 @@ import (
)
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -46,8 +46,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -3,8 +3,8 @@ package edit
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"
@ -21,7 +21,7 @@ import (
func TestNewCmdEdit(t *testing.T) {
tmpFile := filepath.Join(t.TempDir(), "my-body.md")
err := ioutil.WriteFile(tmpFile, []byte("a body from file"), 0600)
err := os.WriteFile(tmpFile, []byte("a body from file"), 0600)
require.NoError(t, err)
tests := []struct {
@ -204,17 +204,17 @@ func TestNewCmdEdit(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStdinTTY(true)
io.SetStderrTTY(true)
ios, stdin, _, _ := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
if tt.stdin != "" {
_, _ = stdin.WriteString(tt.stdin)
}
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
argv, err := shlex.Split(tt.input)
@ -338,10 +338,10 @@ func Test_editRun(t *testing.T) {
},
}
for _, tt := range tests {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStdinTTY(true)
io.SetStderrTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
reg := &httpmock.Registry{}
defer reg.Verify(t)
@ -350,7 +350,7 @@ func Test_editRun(t *testing.T) {
httpClient := func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }
baseRepo := func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil }
tt.input.IO = io
tt.input.IO = ios
tt.input.HttpClient = httpClient
tt.input.BaseRepo = baseRepo

View file

@ -2,7 +2,7 @@ package list
import (
"encoding/json"
"io/ioutil"
"io"
"testing"
"github.com/cli/cli/v2/api"
@ -65,7 +65,7 @@ func TestIssueList(t *testing.T) {
Variables map[string]interface{}
}
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
bodyBytes, _ := io.ReadAll(http.Requests[0].Body)
_ = json.Unmarshal(bodyBytes, &reqBody)
if reqLimit := reqBody.Variables["limit"].(float64); reqLimit != 100 {
t.Errorf("expected 100, got %v", reqLimit)
@ -74,7 +74,7 @@ func TestIssueList(t *testing.T) {
t.Error("did not expect first request to pass 'endCursor'")
}
bodyBytes, _ = ioutil.ReadAll(http.Requests[1].Body)
bodyBytes, _ = io.ReadAll(http.Requests[1].Body)
_ = json.Unmarshal(bodyBytes, &reqBody)
if endCursor := reqBody.Variables["endCursor"].(string); endCursor != "ENDCURSOR" {
t.Errorf("expected %q, got %q", "ENDCURSOR", endCursor)

View file

@ -2,7 +2,7 @@ package list
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"regexp"
"testing"
@ -21,13 +21,13 @@ import (
)
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -48,8 +48,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{
@ -182,9 +182,9 @@ func TestIssueList_disabledIssues(t *testing.T) {
}
func TestIssueList_web(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStderrTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStderrTTY(true)
browser := &cmdutil.TestBrowser{}
reg := &httpmock.Registry{}
@ -194,7 +194,7 @@ func TestIssueList_web(t *testing.T) {
defer cmdTeardown(t)
err := listRun(&ListOptions{
IO: io,
IO: ios,
Browser: browser,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: reg}, nil

View file

@ -2,7 +2,7 @@ package reopen
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"regexp"
"testing"
@ -18,13 +18,13 @@ import (
)
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -45,8 +45,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -2,7 +2,7 @@ package status
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"regexp"
"testing"
@ -17,13 +17,13 @@ import (
)
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -44,8 +44,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -2,7 +2,7 @@ package transfer
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"
@ -17,10 +17,10 @@ import (
)
func runCommand(rt http.RoundTripper, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -32,7 +32,7 @@ func runCommand(rt http.RoundTripper, cli string) (*test.CmdOut, error) {
},
}
io.SetStdoutTTY(true)
ios.SetStdoutTTY(true)
cmd := NewCmdTransfer(factory, nil)
@ -43,8 +43,8 @@ func runCommand(rt http.RoundTripper, cli string) (*test.CmdOut, error) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
@ -124,9 +124,9 @@ func Test_transferRunSuccessfulIssueTransfer(t *testing.T) {
http.Register(
httpmock.GraphQL(`query RepositoryInfo\b`),
httpmock.StringResponse(`
{ "data": { "repository": {
{ "data": { "repository": {
"id": "dest-id",
"name": "REPO1",
"name": "REPO1",
"owner": { "login": "OWNER1" },
"viewerPermission": "WRITE",
"hasIssuesEnabled": true

View file

@ -3,7 +3,7 @@ package view
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"
"time"
@ -20,13 +20,13 @@ import (
)
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -47,8 +47,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{
@ -58,9 +58,9 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
}
func TestIssueView_web(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStderrTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStderrTTY(true)
browser := &cmdutil.TestBrowser{}
reg := &httpmock.Registry{}
@ -79,7 +79,7 @@ func TestIssueView_web(t *testing.T) {
defer cmdTeardown(t)
err := viewRun(&ViewOptions{
IO: io,
IO: ios,
Browser: browser,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: reg}, nil
@ -223,10 +223,10 @@ func TestIssueView_tty_Preview(t *testing.T) {
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStdinTTY(true)
io.SetStderrTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
httpReg := &httpmock.Registry{}
defer httpReg.Verify(t)
@ -234,7 +234,7 @@ func TestIssueView_tty_Preview(t *testing.T) {
httpReg.Register(httpmock.GraphQL(`query IssueByNumber\b`), httpmock.FileResponse(tc.fixture))
opts := ViewOptions{
IO: io,
IO: ios,
Now: func() time.Time {
t, _ := time.Parse(time.RFC822, "03 Nov 20 15:04 UTC")
return t

View file

@ -3,7 +3,7 @@ package label
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"testing"
@ -53,9 +53,9 @@ func TestNewCmdCreate(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
argv, err := shlex.Split(tt.input)
assert.NoError(t, err)
@ -144,11 +144,11 @@ func TestCreateRun(t *testing.T) {
tt.opts.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: reg}, nil
}
io, _, stdout, _ := iostreams.Test()
io.SetStdoutTTY(tt.tty)
io.SetStdinTTY(tt.tty)
io.SetStderrTTY(tt.tty)
tt.opts.IO = io
ios, _, stdout, _ := iostreams.Test()
ios.SetStdoutTTY(tt.tty)
ios.SetStdinTTY(tt.tty)
ios.SetStderrTTY(tt.tty)
tt.opts.IO = ios
tt.opts.BaseRepo = func() (ghrepo.Interface, error) {
return ghrepo.New("OWNER", "REPO"), nil
}
@ -157,7 +157,7 @@ func TestCreateRun(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, tt.wantStdout, stdout.String())
bodyBytes, _ := ioutil.ReadAll(reg.Requests[0].Body)
bodyBytes, _ := io.ReadAll(reg.Requests[0].Body)
reqBody := map[string]string{}
err = json.Unmarshal(bodyBytes, &reqBody)
assert.NoError(t, err)

View file

@ -46,9 +46,9 @@ func TestNewCmdList(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
argv, err := shlex.Split(tt.input)
assert.NoError(t, err)
@ -192,11 +192,11 @@ func TestListRun(t *testing.T) {
tt.opts.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: reg}, nil
}
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.tty)
io.SetStdinTTY(tt.tty)
io.SetStderrTTY(tt.tty)
tt.opts.IO = io
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.tty)
ios.SetStdinTTY(tt.tty)
ios.SetStderrTTY(tt.tty)
tt.opts.IO = ios
tt.opts.Browser = &cmdutil.TestBrowser{}
tt.opts.BaseRepo = func() (ghrepo.Interface, error) {
return ghrepo.New("OWNER", "REPO"), nil

View file

@ -3,7 +3,7 @@ package checkout
import (
"bytes"
"errors"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -162,9 +162,8 @@ func Test_checkoutRun(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
opts := tt.opts
io, _, stdout, stderr := iostreams.Test()
opts.IO = io
ios, _, stdout, stderr := iostreams.Test()
opts.IO = ios
httpReg := &httpmock.Registry{}
defer httpReg.Verify(t)
if tt.httpStubs != nil {
@ -211,10 +210,10 @@ func Test_checkoutRun(t *testing.T) {
/** LEGACY TESTS **/
func runCommand(rt http.RoundTripper, remotes context.Remotes, branch string, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -246,8 +245,8 @@ func runCommand(rt http.RoundTripper, remotes context.Remotes, branch string, cl
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -67,9 +67,9 @@ func TestNewCmdChecks(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
ios, _, _, _ := iostreams.Test()
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
argv, err := shlex.Split(tt.cli)
@ -249,16 +249,16 @@ func TestChecksRun_web(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
browser := &cmdutil.TestBrowser{}
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tc.isTTY)
io.SetStdinTTY(tc.isTTY)
io.SetStderrTTY(tc.isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tc.isTTY)
ios.SetStdinTTY(tc.isTTY)
ios.SetStderrTTY(tc.isTTY)
_, teardown := run.Stub()
defer teardown(t)
err := checksRunWebMode(&ChecksOptions{
IO: io,
IO: ios,
Browser: browser,
WebMode: true,
SelectorArg: "123",

View file

@ -2,7 +2,7 @@ package close
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -59,13 +59,13 @@ func stubPR(repo, prHead string) (ghrepo.Interface, *api.PullRequest) {
}
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -83,8 +83,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -3,8 +3,8 @@ package comment
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"
@ -21,7 +21,7 @@ import (
func TestNewCmdComment(t *testing.T) {
tmpFile := filepath.Join(t.TempDir(), "my-body.md")
err := ioutil.WriteFile(tmpFile, []byte("a body from file"), 0600)
err := os.WriteFile(tmpFile, []byte("a body from file"), 0600)
require.NoError(t, err)
tests := []struct {
@ -162,17 +162,17 @@ func TestNewCmdComment(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStdinTTY(true)
io.SetStderrTTY(true)
ios, stdin, _, _ := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
if tt.stdin != "" {
_, _ = stdin.WriteString(tt.stdin)
}
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
Browser: &cmdutil.TestBrowser{},
}
@ -267,10 +267,10 @@ func Test_commentRun(t *testing.T) {
},
}
for _, tt := range tests {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStdinTTY(true)
io.SetStderrTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
reg := &httpmock.Registry{}
defer reg.Verify(t)
@ -280,7 +280,7 @@ func Test_commentRun(t *testing.T) {
httpClient := func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }
tt.input.IO = io
tt.input.IO = ios
tt.input.HttpClient = httpClient
tt.input.RetrieveCommentable = func() (shared.Commentable, ghrepo.Interface, error) {
return &api.PullRequest{

View file

@ -4,8 +4,9 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
"testing"
@ -30,7 +31,7 @@ import (
func TestNewCmdCreate(t *testing.T) {
tmpFile := filepath.Join(t.TempDir(), "my-body.md")
err := ioutil.WriteFile(tmpFile, []byte("a body from file"), 0600)
err := os.WriteFile(tmpFile, []byte("a body from file"), 0600)
require.NoError(t, err)
tests := []struct {
@ -108,16 +109,16 @@ func TestNewCmdCreate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, stdout, stderr := iostreams.Test()
ios, stdin, stdout, stderr := iostreams.Test()
if tt.stdin != "" {
_, _ = stdin.WriteString(tt.stdin)
} else if tt.tty {
io.SetStdinTTY(true)
io.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStdoutTTY(true)
}
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *CreateOptions
@ -160,14 +161,14 @@ func runCommand(rt http.RoundTripper, remotes context.Remotes, branch string, is
}
func runCommandWithRootDirOverridden(rt http.RoundTripper, remotes context.Remotes, branch string, isTTY bool, cli string, rootDir string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
browser := &cmdutil.TestBrowser{}
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
Browser: browser,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
@ -207,8 +208,8 @@ func runCommandWithRootDirOverridden(rt http.RoundTripper, remotes context.Remot
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{
@ -291,7 +292,7 @@ func TestPRCreate_recover(t *testing.T) {
as.StubPrompt("Body").AnswerDefault()
as.StubPrompt("What's next?").AnswerDefault()
tmpfile, err := ioutil.TempFile(t.TempDir(), "testrecover*")
tmpfile, err := os.CreateTemp(t.TempDir(), "testrecover*")
assert.NoError(t, err)
defer tmpfile.Close()
@ -790,7 +791,7 @@ func TestPRCreate_web(t *testing.T) {
func TestPRCreate_webLongURL(t *testing.T) {
longBodyFile := filepath.Join(t.TempDir(), "long-body.txt")
err := ioutil.WriteFile(longBodyFile, make([]byte, 9216), 0600)
err := os.WriteFile(longBodyFile, make([]byte, 9216), 0600)
require.NoError(t, err)
http := initFakeHTTP()

View file

@ -3,7 +3,7 @@ package diff
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -88,14 +88,14 @@ func Test_NewCmdDiff(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
io.SetColorEnabled(tt.isTTY)
ios, _, _, _ := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
ios.SetColorEnabled(tt.isTTY)
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *DiffOptions
@ -110,8 +110,8 @@ func Test_NewCmdDiff(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
@ -184,7 +184,7 @@ func Test_diffRun(t *testing.T) {
return &http.Response{
StatusCode: 200,
Request: req,
Body: ioutil.NopCloser(strings.NewReader(tt.rawDiff)),
Body: io.NopCloser(strings.NewReader(tt.rawDiff)),
}, nil
})
@ -193,9 +193,8 @@ func Test_diffRun(t *testing.T) {
return &http.Client{Transport: httpReg}, nil
}
io, _, stdout, stderr := iostreams.Test()
opts.IO = io
ios, _, stdout, stderr := iostreams.Test()
opts.IO = ios
finder := shared.NewMockFinder("123", pr, ghrepo.New("OWNER", "REPO"))
finder.ExpectFields([]string{"number"})
opts.Finder = finder
@ -239,12 +238,12 @@ const testDiff = `%[2]sdiff --git a/.github/workflows/releases.yml b/.github/wor
@@ -22,8 +22,8 @@ test:
go test ./...
.PHONY: test
%[4]s-site:%[1]s
%[4]s- git clone https://github.com/github/cli.github.com.git "$@"%[1]s
%[3]s+site: bin/gh%[1]s
%[3]s+ bin/gh repo clone github/cli.github.com "$@"%[1]s
site-docs: site
git -C site pull
`

View file

@ -3,8 +3,8 @@ package edit
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"
@ -21,7 +21,7 @@ import (
func TestNewCmdEdit(t *testing.T) {
tmpFile := filepath.Join(t.TempDir(), "my-body.md")
err := ioutil.WriteFile(tmpFile, []byte("a body from file"), 0600)
err := os.WriteFile(tmpFile, []byte("a body from file"), 0600)
require.NoError(t, err)
tests := []struct {
@ -255,17 +255,17 @@ func TestNewCmdEdit(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStdinTTY(true)
io.SetStderrTTY(true)
ios, stdin, _, _ := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
if tt.stdin != "" {
_, _ = stdin.WriteString(tt.stdin)
}
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
argv, err := shlex.Split(tt.input)
@ -450,10 +450,10 @@ func Test_editRun(t *testing.T) {
},
}
for _, tt := range tests {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStdinTTY(true)
io.SetStderrTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStdinTTY(true)
ios.SetStderrTTY(true)
reg := &httpmock.Registry{}
defer reg.Verify(t)
@ -461,7 +461,7 @@ func Test_editRun(t *testing.T) {
httpClient := func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }
tt.input.IO = io
tt.input.IO = ios
tt.input.HttpClient = httpClient
t.Run(tt.name, func(t *testing.T) {

View file

@ -2,7 +2,7 @@ package list
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -19,14 +19,14 @@ import (
)
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
browser := &cmdutil.TestBrowser{}
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
Browser: browser,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
@ -45,8 +45,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -4,8 +4,9 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
@ -30,7 +31,7 @@ import (
func Test_NewCmdMerge(t *testing.T) {
tmpFile := filepath.Join(t.TempDir(), "my-body.md")
err := ioutil.WriteFile(tmpFile, []byte("a body from file"), 0600)
err := os.WriteFile(tmpFile, []byte("a body from file"), 0600)
require.NoError(t, err)
tests := []struct {
@ -150,17 +151,17 @@ func Test_NewCmdMerge(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, stdin, _, _ := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
if tt.stdin != "" {
_, _ = stdin.WriteString(tt.stdin)
}
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *MergeOptions
@ -175,8 +176,8 @@ func Test_NewCmdMerge(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
@ -212,13 +213,13 @@ func stubCommit(pr *api.PullRequest, oid string) {
}
func runCommand(rt http.RoundTripper, branch string, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -248,8 +249,8 @@ func runCommand(rt http.RoundTripper, branch string, isTTY bool, cli string) (*t
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{
@ -1069,9 +1070,9 @@ func TestPRMerge_interactiveWithDeleteBranch(t *testing.T) {
}
func TestPRMerge_interactiveSquashEditCommitMsgAndSubject(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStderrTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStderrTTY(true)
tr := initFakeHTTP()
defer tr.Verify(t)
@ -1125,7 +1126,7 @@ func TestPRMerge_interactiveSquashEditCommitMsgAndSubject(t *testing.T) {
as.StubOne("Submit") // Confirm submit survey
err := mergeRun(&MergeOptions{
IO: io,
IO: ios,
Editor: testEditor{},
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: tr}, nil
@ -1204,9 +1205,9 @@ func Test_mergeMethodSurvey(t *testing.T) {
}
func TestMergeRun_autoMerge(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStderrTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStderrTTY(true)
tr := initFakeHTTP()
defer tr.Verify(t)
@ -1221,7 +1222,7 @@ func TestMergeRun_autoMerge(t *testing.T) {
defer cmdTeardown(t)
err := mergeRun(&MergeOptions{
IO: io,
IO: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: tr}, nil
},
@ -1241,9 +1242,9 @@ func TestMergeRun_autoMerge(t *testing.T) {
}
func TestMergeRun_autoMerge_directMerge(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStderrTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStderrTTY(true)
tr := initFakeHTTP()
defer tr.Verify(t)
@ -1259,7 +1260,7 @@ func TestMergeRun_autoMerge_directMerge(t *testing.T) {
defer cmdTeardown(t)
err := mergeRun(&MergeOptions{
IO: io,
IO: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: tr}, nil
},
@ -1279,9 +1280,9 @@ func TestMergeRun_autoMerge_directMerge(t *testing.T) {
}
func TestMergeRun_disableAutoMerge(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStderrTTY(true)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(true)
ios.SetStderrTTY(true)
tr := initFakeHTTP()
defer tr.Verify(t)
@ -1295,7 +1296,7 @@ func TestMergeRun_disableAutoMerge(t *testing.T) {
defer cmdTeardown(t)
err := mergeRun(&MergeOptions{
IO: io,
IO: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: tr}, nil
},

View file

@ -2,7 +2,7 @@ package ready
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"
@ -51,13 +51,13 @@ func Test_NewCmdReady(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, _, _ := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *ReadyOptions
@ -72,8 +72,8 @@ func Test_NewCmdReady(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
@ -89,13 +89,13 @@ func Test_NewCmdReady(t *testing.T) {
}
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -110,8 +110,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -2,7 +2,7 @@ package reopen
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"
@ -18,13 +18,13 @@ import (
)
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -39,8 +39,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -3,8 +3,9 @@ package review
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
"testing"
@ -26,7 +27,7 @@ import (
func Test_NewCmdReview(t *testing.T) {
tmpFile := filepath.Join(t.TempDir(), "my-body.md")
err := ioutil.WriteFile(tmpFile, []byte("a body from file"), 0600)
err := os.WriteFile(tmpFile, []byte("a body from file"), 0600)
require.NoError(t, err)
tests := []struct {
@ -123,17 +124,17 @@ func Test_NewCmdReview(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, stdin, _, _ := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
if tt.stdin != "" {
_, _ = stdin.WriteString(tt.stdin)
}
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *ReviewOptions
@ -148,8 +149,8 @@ func Test_NewCmdReview(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
@ -166,13 +167,13 @@ func Test_NewCmdReview(t *testing.T) {
}
func runCommand(rt http.RoundTripper, remotes context.Remotes, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -190,8 +191,8 @@ func runCommand(rt http.RoundTripper, remotes context.Remotes, isTTY bool, cli s
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -3,7 +3,8 @@ package shared
import (
"encoding/json"
"errors"
"io/ioutil"
"io"
"os"
"testing"
"github.com/cli/cli/v2/pkg/iostreams"
@ -77,25 +78,25 @@ func Test_PreserveInput(t *testing.T) {
tt.state = &IssueMetadataState{}
}
io, _, _, errOut := iostreams.Test()
ios, _, _, errOut := iostreams.Test()
tf, tferr := ioutil.TempFile(tempDir, "testfile*")
tf, tferr := os.CreateTemp(tempDir, "testfile*")
assert.NoError(t, tferr)
defer tf.Close()
io.TempFileOverride = tf
ios.TempFileOverride = tf
var err error
if tt.err {
err = errors.New("error during creation")
}
PreserveInput(io, tt.state, &err)()
PreserveInput(ios, tt.state, &err)()
_, err = tf.Seek(0, 0)
assert.NoError(t, err)
data, err := ioutil.ReadAll(tf)
data, err := io.ReadAll(tf)
assert.NoError(t, err)
if tt.wantPreservation {

View file

@ -19,7 +19,7 @@ func (mf *metadataFetcher) RepoMetadataFetch(input api.RepoMetadataInput) (*api.
}
func TestMetadataSurvey_selectAll(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
repo := ghrepo.New("OWNER", "REPO")
@ -81,7 +81,7 @@ func TestMetadataSurvey_selectAll(t *testing.T) {
state := &IssueMetadataState{
Assignees: []string{"hubot"},
}
err := MetadataSurvey(io, repo, fetcher, state)
err := MetadataSurvey(ios, repo, fetcher, state)
assert.NoError(t, err)
assert.Equal(t, "", stdout.String())
@ -95,7 +95,7 @@ func TestMetadataSurvey_selectAll(t *testing.T) {
}
func TestMetadataSurvey_keepExisting(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
ios, _, stdout, stderr := iostreams.Test()
repo := ghrepo.New("OWNER", "REPO")
@ -138,7 +138,7 @@ func TestMetadataSurvey_keepExisting(t *testing.T) {
state := &IssueMetadataState{
Assignees: []string{"hubot"},
}
err := MetadataSurvey(io, repo, fetcher, state)
err := MetadataSurvey(ios, repo, fetcher, state)
assert.NoError(t, err)
assert.Equal(t, "", stdout.String())

View file

@ -1,7 +1,6 @@
package shared
import (
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -17,7 +16,7 @@ func TestTemplateManager_hasAPI(t *testing.T) {
rootDir := t.TempDir()
legacyTemplateFile := filepath.Join(rootDir, ".github", "ISSUE_TEMPLATE.md")
_ = os.MkdirAll(filepath.Dir(legacyTemplateFile), 0755)
_ = ioutil.WriteFile(legacyTemplateFile, []byte("LEGACY"), 0644)
_ = os.WriteFile(legacyTemplateFile, []byte("LEGACY"), 0644)
tr := httpmock.Registry{}
httpClient := &http.Client{Transport: &tr}
@ -79,7 +78,7 @@ func TestTemplateManager_hasAPI_PullRequest(t *testing.T) {
rootDir := t.TempDir()
legacyTemplateFile := filepath.Join(rootDir, ".github", "PULL_REQUEST_TEMPLATE.md")
_ = os.MkdirAll(filepath.Dir(legacyTemplateFile), 0755)
_ = ioutil.WriteFile(legacyTemplateFile, []byte("LEGACY"), 0644)
_ = os.WriteFile(legacyTemplateFile, []byte("LEGACY"), 0644)
tr := httpmock.Registry{}
httpClient := &http.Client{Transport: &tr}

View file

@ -2,7 +2,7 @@ package status
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
@ -20,13 +20,13 @@ import (
)
func runCommand(rt http.RoundTripper, branch string, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
@ -62,8 +62,8 @@ func runCommand(rt http.RoundTripper, branch string, isTTY bool, cli string) (*t
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"testing"
@ -75,13 +75,13 @@ func Test_NewCmdView(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, _, _ := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *ViewOptions
@ -96,8 +96,8 @@ func Test_NewCmdView(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
@ -113,14 +113,14 @@ func Test_NewCmdView(t *testing.T) {
}
func runCommand(rt http.RoundTripper, branch string, isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
ios.SetStdinTTY(isTTY)
ios.SetStderrTTY(isTTY)
browser := &cmdutil.TestBrowser{}
factory := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
Browser: browser,
}
@ -133,8 +133,8 @@ func runCommand(rt http.RoundTripper, branch string, isTTY bool, cli string) (*t
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{

View file

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -26,7 +25,7 @@ import (
func Test_NewCmdCreate(t *testing.T) {
tempDir := t.TempDir()
tf, err := ioutil.TempFile(tempDir, "release-create")
tf, err := os.CreateTemp(tempDir, "release-create")
require.NoError(t, err)
fmt.Fprint(tf, "MY NOTES")
tf.Close()
@ -225,18 +224,18 @@ func Test_NewCmdCreate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
ios, stdin, _, _ := iostreams.Test()
if tt.stdin == "" {
io.SetStdinTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
} else {
io.SetStdinTTY(false)
ios.SetStdinTTY(false)
fmt.Fprint(stdin, tt.stdin)
}
io.SetStdoutTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios.SetStdoutTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *CreateOptions
@ -251,8 +250,8 @@ func Test_NewCmdCreate(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
@ -446,7 +445,7 @@ func Test_createRun(t *testing.T) {
{
Name: "ball.tgz",
Open: func() (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewBufferString(`TARBALL`)), nil
return io.NopCloser(bytes.NewBufferString(`TARBALL`)), nil
},
},
},
@ -471,7 +470,7 @@ func Test_createRun(t *testing.T) {
return &http.Response{
StatusCode: 201,
Request: req,
Body: ioutil.NopCloser(bytes.NewBufferString(`{}`)),
Body: io.NopCloser(bytes.NewBufferString(`{}`)),
Header: map[string][]string{
"Content-Type": {"application/json"},
},
@ -502,7 +501,7 @@ func Test_createRun(t *testing.T) {
{
Name: "ball.tgz",
Open: func() (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewBufferString(`TARBALL`)), nil
return io.NopCloser(bytes.NewBufferString(`TARBALL`)), nil
},
},
},
@ -529,7 +528,7 @@ func Test_createRun(t *testing.T) {
return &http.Response{
StatusCode: 201,
Request: req,
Body: ioutil.NopCloser(bytes.NewBufferString(`{}`)),
Body: io.NopCloser(bytes.NewBufferString(`{}`)),
Header: map[string][]string{
"Content-Type": {"application/json"},
},
@ -550,10 +549,10 @@ func Test_createRun(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
fakeHTTP := &httpmock.Registry{}
if tt.httpStubs != nil {
@ -561,7 +560,7 @@ func Test_createRun(t *testing.T) {
}
defer fakeHTTP.Verify(t)
tt.opts.IO = io
tt.opts.IO = ios
tt.opts.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: fakeHTTP}, nil
}
@ -883,7 +882,7 @@ func Test_createRun_interactive(t *testing.T) {
if r == nil {
t.Fatalf("no http requests for creating a release found")
}
bb, err := ioutil.ReadAll(r.Body)
bb, err := io.ReadAll(r.Body)
assert.NoError(t, err)
var params map[string]interface{}
err = json.Unmarshal(bb, &params)

View file

@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"github.com/cli/cli/v2/api"
@ -109,7 +108,7 @@ func generateReleaseNotes(httpClient *http.Client, repo ghrepo.Interface, params
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
@ -145,7 +144,7 @@ func createRelease(httpClient *http.Client, repo ghrepo.Interface, params map[st
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
@ -182,7 +181,7 @@ func publishRelease(httpClient *http.Client, releaseURL string, discussionCatego
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

View file

@ -2,7 +2,7 @@ package deleteasset
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"
@ -58,13 +58,13 @@ func Test_NewCmdDeleteAsset(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, _, _ := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *DeleteAssetOptions
@ -78,8 +78,8 @@ func Test_NewCmdDeleteAsset(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
@ -130,10 +130,10 @@ func Test_deleteAssetRun(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
fakeHTTP := &httpmock.Registry{}
fakeHTTP.Register(httpmock.REST("GET", "repos/OWNER/REPO/releases/tags/v1.2.3"), httpmock.StringResponse(`{
@ -150,7 +150,7 @@ func Test_deleteAssetRun(t *testing.T) {
}`))
fakeHTTP.Register(httpmock.REST("DELETE", "repos/OWNER/REPO/releases/assets/1"), httpmock.StatusStringResponse(204, ""))
tt.opts.IO = io
tt.opts.IO = ios
tt.opts.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: fakeHTTP}, nil
}

View file

@ -2,7 +2,7 @@ package delete
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"
@ -51,13 +51,13 @@ func Test_NewCmdDelete(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, _, _ := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *DeleteOptions
@ -72,8 +72,8 @@ func Test_NewCmdDelete(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
@ -124,10 +124,10 @@ func Test_deleteRun(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
fakeHTTP := &httpmock.Registry{}
fakeHTTP.Register(httpmock.REST("GET", "repos/OWNER/REPO/releases/tags/v1.2.3"), httpmock.StringResponse(`{
@ -137,7 +137,7 @@ func Test_deleteRun(t *testing.T) {
}`))
fakeHTTP.Register(httpmock.REST("DELETE", "repos/OWNER/REPO/releases/23456"), httpmock.StatusStringResponse(204, ""))
tt.opts.IO = io
tt.opts.IO = ios
tt.opts.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: fakeHTTP}, nil
}

View file

@ -2,7 +2,7 @@ package download
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
@ -113,13 +113,13 @@ func Test_NewCmdDownload(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, _, _ := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *DownloadOptions
@ -134,8 +134,8 @@ func Test_NewCmdDownload(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
@ -244,10 +244,10 @@ func Test_downloadRun(t *testing.T) {
tempDir := t.TempDir()
tt.opts.Destination = filepath.Join(tempDir, tt.opts.Destination)
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
fakeHTTP := &httpmock.Registry{}
fakeHTTP.Register(httpmock.REST("GET", "repos/OWNER/REPO/releases/tags/v1.2.3"), httpmock.StringResponse(`{
@ -286,7 +286,7 @@ func Test_downloadRun(t *testing.T) {
),
)
tt.opts.IO = io
tt.opts.IO = ios
tt.opts.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: fakeHTTP}, nil
}

View file

@ -3,8 +3,9 @@ package edit
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"testing"
"github.com/cli/cli/v2/internal/ghrepo"
@ -18,7 +19,7 @@ import (
func Test_NewCmdEdit(t *testing.T) {
tempDir := t.TempDir()
tf, err := ioutil.TempFile(tempDir, "release-create")
tf, err := os.CreateTemp(tempDir, "release-create")
require.NoError(t, err)
fmt.Fprint(tf, "MY NOTES")
tf.Close()
@ -124,18 +125,18 @@ func Test_NewCmdEdit(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, stdin, _, _ := iostreams.Test()
ios, stdin, _, _ := iostreams.Test()
if tt.stdin == "" {
io.SetStdinTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
} else {
io.SetStdinTTY(false)
ios.SetStdinTTY(false)
fmt.Fprint(stdin, tt.stdin)
}
io.SetStdoutTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios.SetStdoutTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *EditOptions
@ -150,8 +151,8 @@ func Test_NewCmdEdit(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
@ -372,10 +373,10 @@ func Test_editRun(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
fakeHTTP := &httpmock.Registry{}
fakeHTTP.Register(httpmock.REST("GET", "repos/OWNER/REPO/releases/tags/v1.2.3"), httpmock.JSONResponse(map[string]interface{}{
@ -387,7 +388,7 @@ func Test_editRun(t *testing.T) {
}
defer fakeHTTP.Verify(t)
tt.opts.IO = io
tt.opts.IO = ios
tt.opts.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: fakeHTTP}, nil
}

View file

@ -4,12 +4,13 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"github.com/cli/cli/v2/api"
"github.com/cli/cli/v2/internal/ghinstance"
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/pkg/cmd/release/shared"
"io/ioutil"
"net/http"
)
func editRelease(httpClient *http.Client, repo ghrepo.Interface, releaseID int64, params map[string]interface{}) (*shared.Release, error) {
@ -38,7 +39,7 @@ func editRelease(httpClient *http.Client, repo ghrepo.Interface, releaseID int64
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

View file

@ -3,7 +3,7 @@ package list
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"
"time"
@ -37,13 +37,13 @@ func Test_NewCmdList(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, _, _ := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
f := &cmdutil.Factory{
IOStreams: io,
IOStreams: ios,
}
var opts *ListOptions
@ -58,8 +58,8 @@ func Test_NewCmdList(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
@ -117,10 +117,10 @@ func Test_listRun(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
ios.SetStdinTTY(tt.isTTY)
ios.SetStderrTTY(tt.isTTY)
createdAt := frozenTime
if tt.isTTY {
@ -170,7 +170,7 @@ func Test_listRun(t *testing.T) {
]
} } } }`, createdAt.Format(time.RFC3339))))
tt.opts.IO = io
tt.opts.IO = ios
tt.opts.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: fakeHTTP}, nil
}

View file

@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"reflect"
"strings"
@ -141,7 +141,7 @@ func FetchRelease(httpClient *http.Client, baseRepo ghrepo.Interface, tagName st
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
@ -174,7 +174,7 @@ func FetchLatestRelease(httpClient *http.Client, baseRepo ghrepo.Interface) (*Re
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
@ -211,7 +211,7 @@ func FindDraftRelease(httpClient *http.Client, baseRepo ghrepo.Interface, tagNam
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

View file

@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"mime"
"net/http"
"net/url"
@ -183,7 +182,7 @@ func uploadAsset(httpClient *http.Client, uploadURL string, asset AssetForUpload
return nil, api.HandleHTTPError(resp)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

Some files were not shown because too many files have changed in this diff Show more