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

Function TestListRun

pkg/cmd/event/subscription/list/list_test.go:100–218  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

98}
99
100func TestListRun(t *testing.T) {
101 now := time.Date(2026, 1, 2, 3, 0, 0, 0, time.UTC)
102 subs := []client.Subscription{
103 {
104 ID: "sub_2",
105 ResourceURL: "https://github.com/OWNER/REPO/pull/2",
106 EventTypes: []string{"test.a", "test.b"},
107 ExpiresAt: now.Add(23 * time.Hour),
108 },
109 {
110 ID: "sub_1",
111 ResourceURL: "https://github.com/OWNER/REPO/pull/1",
112 EventTypes: []string{"test.a"},
113 ExpiresAt: now.Add(30 * time.Minute),
114 },
115 }
116
117 tests := []struct {
118 name string
119 tty bool
120 jsonFields []string
121 subs []client.Subscription
122 listErr error
123 wantOut string
124 wantErr string
125 wantNoRes bool
126 }{
127 {
128 name: "tty",
129 tty: true,
130 subs: subs,
131 wantOut: "\n" + heredoc.Doc(`
132 Showing 2 event subscriptions
133
134 ID RESOURCE EVENTS EXPIRES
135 sub_2 https://github.com/OWNER/REPO/pull/2 test.a, test.b in about 23 hours
136 sub_1 https://github.com/OWNER/REPO/pull/1 test.a in about 30 minutes
137 `),
138 },
139 {
140 name: "not tty",
141 subs: subs,
142 wantOut: heredoc.Doc(`
143 sub_2 https://github.com/OWNER/REPO/pull/2 test.a,test.b 2026-01-03T02:00:00Z
144 sub_1 https://github.com/OWNER/REPO/pull/1 test.a 2026-01-02T03:30:00Z
145 `),
146 },
147 {
148 name: "no subscriptions",
149 tty: true,
150 subs: []client.Subscription{},
151 wantNoRes: true,
152 },
153 {
154 name: "json",
155 jsonFields: []string{"id", "eventTypes"},
156 subs: subs,
157 wantOut: `[{"eventTypes":["test.a","test.b"],"id":"sub_2"},{"eventTypes":["test.a"],"id":"sub_1"}]` + "\n",

Callers

nothing calls this directly

Calls 12

ErrorMethod · 0.95
TestFunction · 0.92
NewMockConfigFunction · 0.92
NewJSONExporterFunction · 0.92
SetStdoutTTYMethod · 0.80
SetFieldsMethod · 0.80
EqualMethod · 0.80
EmptyMethod · 0.80
listRunFunction · 0.70
AddMethod · 0.65
RunMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected