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

Function TestGitService_CreateTree

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

Source from the content-addressed store, hash-verified

87}
88
89func TestGitService_CreateTree(t *testing.T) {
90 t.Parallel()
91 client, mux, _ := setup(t)
92
93 input := []*TreeEntry{
94 {
95 Path: Ptr("file.rb"),
96 Mode: Ptr("100644"),
97 Type: Ptr("blob"),
98 SHA: Ptr("7c258a9869f33c1e1e1f74fbb32f07c86cb5a75b"),
99 },
100 }
101
102 mux.HandleFunc("/repos/o/r/git/trees", func(w http.ResponseWriter, r *http.Request) {
103 got, err := io.ReadAll(r.Body)
104 if err != nil {
105 t.Fatalf("unable to read body: %v", err)
106 }
107
108 testMethod(t, r, "POST")
109
110 want := []byte(`{"base_tree":"b","tree":[{"sha":"7c258a9869f33c1e1e1f74fbb32f07c86cb5a75b","path":"file.rb","mode":"100644","type":"blob"}]}` + "\n")
111 if !bytes.Equal(got, want) {
112 t.Errorf("Git.CreateTree request body: %v, want %v", got, want)
113 }
114
115 fmt.Fprint(w, `{
116 "sha": "cd8274d15fa3ae2ab983129fb037999f264ba9a7",
117 "tree": [
118 {
119 "path": "file.rb",
120 "mode": "100644",
121 "type": "blob",
122 "size": 132,
123 "sha": "7c258a9869f33c1e1e1f74fbb32f07c86cb5a75b"
124 }
125 ]
126 }`)
127 })
128
129 ctx := t.Context()
130 tree, _, err := client.Git.CreateTree(ctx, "o", "r", "b", input)
131 if err != nil {
132 t.Errorf("Git.CreateTree returned error: %v", err)
133 }
134
135 want := Tree{
136 Ptr("cd8274d15fa3ae2ab983129fb037999f264ba9a7"),
137 []*TreeEntry{
138 {
139 Path: Ptr("file.rb"),
140 Mode: Ptr("100644"),
141 Type: Ptr("blob"),
142 Size: Ptr(132),
143 SHA: Ptr("7c258a9869f33c1e1e1f74fbb32f07c86cb5a75b"),
144 },
145 },
146 nil,

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…