MCPcopy Index your code
hub / github.com/google/go-github / TestRepositoriesService_CreateKey

Function TestRepositoriesService_CreateKey

github/repos_keys_test.go:106–142  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

104}
105
106func TestRepositoriesService_CreateKey(t *testing.T) {
107 t.Parallel()
108 client, mux, _ := setup(t)
109
110 input := &Key{Key: Ptr("k"), Title: Ptr("t")}
111
112 mux.HandleFunc("/repos/o/r/keys", func(w http.ResponseWriter, r *http.Request) {
113 testMethod(t, r, "POST")
114 testJSONBody(t, r, input)
115 fmt.Fprint(w, `{"id":1}`)
116 })
117
118 ctx := t.Context()
119 key, _, err := client.Repositories.CreateKey(ctx, "o", "r", input)
120 if err != nil {
121 t.Errorf("Repositories.GetKey returned error: %v", err)
122 }
123
124 want := &Key{ID: Ptr(int64(1))}
125 if !cmp.Equal(key, want) {
126 t.Errorf("Repositories.GetKey returned %+v, want %+v", key, want)
127 }
128
129 const methodName = "CreateKey"
130 testBadOptions(t, methodName, func() (err error) {
131 _, _, err = client.Repositories.CreateKey(ctx, "\n", "\n", input)
132 return err
133 })
134
135 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
136 got, resp, err := client.Repositories.CreateKey(ctx, "o", "r", input)
137 if got != nil {
138 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
139 }
140 return resp, err
141 })
142}
143
144func TestRepositoriesService_CreateKey_invalidOwner(t *testing.T) {
145 t.Parallel()

Callers

nothing calls this directly

Calls 8

testMethodFunction · 0.85
testJSONBodyFunction · 0.85
testBadOptionsFunction · 0.85
EqualMethod · 0.80
setupFunction · 0.70
PtrFunction · 0.70
CreateKeyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…