MCPcopy Create free account
hub / github.com/google/go-github / TestRepositoriesService_AddAutolink

Function TestRepositoriesService_AddAutolink

github/repos_autolinks_test.go:55–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

53}
54
55func TestRepositoriesService_AddAutolink(t *testing.T) {
56 t.Parallel()
57 client, mux, _ := setup(t)
58
59 opt := &AutolinkOptions{
60 KeyPrefix: Ptr("TICKET-"),
61 URLTemplate: Ptr("https://example.com/TICKET?query=<num>"),
62 IsAlphanumeric: Ptr(true),
63 }
64 mux.HandleFunc("/repos/o/r/autolinks", func(w http.ResponseWriter, r *http.Request) {
65 testMethod(t, r, "POST")
66 testJSONBody(t, r, opt)
67 w.WriteHeader(http.StatusOK)
68 assertWrite(t, w, []byte(`
69 {
70 "key_prefix": "TICKET-",
71 "url_template": "https://example.com/TICKET?query=<num>",
72 "is_alphanumeric": true
73 }
74 `))
75 })
76 ctx := t.Context()
77 autolink, _, err := client.Repositories.AddAutolink(ctx, "o", "r", opt)
78 if err != nil {
79 t.Errorf("Repositories.AddAutolink returned error: %v", err)
80 }
81 want := &Autolink{
82 KeyPrefix: Ptr("TICKET-"),
83 URLTemplate: Ptr("https://example.com/TICKET?query=<num>"),
84 IsAlphanumeric: Ptr(true),
85 }
86
87 if !cmp.Equal(autolink, want) {
88 t.Errorf("AddAutolink returned %+v, want %+v", autolink, want)
89 }
90
91 const methodName = "AddAutolink"
92 testBadOptions(t, methodName, func() (err error) {
93 _, _, err = client.Repositories.AddAutolink(ctx, "\n", "\n", opt)
94 return err
95 })
96
97 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
98 got, resp, err := client.Repositories.AddAutolink(ctx, "o", "r", opt)
99 if got != nil {
100 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
101 }
102 return resp, err
103 })
104}
105
106func TestRepositoriesService_GetAutolink(t *testing.T) {
107 t.Parallel()

Callers

nothing calls this directly

Calls 9

testMethodFunction · 0.85
testJSONBodyFunction · 0.85
assertWriteFunction · 0.85
testBadOptionsFunction · 0.85
AddAutolinkMethod · 0.80
EqualMethod · 0.80
setupFunction · 0.70
PtrFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…