cli/pkg/cmd/repo/deploy-key/delete/delete_test.go
Nilesh Singh 47a6aff54a
Add repo deploy key commands (#4302)
Co-authored-by: Mislav Marohnić <mislav@github.com>
2022-01-25 17:48:24 +00:00

40 lines
907 B
Go

package delete
import (
"net/http"
"testing"
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/pkg/httpmock"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/stretchr/testify/assert"
)
func Test_deleteRun(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdinTTY(false)
io.SetStdoutTTY(true)
io.SetStderrTTY(true)
tr := httpmock.Registry{}
defer tr.Verify(t)
tr.Register(
httpmock.REST("DELETE", "repos/OWNER/REPO/keys/1234"),
httpmock.StringResponse(`{}`))
err := deleteRun(&DeleteOptions{
IO: io,
HTTPClient: func() (*http.Client, error) {
return &http.Client{Transport: &tr}, nil
},
BaseRepo: func() (ghrepo.Interface, error) {
return ghrepo.New("OWNER", "REPO"), nil
},
KeyID: "1234",
})
assert.NoError(t, err)
assert.Equal(t, "", stderr.String())
assert.Equal(t, "✓ Deploy key deleted from OWNER/REPO\n", stdout.String())
}