MCPcopy Create free account
hub / github.com/cli/cli / Test_runAdd

Function Test_runAdd

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

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected