MCPcopy
hub / github.com/cli/cli / Test_runAdd

Function Test_runAdd

pkg/cmd/ssh-key/add/add_test.go:14–151  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func Test_runAdd(t *testing.T) {
15 tests := []struct {
16 name string
17 stdin string
18 opts AddOptions
19 httpStubs func(*httpmock.Registry)
20 wantStdout string
21 wantStderr string
22 wantErrMsg string
23 }{
24 {
25 name: "valid key format, not already in use",
26 stdin: "ssh-ed25519 asdf",
27 httpStubs: func(reg *httpmock.Registry) {
28 reg.Register(
29 httpmock.REST("GET", "user/keys"),
30 httpmock.StringResponse("[]"))
31 reg.Register(
32 httpmock.REST("POST", "user/keys"),
33 httpmock.RESTPayload(200, ``, func(payload map[string]interface{}) {
34 assert.Contains(t, payload, "key")
35 assert.Empty(t, payload["title"])
36 }))
37 },
38 wantStdout: "",
39 wantStderr: "✓ Public key added to your account\n",
40 wantErrMsg: "",
41 opts: AddOptions{KeyFile: "-"},
42 },
43 {
44 name: "valid signing key format, not already in use",
45 stdin: "ssh-ed25519 asdf",
46 httpStubs: func(reg *httpmock.Registry) {
47 reg.Register(
48 httpmock.REST("GET", "user/ssh_signing_keys"),
49 httpmock.StringResponse("[]"))
50 reg.Register(
51 httpmock.REST("POST", "user/ssh_signing_keys"),
52 httpmock.RESTPayload(200, ``, func(payload map[string]interface{}) {
53 assert.Contains(t, payload, "key")
54 assert.Empty(t, payload["title"])
55 }))
56 },
57 wantStdout: "",
58 wantStderr: "✓ Public key added to your account\n",
59 wantErrMsg: "",
60 opts: AddOptions{KeyFile: "-", Type: "signing"},
61 },
62 {
63 name: "valid key format, already in use",
64 stdin: "ssh-ed25519 asdf title",
65 httpStubs: func(reg *httpmock.Registry) {
66 reg.Register(
67 httpmock.REST("GET", "user/keys"),
68 httpmock.StringResponse(`[
69 {
70 "id": 1,
71 "key": "ssh-ed25519 asdf",

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
StringResponseFunction · 0.92
RESTPayloadFunction · 0.92
TestFunction · 0.92
NewBlankConfigFunction · 0.92
ContainsMethod · 0.80
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected