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

Function TestViewRun

pkg/cmd/event/subscription/view/view_test.go:95–196  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func TestViewRun(t *testing.T) {
96 now := time.Date(2026, 1, 2, 3, 0, 0, 0, time.UTC)
97 sub := &client.Subscription{
98 ID: "sub_1",
99 ResourceURL: "https://github.com/OWNER/REPO/pull/1",
100 EventTypes: []string{"com.github.pull_request.review.submitted.v1", "test.b"},
101 CreatedAt: now.Add(-2 * time.Hour),
102 ExpiresAt: now.Add(22 * time.Hour),
103 }
104
105 tests := []struct {
106 name string
107 tty bool
108 jsonFields []string
109 getErr error
110 wantOut string
111 wantErr string
112 }{
113 {
114 name: "tty",
115 tty: true,
116 wantOut: heredoc.Doc(`
117 sub_1
118 Created about 2 hours ago • Expires in about 22 hours
119
120 Resource
121 https://github.com/OWNER/REPO/pull/1
122
123 Events
124 • com.github.pull_request.review.submitted.v1 a review was submitted
125 • test.b
126 `),
127 },
128 {
129 name: "not tty",
130 wantOut: heredoc.Doc(`
131 id: sub_1
132 resource: https://github.com/OWNER/REPO/pull/1
133 events: com.github.pull_request.review.submitted.v1,test.b
134 created: 2026-01-02T01:00:00Z
135 expires: 2026-01-03T01:00:00Z
136 `),
137 },
138 {
139 name: "json",
140 jsonFields: []string{"id", "expiresAt"},
141 wantOut: `{"expiresAt":"2026-01-03T01:00:00Z","id":"sub_1"}` + "\n",
142 },
143 {
144 name: "missing subscription",
145 getErr: client.ErrSubscriptionNotFound,
146 wantErr: "subscription sub_1 was not found; it may have expired or been deleted, or you cannot access it",
147 },
148 {
149 name: "other error",
150 getErr: client.ErrPreviewNotEnabled,
151 wantErr: "failed to get subscription: event subscriptions are in preview",
152 },

Callers

nothing calls this directly

Calls 11

TestFunction · 0.92
NewMockConfigFunction · 0.92
NewJSONExporterFunction · 0.92
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
SetFieldsMethod · 0.80
EmptyMethod · 0.80
viewRunFunction · 0.70
AddMethod · 0.65
RunMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected