github.com/secman-team/gh-api@v1.8.2/pkg/cmd/ssh-key/add/add_test.go (about)

     1  package add
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  
     7  	"github.com/secman-team/gh-api/core/config"
     8  	"github.com/secman-team/gh-api/pkg/httpmock"
     9  	"github.com/secman-team/gh-api/pkg/iostreams"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func Test_runAdd(t *testing.T) {
    14  	io, stdin, stdout, stderr := iostreams.Test()
    15  	io.SetStdinTTY(false)
    16  	io.SetStdoutTTY(true)
    17  	io.SetStderrTTY(true)
    18  
    19  	stdin.WriteString("PUBKEY")
    20  
    21  	tr := httpmock.Registry{}
    22  	defer tr.Verify(t)
    23  
    24  	tr.Register(
    25  		httpmock.REST("POST", "user/keys"),
    26  		httpmock.StringResponse(`{}`))
    27  
    28  	err := runAdd(&AddOptions{
    29  		IO: io,
    30  		Config: func() (config.Config, error) {
    31  			return config.NewBlankConfig(), nil
    32  		},
    33  		HTTPClient: func() (*http.Client, error) {
    34  			return &http.Client{Transport: &tr}, nil
    35  		},
    36  		KeyFile: "-",
    37  		Title:   "my sacred key",
    38  	})
    39  	assert.NoError(t, err)
    40  
    41  	assert.Equal(t, "", stdout.String())
    42  	assert.Equal(t, "✓ Public key added to your account\n", stderr.String())
    43  }