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

Function TestAutolinkCreator_Create

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

Source from the content-addressed store, hash-verified

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

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