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

Function TestListRun

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

Source from the content-addressed store, hash-verified

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

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