(t *testing.T)
| 53 | } |
| 54 | |
| 55 | func 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 | |
| 106 | func TestRepositoriesService_GetAutolink(t *testing.T) { |
| 107 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…