use strings.Replace for all command tests

Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
Meredith Lancaster 2024-03-19 16:51:26 -06:00
parent 79d3c9594d
commit 98d7bef299
3 changed files with 9 additions and 12 deletions

View file

@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"net/http"
"strings"
"testing"
"github.com/cli/cli/v2/pkg/cmd/attestation/api"
@ -15,7 +16,6 @@ import (
"github.com/cli/cli/v2/pkg/httpmock"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/google/shlex"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -153,13 +153,12 @@ func TestNewDownloadCmd(t *testing.T) {
return nil
})
argv, err := shlex.Split(tc.cli)
assert.NoError(t, err)
argv := strings.Split(tc.cli, " ")
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(&bytes.Buffer{})
cmd.SetErr(&bytes.Buffer{})
_, err = cmd.ExecuteC()
_, err := cmd.ExecuteC()
if tc.wantsErr {
assert.Error(t, err)
return

View file

@ -2,13 +2,13 @@ package tufrootverify
import (
"bytes"
"strings"
"testing"
"github.com/cli/cli/v2/pkg/cmd/attestation/test"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/google/shlex"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -47,13 +47,12 @@ func TestNewTUFRootVerifyCmd(t *testing.T) {
return nil
})
argv, err := shlex.Split(tc.cli)
assert.NoError(t, err)
argv := strings.Split(tc.cli, " ")
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(&bytes.Buffer{})
cmd.SetErr(&bytes.Buffer{})
_, err = cmd.ExecuteC()
_, err := cmd.ExecuteC()
if tc.wantsErr {
assert.Error(t, err)
return

View file

@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"net/http"
"strings"
"testing"
"github.com/cli/cli/v2/pkg/cmd/attestation/api"
@ -15,7 +16,6 @@ import (
"github.com/cli/cli/v2/pkg/httpmock"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/google/shlex"
"github.com/stretchr/testify/assert"
"github.com/in-toto/in-toto-golang/in_toto"
@ -197,13 +197,12 @@ func TestNewVerifyCmd(t *testing.T) {
return nil
})
argv, err := shlex.Split(tc.cli)
assert.NoError(t, err)
argv := strings.Split(tc.cli, " ")
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(&bytes.Buffer{})
cmd.SetErr(&bytes.Buffer{})
_, err = cmd.ExecuteC()
_, err := cmd.ExecuteC()
if tc.wantsErr {
assert.Error(t, err)
return