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

Function Test_listRun

pkg/cmd/gpg-key/list/list_test.go:70–198  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

68}
69
70func Test_listRun(t *testing.T) {
71 tests := []struct {
72 name string
73 opts ListOptions
74 isTTY bool
75 wantStdout string
76 wantStderr string
77 wantErr bool
78 }{
79 {
80 name: "list tty",
81 opts: ListOptions{HTTPClient: func() (*http.Client, error) {
82 createdAt := time.Now().Add(time.Duration(-24) * time.Hour)
83 expiresAt, _ := time.Parse(time.RFC3339, "2099-01-01T15:44:24+01:00")
84 noExpires := time.Time{}
85 reg := &httpmock.Registry{}
86 reg.Register(
87 httpmock.REST("GET", "user/gpg_keys"),
88 httpmock.StringResponse(fmt.Sprintf(`[
89 {
90 "id": 1234,
91 "key_id": "ABCDEF1234567890",
92 "public_key": "xJMEWfoofoofoo",
93 "emails": [{"email": "johnny@test.com"}],
94 "created_at": "%[1]s",
95 "expires_at": "%[2]s"
96 },
97 {
98 "id": 5678,
99 "key_id": "1234567890ABCDEF",
100 "public_key": "xJMEWbarbarbar",
101 "emails": [{"email": "monalisa@github.com"}],
102 "created_at": "%[1]s",
103 "expires_at": "%[3]s"
104 }
105 ]`, createdAt.Format(time.RFC3339),
106 expiresAt.Format(time.RFC3339),
107 noExpires.Format(time.RFC3339))),
108 )
109 return &http.Client{Transport: reg}, nil
110 }},
111 isTTY: true,
112 wantStdout: heredoc.Doc(`
113 EMAIL KEY ID PUBLIC KEY ADDED EXPIRES
114 johnny@test.com ABCDEF123456... xJMEWfoofoofoo about 1 day ago 2099-01-01
115 monalisa@github... 1234567890AB... xJMEWbarbarbar about 1 day ago Never
116 `),
117 wantStderr: "",
118 },
119 {
120 name: "list non-tty",
121 opts: ListOptions{HTTPClient: func() (*http.Client, error) {
122 createdAt1, _ := time.Parse(time.RFC3339, "2020-06-11T15:44:24+01:00")
123 expiresAt, _ := time.Parse(time.RFC3339, "2099-01-01T15:44:24+01:00")
124 createdAt2, _ := time.Parse(time.RFC3339, "2021-01-11T15:44:24+01:00")
125 noExpires := time.Time{}
126 reg := &httpmock.Registry{}
127 reg.Register(

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected