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

Function TestViewRun

pkg/cmd/repo/autolink/view/view_test.go:114–197  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func 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 },

Callers

nothing calls this directly

Calls 9

NewJSONExporterFunction · 0.92
TestFunction · 0.92
NewFunction · 0.92
SetFieldsMethod · 0.80
EqualMethod · 0.80
viewRunFunction · 0.70
RunMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected