github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/pkg/cmd/repo/deploy-key/delete/delete_test.go (about)

     1  package delete
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  
     7  	"github.com/ungtb10d/cli/v2/internal/ghrepo"
     8  	"github.com/ungtb10d/cli/v2/pkg/httpmock"
     9  	"github.com/ungtb10d/cli/v2/pkg/iostreams"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func Test_deleteRun(t *testing.T) {
    14  	ios, _, stdout, stderr := iostreams.Test()
    15  	ios.SetStdinTTY(false)
    16  	ios.SetStdoutTTY(true)
    17  	ios.SetStderrTTY(true)
    18  
    19  	tr := httpmock.Registry{}
    20  	defer tr.Verify(t)
    21  
    22  	tr.Register(
    23  		httpmock.REST("DELETE", "repos/OWNER/REPO/keys/1234"),
    24  		httpmock.StringResponse(`{}`))
    25  
    26  	err := deleteRun(&DeleteOptions{
    27  		IO: ios,
    28  		HTTPClient: func() (*http.Client, error) {
    29  			return &http.Client{Transport: &tr}, nil
    30  		},
    31  		BaseRepo: func() (ghrepo.Interface, error) {
    32  			return ghrepo.New("OWNER", "REPO"), nil
    33  		},
    34  		KeyID: "1234",
    35  	})
    36  	assert.NoError(t, err)
    37  
    38  	assert.Equal(t, "", stderr.String())
    39  	assert.Equal(t, "✓ Deploy key deleted from OWNER/REPO\n", stdout.String())
    40  }