MCPcopy
hub / github.com/cli/cli / TestCreateRun

Function TestCreateRun

pkg/cmd/repo/autolink/create/create_test.go:118–190  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

116}
117
118func TestCreateRun(t *testing.T) {
119 tests := []struct {
120 name string
121 opts *createOptions
122 stubCreator stubAutolinkCreator
123 expectedErr error
124 errMsg string
125 wantStdout string
126 wantStderr string
127 }{
128 {
129 name: "success, alphanumeric",
130 opts: &createOptions{
131 KeyPrefix: "TICKET-",
132 URLTemplate: "https://example.com/TICKET?query=<num>",
133 },
134 stubCreator: stubAutolinkCreator{},
135 wantStdout: "✓ Created repository autolink 1 on OWNER/REPO\n",
136 },
137 {
138 name: "success, numeric",
139 opts: &createOptions{
140 KeyPrefix: "TICKET-",
141 URLTemplate: "https://example.com/TICKET?query=<num>",
142 Numeric: true,
143 },
144 stubCreator: stubAutolinkCreator{},
145 wantStdout: "✓ Created repository autolink 1 on OWNER/REPO\n",
146 },
147 {
148 name: "client error",
149 opts: &createOptions{
150 KeyPrefix: "TICKET-",
151 URLTemplate: "https://example.com/TICKET?query=<num>",
152 },
153 stubCreator: stubAutolinkCreator{err: testAutolinkClientCreateError{}},
154 expectedErr: testAutolinkClientCreateError{},
155 errMsg: fmt.Sprint("error creating autolink: ", testAutolinkClientCreateError{}.Error()),
156 },
157 }
158
159 for _, tt := range tests {
160 t.Run(tt.name, func(t *testing.T) {
161 ios, _, stdout, stderr := iostreams.Test()
162
163 opts := tt.opts
164 opts.IO = ios
165 opts.Browser = &browser.Stub{}
166
167 opts.IO = ios
168 opts.BaseRepo = func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil }
169
170 opts.AutolinkClient = &tt.stubCreator
171 err := createRun(opts)
172
173 if tt.expectedErr != nil {
174 require.Error(t, err)
175 assert.ErrorIs(t, err, tt.expectedErr)

Callers

nothing calls this directly

Calls 7

TestFunction · 0.92
NewFunction · 0.92
EqualMethod · 0.80
createRunFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected