| 112 | } |
| 113 | |
| 114 | func TestViewRun(t *testing.T) { |
| 115 | tests := []struct { |
| 116 | name string |
| 117 | opts *viewOptions |
| 118 | stubViewer stubAutolinkViewer |
| 119 | expectedErr error |
| 120 | wantStdout string |
| 121 | }{ |
| 122 | { |
| 123 | name: "view", |
| 124 | opts: &viewOptions{ |
| 125 | ID: "1", |
| 126 | }, |
| 127 | stubViewer: stubAutolinkViewer{ |
| 128 | autolink: &shared.Autolink{ |
| 129 | ID: 1, |
| 130 | KeyPrefix: "TICKET-", |
| 131 | URLTemplate: "https://example.com/TICKET?query=<num>", |
| 132 | IsAlphanumeric: true, |
| 133 | }, |
| 134 | }, |
| 135 | wantStdout: heredoc.Doc(` |
| 136 | Autolink in OWNER/REPO |
| 137 | |
| 138 | ID: 1 |
| 139 | Key Prefix: TICKET- |
| 140 | URL Template: https://example.com/TICKET?query=<num> |
| 141 | Alphanumeric: true |
| 142 | `), |
| 143 | }, |
| 144 | { |
| 145 | name: "view json", |
| 146 | opts: &viewOptions{ |
| 147 | Exporter: func() cmdutil.Exporter { |
| 148 | exporter := cmdutil.NewJSONExporter() |
| 149 | exporter.SetFields([]string{"id"}) |
| 150 | return exporter |
| 151 | }(), |
| 152 | }, |
| 153 | stubViewer: stubAutolinkViewer{ |
| 154 | autolink: &shared.Autolink{ |
| 155 | ID: 1, |
| 156 | KeyPrefix: "TICKET-", |
| 157 | URLTemplate: "https://example.com/TICKET?query=<num>", |
| 158 | IsAlphanumeric: true, |
| 159 | }, |
| 160 | }, |
| 161 | wantStdout: "{\"id\":1}\n", |
| 162 | }, |
| 163 | { |
| 164 | name: "client error", |
| 165 | opts: &viewOptions{}, |
| 166 | stubViewer: stubAutolinkViewer{ |
| 167 | autolink: nil, |
| 168 | err: testAutolinkClientViewError{}, |
| 169 | }, |
| 170 | expectedErr: testAutolinkClientViewError{}, |
| 171 | }, |