MCPcopy
hub / github.com/cli/cli / TestListRun

Function TestListRun

pkg/cmd/repo/deploy-key/list/list_test.go:15–133  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestListRun(t *testing.T) {
16 tests := []struct {
17 name string
18 opts ListOptions
19 isTTY bool
20 httpStubs func(t *testing.T, reg *httpmock.Registry)
21 wantStdout string
22 wantStderr string
23 wantErr bool
24 }{
25 {
26 name: "list tty",
27 isTTY: true,
28 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
29 createdAt := time.Now().Add(time.Duration(-24) * time.Hour)
30 reg.Register(
31 httpmock.REST("GET", "repos/OWNER/REPO/keys"),
32 httpmock.StringResponse(fmt.Sprintf(`[
33 {
34 "id": 1234,
35 "key": "ssh-rsa AAAABbBB123",
36 "title": "Mac",
37 "created_at": "%[1]s",
38 "read_only": true
39 },
40 {
41 "id": 5678,
42 "key": "ssh-rsa EEEEEEEK247",
43 "title": "hubot@Windows",
44 "created_at": "%[1]s",
45 "read_only": false
46 }
47 ]`, createdAt.Format(time.RFC3339))),
48 )
49 },
50 wantStdout: heredoc.Doc(`
51 ID TITLE TYPE KEY CREATED AT
52 1234 Mac read-only ssh-rsa AAAABbBB123 about 1 day ago
53 5678 hubot@Windows read-write ssh-rsa EEEEEEEK247 about 1 day ago
54 `),
55 wantStderr: "",
56 },
57 {
58 name: "list non-tty",
59 isTTY: false,
60 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
61 createdAt, _ := time.Parse(time.RFC3339, "2020-08-31T15:44:24+02:00")
62 reg.Register(
63 httpmock.REST("GET", "repos/OWNER/REPO/keys"),
64 httpmock.StringResponse(fmt.Sprintf(`[
65 {
66 "id": 1234,
67 "key": "ssh-rsa AAAABbBB123",
68 "title": "Mac",
69 "created_at": "%[1]s",
70 "read_only": false
71 },
72 {

Callers

nothing calls this directly

Calls 14

RegisterMethod · 0.95
RESTFunction · 0.92
StringResponseFunction · 0.92
TestFunction · 0.92
NewFunction · 0.92
DurationMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80
SetStderrTTYMethod · 0.80
listRunFunction · 0.70
AddMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected