(t *testing.T)
| 93 | } |
| 94 | |
| 95 | func 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 | }, |
nothing calls this directly
no test coverage detected