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

Function TestGitService_CreateTree_Delete

github/git_trees_test.go:249–327  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

247}
248
249func TestGitService_CreateTree_Delete(t *testing.T) {
250 t.Parallel()
251 client, mux, _ := setup(t)
252
253 input := []*TreeEntry{
254 {
255 Path: Ptr("content.md"),
256 Mode: Ptr("100644"),
257 },
258 }
259
260 mux.HandleFunc("/repos/o/r/git/trees", func(w http.ResponseWriter, r *http.Request) {
261 got, err := io.ReadAll(r.Body)
262 if err != nil {
263 t.Fatalf("unable to read body: %v", err)
264 }
265
266 testMethod(t, r, "POST")
267
268 want := []byte(`{"base_tree":"b","tree":[{"sha":null,"path":"content.md","mode":"100644"}]}` + "\n")
269 if !bytes.Equal(got, want) {
270 t.Errorf("Git.CreateTree request body: %v, want %v", got, want)
271 }
272
273 fmt.Fprint(w, `{
274 "sha": "5c6780ad2c68743383b740fd1dab6f6a33202b11",
275 "url": "https://api.github.com/repos/o/r/git/trees/5c6780ad2c68743383b740fd1dab6f6a33202b11",
276 "tree": [
277 {
278 "mode": "100644",
279 "type": "blob",
280 "sha": null,
281 "path": "content.md",
282 "size": 12,
283 "url": "https://api.github.com/repos/o/r/git/blobs/aad8feacf6f8063150476a7b2bd9770f2794c08b"
284 }
285 ]
286 }`)
287 })
288
289 ctx := t.Context()
290 tree, _, err := client.Git.CreateTree(ctx, "o", "r", "b", input)
291 if err != nil {
292 t.Errorf("Git.CreateTree returned error: %v", err)
293 }
294
295 want := Tree{
296 Ptr("5c6780ad2c68743383b740fd1dab6f6a33202b11"),
297 []*TreeEntry{
298 {
299 Path: Ptr("content.md"),
300 Mode: Ptr("100644"),
301 Type: Ptr("blob"),
302 Size: Ptr(12),
303 SHA: nil,
304 URL: Ptr("https://api.github.com/repos/o/r/git/blobs/aad8feacf6f8063150476a7b2bd9770f2794c08b"),
305 },
306 },

Callers

nothing calls this directly

Calls 7

testMethodFunction · 0.85
testBadOptionsFunction · 0.85
EqualMethod · 0.80
CreateTreeMethod · 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…