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

Function TestCreateSubscription

pkg/cmd/event/client/client_test.go:51–75  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestCreateSubscription(t *testing.T) {
52 for _, status := range []int{http.StatusCreated, http.StatusOK} {
53 t.Run(http.StatusText(status), func(t *testing.T) {
54 client, reg := newTestClient(t, "github.com")
55 var gotBody map[string]any
56 reg.Register(httpmock.REST("POST", "event-subscriptions"), func(req *http.Request) (*http.Response, error) {
57 body, err := io.ReadAll(req.Body)
58 require.NoError(t, err)
59 require.NoError(t, json.Unmarshal(body, &gotBody))
60 return httpmock.StatusStringResponse(status, subscriptionJSON)(req)
61 })
62
63 sub, created, err := client.CreateSubscription(context.Background(), "https://github.com/OWNER/REPO/pull/1",
64 []string{"test.a", "test.b"})
65
66 require.NoError(t, err)
67 assert.Equal(t, wantSubscription, sub)
68 assert.Equal(t, status == http.StatusCreated, created)
69 assert.Equal(t, map[string]any{
70 "resource_url": "https://github.com/OWNER/REPO/pull/1",
71 "event_types": []any{"test.a", "test.b"},
72 }, gotBody)
73 })
74 }
75}
76
77func TestGetSubscription(t *testing.T) {
78 client, reg := newTestClient(t, "github.com")

Callers

nothing calls this directly

Calls 7

RESTFunction · 0.92
StatusStringResponseFunction · 0.92
EqualMethod · 0.80
newTestClientFunction · 0.70
RunMethod · 0.65
CreateSubscriptionMethod · 0.65
RegisterMethod · 0.45

Tested by

no test coverage detected