mirror of https://gitlab.com/gitlab-org/cli.git
chore: fix ioutil lint deprecations
This commit is contained in:
parent
14c6e3e8a5
commit
cf0968d56d
|
@ -5,10 +5,10 @@ import (
|
|||
"crypto/x509"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -165,7 +165,7 @@ func NewClientWithCustomCA(host, token, caFile string, isGraphQL bool) (*Client,
|
|||
apiClient.isGraphQL = isGraphQL
|
||||
|
||||
if apiClient.httpClientOverride == nil {
|
||||
caCert, err := ioutil.ReadFile(apiClient.caFile)
|
||||
caCert, err := os.ReadFile(apiClient.caFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading cert file: %w", err)
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ func NewClientWithCustomCAClientCert(host, token, caFile string, certFile string
|
|||
apiClient.isGraphQL = isGraphQL
|
||||
|
||||
if apiClient.httpClientOverride == nil {
|
||||
caCert, err := ioutil.ReadFile(apiClient.caFile)
|
||||
caCert, err := os.ReadFile(apiClient.caFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading cert file: %w", err)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package request
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
@ -26,7 +25,7 @@ func MakeRequest(payload, url, method string) (string, error) {
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
bodyBytes, _ := ioutil.ReadAll(resp.Body)
|
||||
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||
bodyString := string(bodyBytes)
|
||||
|
||||
return bodyString, nil
|
||||
|
|
|
@ -2,7 +2,7 @@ package delete
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"gitlab.com/gitlab-org/cli/pkg/iostreams"
|
||||
|
@ -50,16 +50,16 @@ 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.IsaTTY = tt.isTTY
|
||||
io.IsErrTTY = tt.isTTY
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.IsaTTY = tt.isTTY
|
||||
ios.IsErrTTY = tt.isTTY
|
||||
|
||||
factoryConf := &cmdutils.Factory{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
Config: func() (config.Config, error) {
|
||||
return cfg, nil
|
||||
},
|
||||
|
@ -72,8 +72,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 != "" {
|
||||
|
|
|
@ -2,7 +2,7 @@ package list
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"gitlab.com/gitlab-org/cli/pkg/iostreams"
|
||||
|
@ -46,27 +46,27 @@ 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.IsaTTY = tt.isaTTy
|
||||
io.IsErrTTY = tt.isaTTy
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.IsaTTY = tt.isaTTy
|
||||
ios.IsErrTTY = tt.isaTTy
|
||||
|
||||
factoryConf := &cmdutils.Factory{
|
||||
Config: func() (config.Config, error) {
|
||||
return cfg, nil
|
||||
},
|
||||
IO: io,
|
||||
IO: ios,
|
||||
}
|
||||
|
||||
cmd := NewCmdList(factoryConf, nil)
|
||||
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()
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -2,7 +2,7 @@ package set
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"gitlab.com/gitlab-org/cli/pkg/iostreams"
|
||||
|
@ -20,15 +20,15 @@ import (
|
|||
)
|
||||
|
||||
func runCommand(cfg config.Config, isTTY bool, cli string) (*test.CmdOut, error) {
|
||||
io, _, stdout, stderr := iostreams.Test()
|
||||
io.IsaTTY = isTTY
|
||||
io.IsErrTTY = isTTY
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.IsaTTY = isTTY
|
||||
ios.IsErrTTY = isTTY
|
||||
|
||||
factoryConf := &cmdutils.Factory{
|
||||
Config: func() (config.Config, error) {
|
||||
return cfg, nil
|
||||
},
|
||||
IO: io,
|
||||
IO: ios,
|
||||
}
|
||||
|
||||
cmd := NewCmdSet(factoryConf, nil)
|
||||
|
@ -51,8 +51,8 @@ func runCommand(cfg config.Config, isTTY bool, cli string) (*test.CmdOut, error)
|
|||
rootCmd.SetArgs(argv)
|
||||
|
||||
rootCmd.SetIn(&bytes.Buffer{})
|
||||
rootCmd.SetOut(ioutil.Discard)
|
||||
rootCmd.SetErr(ioutil.Discard)
|
||||
rootCmd.SetOut(io.Discard)
|
||||
rootCmd.SetErr(io.Discard)
|
||||
|
||||
_, err = rootCmd.ExecuteC()
|
||||
return &test.CmdOut{
|
||||
|
@ -62,7 +62,7 @@ func runCommand(cfg config.Config, isTTY bool, cli string) (*test.CmdOut, error)
|
|||
}
|
||||
|
||||
func TestAliasSet_glab_command(t *testing.T) {
|
||||
defer config.StubWriteConfig(ioutil.Discard, ioutil.Discard)()
|
||||
defer config.StubWriteConfig(io.Discard, io.Discard)()
|
||||
|
||||
cfg := config.NewFromString(``)
|
||||
|
||||
|
@ -75,7 +75,7 @@ func TestAliasSet_glab_command(t *testing.T) {
|
|||
|
||||
func TestAliasSet_empty_aliases(t *testing.T) {
|
||||
mainBuf := bytes.Buffer{}
|
||||
defer config.StubWriteConfig(ioutil.Discard, &mainBuf)()
|
||||
defer config.StubWriteConfig(io.Discard, &mainBuf)()
|
||||
|
||||
cfg := config.NewFromString(heredoc.Doc(`
|
||||
aliases:
|
||||
|
@ -97,7 +97,7 @@ func TestAliasSet_empty_aliases(t *testing.T) {
|
|||
|
||||
func TestAliasSet_existing_alias(t *testing.T) {
|
||||
mainBuf := bytes.Buffer{}
|
||||
defer config.StubWriteConfig(ioutil.Discard, &mainBuf)()
|
||||
defer config.StubWriteConfig(io.Discard, &mainBuf)()
|
||||
|
||||
cfg := config.NewFromString(heredoc.Doc(`
|
||||
aliases:
|
||||
|
@ -112,7 +112,7 @@ func TestAliasSet_existing_alias(t *testing.T) {
|
|||
|
||||
func TestAliasSet_space_args(t *testing.T) {
|
||||
mainBuf := bytes.Buffer{}
|
||||
defer config.StubWriteConfig(ioutil.Discard, &mainBuf)()
|
||||
defer config.StubWriteConfig(io.Discard, &mainBuf)()
|
||||
|
||||
cfg := config.NewFromString(``)
|
||||
|
||||
|
@ -150,7 +150,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(ioutil.Discard, &mainBuf)()
|
||||
defer config.StubWriteConfig(io.Discard, &mainBuf)()
|
||||
|
||||
cfg := config.NewFromString(``)
|
||||
|
||||
|
@ -167,7 +167,7 @@ func TestAliasSet_arg_processing(t *testing.T) {
|
|||
|
||||
func TestAliasSet_init_alias_cfg(t *testing.T) {
|
||||
mainBuf := bytes.Buffer{}
|
||||
defer config.StubWriteConfig(ioutil.Discard, &mainBuf)()
|
||||
defer config.StubWriteConfig(io.Discard, &mainBuf)()
|
||||
|
||||
cfg := config.NewFromString(heredoc.Doc(`
|
||||
editor: vim
|
||||
|
@ -185,7 +185,7 @@ func TestAliasSet_init_alias_cfg(t *testing.T) {
|
|||
|
||||
func TestAliasSet_existing_aliases(t *testing.T) {
|
||||
mainBuf := bytes.Buffer{}
|
||||
defer config.StubWriteConfig(ioutil.Discard, &mainBuf)()
|
||||
defer config.StubWriteConfig(io.Discard, &mainBuf)()
|
||||
|
||||
cfg := config.NewFromString(heredoc.Doc(`
|
||||
aliases:
|
||||
|
@ -204,7 +204,7 @@ view: mr view
|
|||
}
|
||||
|
||||
func TestAliasSet_invalid_command(t *testing.T) {
|
||||
defer config.StubWriteConfig(ioutil.Discard, ioutil.Discard)()
|
||||
defer config.StubWriteConfig(io.Discard, io.Discard)()
|
||||
|
||||
cfg := config.NewFromString(``)
|
||||
|
||||
|
@ -216,7 +216,7 @@ func TestAliasSet_invalid_command(t *testing.T) {
|
|||
|
||||
func TestShellAlias_flag(t *testing.T) {
|
||||
mainBuf := bytes.Buffer{}
|
||||
defer config.StubWriteConfig(ioutil.Discard, &mainBuf)()
|
||||
defer config.StubWriteConfig(io.Discard, &mainBuf)()
|
||||
|
||||
cfg := config.NewFromString(``)
|
||||
|
||||
|
@ -234,7 +234,7 @@ func TestShellAlias_flag(t *testing.T) {
|
|||
|
||||
func TestShellAlias_bang(t *testing.T) {
|
||||
mainBuf := bytes.Buffer{}
|
||||
defer config.StubWriteConfig(ioutil.Discard, &mainBuf)()
|
||||
defer config.StubWriteConfig(io.Discard, &mainBuf)()
|
||||
|
||||
cfg := config.NewFromString(``)
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -238,7 +237,7 @@ func apiRun(opts *ApiOptions) error {
|
|||
|
||||
headersOutputStream := opts.IO.StdOut
|
||||
if opts.Silent {
|
||||
opts.IO.StdOut = ioutil.Discard
|
||||
opts.IO.StdOut = io.Discard
|
||||
} else {
|
||||
err := opts.IO.StartPager()
|
||||
if err != nil {
|
||||
|
@ -489,7 +488,7 @@ func readUserFile(fn string, stdin io.ReadCloser) ([]byte, error) {
|
|||
}
|
||||
}
|
||||
defer r.Close()
|
||||
return ioutil.ReadAll(r)
|
||||
return io.ReadAll(r)
|
||||
}
|
||||
|
||||
func openUserFile(fn string, stdin io.ReadCloser) (io.ReadCloser, int64, error) {
|
||||
|
@ -512,7 +511,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
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
|
@ -256,7 +256,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!`,
|
||||
|
@ -271,7 +271,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,
|
||||
|
@ -292,7 +292,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: cmdutils.SilentError,
|
||||
|
@ -303,7 +303,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: cmdutils.SilentError,
|
||||
|
@ -317,7 +317,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: cmdutils.SilentError,
|
||||
|
@ -328,7 +328,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: cmdutils.SilentError,
|
||||
stdout: `gateway timeout`,
|
||||
|
@ -341,7 +341,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: ``,
|
||||
|
@ -357,7 +357,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,
|
||||
|
@ -368,9 +368,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 = config.NewBlankConfig()
|
||||
tt.options.HttpClient = func() (*gitlab.Client, error) {
|
||||
var tr roundTripFunc = func(req *http.Request) (*http.Response, error) {
|
||||
|
@ -401,33 +401,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://gitlab.com/api/v4/projects/1227/issues?page=2>; rel="next", <https://gitlab.com/api/v4/projects/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://gitlab.com/api/v4/projects/1227/issues?page=3>; rel="next", <https://gitlab.com/api/v4/projects/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,
|
||||
Config: config.NewBlankConfig(),
|
||||
HttpClient: func() (*gitlab.Client, error) {
|
||||
var tr roundTripFunc = func(req *http.Request) (*http.Response, error) {
|
||||
|
@ -459,14 +459,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": {
|
||||
|
@ -479,7 +479,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": {
|
||||
|
@ -492,7 +492,7 @@ func Test_apiRun_paginationGraphQL(t *testing.T) {
|
|||
}
|
||||
|
||||
options := ApiOptions{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
Config: config.NewBlankConfig(),
|
||||
HttpClient: func() (*gitlab.Client, error) {
|
||||
var tr roundTripFunc = func(req *http.Request) (*http.Response, error) {
|
||||
|
@ -524,14 +524,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)
|
||||
|
@ -564,14 +564,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("", tt.inputFile)
|
||||
f, err := os.CreateTemp("", tt.inputFile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -587,12 +587,12 @@ func Test_apiRun_inputFile(t *testing.T) {
|
|||
RequestInputFile: inputFile,
|
||||
RawFields: []string{"a=b", "c=d"},
|
||||
|
||||
IO: io,
|
||||
IO: ios,
|
||||
Config: config.NewBlankConfig(),
|
||||
HttpClient: func() (*gitlab.Client, error) {
|
||||
var tr roundTripFunc = 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
|
||||
|
@ -621,11 +621,11 @@ func Test_apiRun_inputFile(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",
|
||||
|
@ -657,7 +657,7 @@ func Test_parseFields(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_magicFieldValue(t *testing.T) {
|
||||
f, err := ioutil.TempFile("", "gitlab-test")
|
||||
f, err := os.CreateTemp("", "gitlab-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -665,7 +665,7 @@ func Test_magicFieldValue(t *testing.T) {
|
|||
f.Close()
|
||||
t.Cleanup(func() { os.Remove(f.Name()) })
|
||||
|
||||
io, _, _, _ := iostreams.Test()
|
||||
ios, _, _, _ := iostreams.Test()
|
||||
|
||||
type args struct {
|
||||
v string
|
||||
|
@ -706,7 +706,7 @@ func Test_magicFieldValue(t *testing.T) {
|
|||
args: args{
|
||||
v: ":namespace",
|
||||
opts: &ApiOptions{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
BaseRepo: func() (glrepo.Interface, error) {
|
||||
return glrepo.New("gitlab-com", "www-gitlab-com"), nil
|
||||
},
|
||||
|
@ -719,7 +719,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,
|
||||
|
@ -728,7 +728,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,
|
||||
|
@ -750,7 +750,7 @@ func Test_magicFieldValue(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_openUserFile(t *testing.T) {
|
||||
f, err := ioutil.TempFile("", "gitlab-test")
|
||||
f, err := os.CreateTemp("", "gitlab-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -764,7 +764,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)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
|
@ -249,7 +249,7 @@ hosts:
|
|||
t.Errorf("Request.URL = %q, want %q", req.URL.String(), tt.want.u)
|
||||
}
|
||||
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
|
||||
|
|
|
@ -3,7 +3,7 @@ package login
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
@ -69,7 +69,7 @@ func NewCmdLogin(f *cmdutils.Factory) *cobra.Command {
|
|||
|
||||
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 STDIN: %w", err)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -93,7 +92,7 @@ func RunTrace(ctx context.Context, apiClient *gitlab.Client, w io.Writer, pid in
|
|||
}
|
||||
fmt.Fprintf(w, "Showing logs for %s job #%d\n", job.Name, job.ID)
|
||||
})
|
||||
_, _ = io.CopyN(ioutil.Discard, trace, offset)
|
||||
_, _ = io.CopyN(io.Discard, trace, offset)
|
||||
lenT, err := io.Copy(w, trace)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
|
@ -67,7 +66,7 @@ func lintRun(f *cmdutils.Factory, path string) error {
|
|||
}
|
||||
content = stdout.Bytes()
|
||||
} else {
|
||||
content, err = ioutil.ReadFile(path)
|
||||
content, err = os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return fmt.Errorf("%s: no such file or directory", path)
|
||||
|
|
|
@ -3,7 +3,7 @@ package cmdutils
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
@ -54,7 +54,7 @@ func LoadGitLabTemplate(tmplType, tmplName string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
tmpl, err := ioutil.ReadAll(f)
|
||||
tmpl, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package list
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
@ -27,17 +27,17 @@ import (
|
|||
)
|
||||
|
||||
func runCommand(rt http.RoundTripper, isTTY bool, cli string, runE func(opts *ListOptions) error, doHyperlinks string) (*test.CmdOut, error) {
|
||||
io, _, stdout, stderr := iostreams.Test()
|
||||
io.IsaTTY = isTTY
|
||||
io.IsInTTY = isTTY
|
||||
io.IsErrTTY = isTTY
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.IsaTTY = isTTY
|
||||
ios.IsInTTY = isTTY
|
||||
ios.IsErrTTY = isTTY
|
||||
|
||||
if doHyperlinks != "" {
|
||||
io.SetDisplayHyperlinks(doHyperlinks)
|
||||
ios.SetDisplayHyperlinks(doHyperlinks)
|
||||
}
|
||||
|
||||
factory := &cmdutils.Factory{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
HttpClient: func() (*gitlab.Client, error) {
|
||||
a, err := api.TestClient(&http.Client{Transport: rt}, "", "", false)
|
||||
if err != nil {
|
||||
|
@ -65,8 +65,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string, runE func(opts *Li
|
|||
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{
|
||||
|
@ -76,16 +76,16 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string, runE func(opts *Li
|
|||
}
|
||||
|
||||
func TestNewCmdList(t *testing.T) {
|
||||
io, _, _, _ := iostreams.Test()
|
||||
io.IsaTTY = true
|
||||
io.IsInTTY = true
|
||||
io.IsErrTTY = true
|
||||
ios, _, _, _ := iostreams.Test()
|
||||
ios.IsaTTY = true
|
||||
ios.IsInTTY = true
|
||||
ios.IsErrTTY = true
|
||||
|
||||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
factory := &cmdutils.Factory{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
HttpClient: func() (*gitlab.Client, error) {
|
||||
a, err := api.TestClient(&http.Client{Transport: fakeHTTP}, "", "", false)
|
||||
if err != nil {
|
||||
|
|
|
@ -2,7 +2,7 @@ package note
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
|
@ -22,13 +22,13 @@ import (
|
|||
)
|
||||
|
||||
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
|
||||
io, _, stdout, stderr := iostreams.Test()
|
||||
io.IsaTTY = isTTY
|
||||
io.IsInTTY = isTTY
|
||||
io.IsErrTTY = isTTY
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.IsaTTY = isTTY
|
||||
ios.IsInTTY = isTTY
|
||||
ios.IsErrTTY = isTTY
|
||||
|
||||
factory := &cmdutils.Factory{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
HttpClient: func() (*gitlab.Client, error) {
|
||||
a, err := api.TestClient(&http.Client{Transport: rt}, "", "", false)
|
||||
if err != nil {
|
||||
|
@ -57,8 +57,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{
|
||||
|
|
|
@ -2,7 +2,7 @@ package update
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -91,9 +91,9 @@ func TestNewCmdUpdate(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
io, _, stdout, stderr := iostreams.Test()
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
f := cmdtest.StubFactory("https://gitlab.com/glab-cli/test")
|
||||
f.IO = io
|
||||
f.IO = ios
|
||||
f.IO.IsaTTY = true
|
||||
f.IO.IsErrTTY = true
|
||||
|
||||
|
@ -104,8 +104,8 @@ func TestNewCmdUpdate(t *testing.T) {
|
|||
t.Run(tc.Name, func(t *testing.T) {
|
||||
args, _ := shlex.Split(tc.Issue)
|
||||
cmd.SetArgs(args)
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetErr(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
cmd.SetErr(io.Discard)
|
||||
|
||||
_, err := cmd.ExecuteC()
|
||||
if tc.wantErr {
|
||||
|
|
|
@ -3,7 +3,7 @@ package create
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
@ -28,13 +28,13 @@ import (
|
|||
)
|
||||
|
||||
func runCommand(rt http.RoundTripper, remotes glrepo.Remotes, runE func(opts *CreateOpts) error, branch string, isTTY bool, cli string) (*test.CmdOut, error) {
|
||||
io, _, stdout, stderr := iostreams.Test()
|
||||
io.IsaTTY = isTTY
|
||||
io.IsInTTY = isTTY
|
||||
io.IsErrTTY = isTTY
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.IsaTTY = isTTY
|
||||
ios.IsInTTY = isTTY
|
||||
ios.IsErrTTY = isTTY
|
||||
|
||||
factory := &cmdutils.Factory{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
HttpClient: func() (*gitlab.Client, error) {
|
||||
a, err := api.TestClient(&http.Client{Transport: rt}, "", "", false)
|
||||
if err != nil {
|
||||
|
@ -80,8 +80,8 @@ func runCommand(rt http.RoundTripper, remotes glrepo.Remotes, runE func(opts *Cr
|
|||
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{
|
||||
|
|
|
@ -3,7 +3,7 @@ package diff
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -72,13 +72,13 @@ func Test_NewCmdDiff(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
io, _, _, _ := iostreams.Test()
|
||||
io.IsaTTY = tt.isTTY
|
||||
io.IsInTTY = tt.isTTY
|
||||
io.IsErrTTY = tt.isTTY
|
||||
ios, _, _, _ := iostreams.Test()
|
||||
ios.IsaTTY = tt.isTTY
|
||||
ios.IsInTTY = tt.isTTY
|
||||
ios.IsErrTTY = tt.isTTY
|
||||
|
||||
f := &cmdutils.Factory{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
}
|
||||
|
||||
var opts *DiffOptions
|
||||
|
@ -93,8 +93,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 != "" {
|
||||
|
@ -111,13 +111,13 @@ func Test_NewCmdDiff(t *testing.T) {
|
|||
}
|
||||
|
||||
func runCommand(remotes glrepo.Remotes, isTTY bool, cli string) (*test.CmdOut, error) {
|
||||
io, _, stdout, stderr := iostreams.Test()
|
||||
io.IsaTTY = isTTY
|
||||
io.IsInTTY = isTTY
|
||||
io.IsErrTTY = isTTY
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.IsaTTY = isTTY
|
||||
ios.IsInTTY = isTTY
|
||||
ios.IsErrTTY = isTTY
|
||||
|
||||
factory := &cmdutils.Factory{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
Config: func() (config.Config, error) {
|
||||
return config.NewBlankConfig(), nil
|
||||
},
|
||||
|
@ -157,8 +157,8 @@ func runCommand(remotes glrepo.Remotes, isTTY bool, cli string) (*test.CmdOut, e
|
|||
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{
|
||||
|
|
|
@ -2,7 +2,7 @@ package issues
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
@ -22,13 +22,13 @@ import (
|
|||
)
|
||||
|
||||
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
|
||||
io, _, stdout, stderr := iostreams.Test()
|
||||
io.IsaTTY = isTTY
|
||||
io.IsInTTY = isTTY
|
||||
io.IsErrTTY = isTTY
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.IsaTTY = isTTY
|
||||
ios.IsInTTY = isTTY
|
||||
ios.IsErrTTY = isTTY
|
||||
|
||||
factory := &cmdutils.Factory{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
HttpClient: func() (*gitlab.Client, error) {
|
||||
a, err := api.TestClient(&http.Client{Transport: rt}, "", "", false)
|
||||
if err != nil {
|
||||
|
@ -53,8 +53,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{
|
||||
|
|
|
@ -3,7 +3,7 @@ package list
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
@ -27,17 +27,17 @@ import (
|
|||
)
|
||||
|
||||
func runCommand(rt http.RoundTripper, isTTY bool, cli string, runE func(opts *ListOptions) error, doHyperlinks string) (*test.CmdOut, error) {
|
||||
io, _, stdout, stderr := iostreams.Test()
|
||||
io.IsaTTY = isTTY
|
||||
io.IsInTTY = isTTY
|
||||
io.IsErrTTY = isTTY
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.IsaTTY = isTTY
|
||||
ios.IsInTTY = isTTY
|
||||
ios.IsErrTTY = isTTY
|
||||
|
||||
if doHyperlinks != "" {
|
||||
io.SetDisplayHyperlinks(doHyperlinks)
|
||||
ios.SetDisplayHyperlinks(doHyperlinks)
|
||||
}
|
||||
|
||||
factory := &cmdutils.Factory{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
HttpClient: func() (*gitlab.Client, error) {
|
||||
a, err := api.TestClient(&http.Client{Transport: rt}, "", "", false)
|
||||
if err != nil {
|
||||
|
@ -65,8 +65,8 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string, runE func(opts *Li
|
|||
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{
|
||||
|
@ -76,16 +76,16 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string, runE func(opts *Li
|
|||
}
|
||||
|
||||
func TestNewCmdList(t *testing.T) {
|
||||
io, _, _, _ := iostreams.Test()
|
||||
io.IsaTTY = true
|
||||
io.IsInTTY = true
|
||||
io.IsErrTTY = true
|
||||
ios, _, _, _ := iostreams.Test()
|
||||
ios.IsaTTY = true
|
||||
ios.IsInTTY = true
|
||||
ios.IsErrTTY = true
|
||||
|
||||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
factory := &cmdutils.Factory{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
HttpClient: func() (*gitlab.Client, error) {
|
||||
a, err := api.TestClient(&http.Client{Transport: fakeHTTP}, "", "", false)
|
||||
if err != nil {
|
||||
|
|
|
@ -2,7 +2,7 @@ package note
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
|
@ -27,13 +27,13 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
|
||||
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
|
||||
io, _, stdout, stderr := iostreams.Test()
|
||||
io.IsaTTY = isTTY
|
||||
io.IsInTTY = isTTY
|
||||
io.IsErrTTY = isTTY
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.IsaTTY = isTTY
|
||||
ios.IsInTTY = isTTY
|
||||
ios.IsErrTTY = isTTY
|
||||
|
||||
factory := &cmdutils.Factory{
|
||||
IO: io,
|
||||
IO: ios,
|
||||
HttpClient: func() (*gitlab.Client, error) {
|
||||
a, err := api.TestClient(&http.Client{Transport: rt}, "", "", false)
|
||||
if err != nil {
|
||||
|
@ -62,8 +62,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{
|
||||
|
|
|
@ -4,7 +4,8 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -135,10 +136,10 @@ func NewCmdCreate(f *cmdutils.Factory, runE func(opts *CreateOpts) error) *cobra
|
|||
var b []byte
|
||||
var err error
|
||||
if opts.NotesFile == "-" {
|
||||
b, err = ioutil.ReadAll(opts.IO.In)
|
||||
b, err = io.ReadAll(opts.IO.In)
|
||||
_ = opts.IO.In.Close()
|
||||
} else {
|
||||
b, err = ioutil.ReadFile(opts.NotesFile)
|
||||
b, err = os.ReadFile(opts.NotesFile)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -3,7 +3,6 @@ package add
|
|||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
|
@ -95,7 +94,7 @@ func addRun(opts *AddOpts) error {
|
|||
keyFileReader = f
|
||||
}
|
||||
|
||||
keyInBytes, err := ioutil.ReadAll(keyFileReader)
|
||||
keyInBytes, err := io.ReadAll(keyFileReader)
|
||||
if err != nil {
|
||||
return cmdutils.WrapError(err, "failed to read ssh key file")
|
||||
}
|
||||
|
|
|
@ -3,27 +3,27 @@ package variableutils
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"gitlab.com/gitlab-org/cli/commands/cmdutils"
|
||||
"gitlab.com/gitlab-org/cli/pkg/iostreams"
|
||||
)
|
||||
|
||||
func GetValue(value string, io *iostreams.IOStreams, args []string) (string, error) {
|
||||
func GetValue(value string, ios *iostreams.IOStreams, args []string) (string, error) {
|
||||
if value != "" {
|
||||
return value, nil
|
||||
} else if len(args) == 2 {
|
||||
return args[1], nil
|
||||
}
|
||||
|
||||
if io.IsInTTY {
|
||||
if ios.IsInTTY {
|
||||
return "", &cmdutils.FlagError{Err: errors.New("no value specified but nothing on STDIN")}
|
||||
}
|
||||
|
||||
// read value from STDIN if not provided
|
||||
defer io.In.Close()
|
||||
stdinValue, err := ioutil.ReadAll(io.In)
|
||||
defer ios.In.Close()
|
||||
stdinValue, err := io.ReadAll(ios.In)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to read value from STDIN: %w", err)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package config
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -62,7 +61,7 @@ func ParseDefaultConfig() (Config, error) {
|
|||
}
|
||||
|
||||
var ReadConfigFile = func(filename string) ([]byte, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, pathError(err)
|
||||
}
|
||||
|
@ -75,7 +74,7 @@ var WriteConfigFile = func(filename string, data []byte) error {
|
|||
if err != nil {
|
||||
return pathError(err)
|
||||
}
|
||||
_, err = ioutil.ReadFile(filename)
|
||||
_, err = os.ReadFile(filename)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package config
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -68,7 +67,7 @@ func getAllOldAliases(aliasFile string) map[string]string {
|
|||
return nil
|
||||
}
|
||||
|
||||
contents, err := ioutil.ReadFile(aliasFile)
|
||||
contents, err := os.ReadFile(aliasFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
@ -166,7 +165,7 @@ func migrateUserConfigs(filePath string, cfg Config, isGlobal bool) error {
|
|||
oldConfigFile := filepath.Join(filePath, ".env")
|
||||
if CheckFileExists(oldConfigFile) {
|
||||
log.Println("- Migrating configuration")
|
||||
data, _ := ioutil.ReadFile(oldConfigFile)
|
||||
data, _ := os.ReadFile(oldConfigFile)
|
||||
file := string(data)
|
||||
temp := strings.Split(file, "\n")
|
||||
|
||||
|
@ -239,7 +238,7 @@ func writeConfig(cfg Config, key, value string, isGlobal bool) (nCfg Config, err
|
|||
|
||||
func copy(src string, dst string) error {
|
||||
// Read all content of src to data
|
||||
data, err := ioutil.ReadFile(src)
|
||||
data, err := os.ReadFile(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
@ -10,7 +9,7 @@ import (
|
|||
|
||||
func Test_CheckPathExists(t *testing.T) {
|
||||
t.Run("exists", func(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
dir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
t.Skipf("unexpected error creating temporary directory for testing = %s", err)
|
||||
}
|
||||
|
@ -26,7 +25,7 @@ func Test_CheckPathExists(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_CheckFileExists(t *testing.T) {
|
||||
file, err := ioutil.TempFile("", "")
|
||||
file, err := os.CreateTemp("", "")
|
||||
if err != nil {
|
||||
t.Skipf("Unexpected error creating temporary file for testing = %s", err)
|
||||
}
|
||||
|
@ -46,7 +45,7 @@ func Test_CheckFileExists(t *testing.T) {
|
|||
|
||||
func Test_BackupConfigFile(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
file, err := ioutil.TempFile("", "")
|
||||
file, err := os.CreateTemp("", "")
|
||||
if err != nil {
|
||||
t.Skipf("Unexpected error creating temporary file for testing = %s", err)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package config
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
@ -12,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func Test_WriteFile(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
dir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
t.Skipf("unexpected error while creating temporary directory = %s", err)
|
||||
}
|
||||
|
@ -27,7 +26,7 @@ func Test_WriteFile(t *testing.T) {
|
|||
"unexpected error = %s", err,
|
||||
)
|
||||
|
||||
result, err := ioutil.ReadFile(fpath)
|
||||
result, err := os.ReadFile(fpath)
|
||||
require.Nilf(t, err, "failed to read file %q due to %q", fpath, err)
|
||||
assert.Equal(t, "profclems/glab", string(result))
|
||||
|
||||
|
@ -45,7 +44,7 @@ func Test_WriteFile(t *testing.T) {
|
|||
"unexpected error = %s", err,
|
||||
)
|
||||
|
||||
result, err := ioutil.ReadFile(symPath)
|
||||
result, err := os.ReadFile(symPath)
|
||||
require.Nilf(t, err, "failed to read file %q due to %q", symPath, err)
|
||||
assert.Equal(t, "profclems/glab/symlink", string(result))
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
@ -10,5 +9,5 @@ import (
|
|||
// replace a file on windows which is why renameio doesn't support
|
||||
// windows.
|
||||
func WriteFile(filename string, data []byte, perm os.FileMode) error {
|
||||
return ioutil.WriteFile(filename, data, perm)
|
||||
return os.WriteFile(filename, data, perm)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -84,6 +83,6 @@ func httpResponse(status int, req *http.Request, body io.Reader) *http.Response
|
|||
return &http.Response{
|
||||
StatusCode: status,
|
||||
Request: req,
|
||||
Body: ioutil.NopCloser(body),
|
||||
Body: io.NopCloser(body),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
@ -237,7 +236,7 @@ func Test() (streams *IOStreams, in *bytes.Buffer, out *bytes.Buffer, errOut *by
|
|||
out = &bytes.Buffer{}
|
||||
errOut = &bytes.Buffer{}
|
||||
streams = &IOStreams{
|
||||
In: ioutil.NopCloser(in),
|
||||
In: io.NopCloser(in),
|
||||
StdOut: out,
|
||||
StdErr: errOut,
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package iostreams
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
@ -194,11 +194,11 @@ func Test_HelperFunctions(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("IOTest()", func(t *testing.T) {
|
||||
io, in, out, err := Test()
|
||||
ios, in, out, err := Test()
|
||||
|
||||
assert.Equal(t, io.In, ioutil.NopCloser(in))
|
||||
assert.Equal(t, io.StdOut, out)
|
||||
assert.Equal(t, io.StdErr, err)
|
||||
assert.Equal(t, ios.In, io.NopCloser(in))
|
||||
assert.Equal(t, ios.StdOut, out)
|
||||
assert.Equal(t, ios.StdErr, err)
|
||||
|
||||
assert.Equal(t, in, &bytes.Buffer{})
|
||||
assert.Equal(t, out, &bytes.Buffer{})
|
||||
|
|
|
@ -6,7 +6,6 @@ package surveyext
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
@ -175,7 +174,7 @@ func Edit(editorCommand, fn, initialValue string, stdin io.Reader, stdout io.Wri
|
|||
if pattern == "" {
|
||||
pattern = "survey*.txt"
|
||||
}
|
||||
f, err := ioutil.TempFile("", pattern)
|
||||
f, err := os.CreateTemp("", pattern)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -230,7 +229,7 @@ func Edit(editorCommand, fn, initialValue string, stdin io.Reader, stdout io.Wri
|
|||
}
|
||||
|
||||
// raw is a BOM-unstripped UTF8 byte slice
|
||||
raw, err := ioutil.ReadFile(f.Name())
|
||||
raw, err := os.ReadFile(f.Name())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue