MCPcopy
hub / github.com/cli/cli / TestAutolinkCreator_Create

Function TestAutolinkCreator_Create

pkg/cmd/repo/autolink/create/http_test.go:16–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestAutolinkCreator_Create(t *testing.T) {
17 repo := ghrepo.New("OWNER", "REPO")
18
19 tests := []struct {
20 name string
21 req AutolinkCreateRequest
22 stubStatus int
23 stubRespJSON string
24
25 expectedAutolink *shared.Autolink
26 expectErr bool
27 expectedErrMsg string
28 }{
29 {
30 name: "201 successful creation",
31 req: AutolinkCreateRequest{
32 IsAlphanumeric: true,
33 KeyPrefix: "TICKET-",
34 URLTemplate: "https://example.com/TICKET?query=<num>",
35 },
36 stubStatus: http.StatusCreated,
37 stubRespJSON: `{
38 "id": 1,
39 "is_alphanumeric": true,
40 "key_prefix": "TICKET-",
41 "url_template": "https://example.com/TICKET?query=<num>"
42 }`,
43 expectedAutolink: &shared.Autolink{
44 ID: 1,
45 KeyPrefix: "TICKET-",
46 URLTemplate: "https://example.com/TICKET?query=<num>",
47 IsAlphanumeric: true,
48 },
49 },
50 {
51 name: "422 URL template not valid URL",
52 req: AutolinkCreateRequest{
53 IsAlphanumeric: true,
54 KeyPrefix: "TICKET-",
55 URLTemplate: "foo/<num>",
56 },
57 stubStatus: http.StatusUnprocessableEntity,
58 stubRespJSON: `{
59 "message": "Validation Failed",
60 "errors": [
61 {
62 "resource": "KeyLink",
63 "code": "custom",
64 "field": "url_template",
65 "message": "url_template must be an absolute URL"
66 }
67 ],
68 "documentation_url": "https://docs.github.com/rest/repos/autolinks#create-an-autolink-reference-for-a-repository",
69 "status": "422"
70 }`,
71 expectErr: true,
72 expectedErrMsg: heredoc.Doc(`
73 HTTP 422: Validation Failed (https://api.github.com/repos/OWNER/REPO/autolinks)

Callers

nothing calls this directly

Calls 10

RegisterMethod · 0.95
VerifyMethod · 0.95
CreateMethod · 0.95
NewFunction · 0.92
RESTFunction · 0.92
RESTPayloadFunction · 0.92
EqualMethod · 0.80
RunMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65

Tested by

no test coverage detected