(t *testing.T)
| 166 | } |
| 167 | |
| 168 | func TestGitService_CreateTree_Content(t *testing.T) { |
| 169 | t.Parallel() |
| 170 | client, mux, _ := setup(t) |
| 171 | |
| 172 | input := []*TreeEntry{ |
| 173 | { |
| 174 | Path: Ptr("content.md"), |
| 175 | Mode: Ptr("100644"), |
| 176 | Content: Ptr("file content"), |
| 177 | }, |
| 178 | } |
| 179 | |
| 180 | mux.HandleFunc("/repos/o/r/git/trees", func(w http.ResponseWriter, r *http.Request) { |
| 181 | got, err := io.ReadAll(r.Body) |
| 182 | if err != nil { |
| 183 | t.Fatalf("unable to read body: %v", err) |
| 184 | } |
| 185 | |
| 186 | testMethod(t, r, "POST") |
| 187 | |
| 188 | want := []byte(`{"base_tree":"b","tree":[{"path":"content.md","mode":"100644","content":"file content"}]}` + "\n") |
| 189 | if !bytes.Equal(got, want) { |
| 190 | t.Errorf("Git.CreateTree request body: %v, want %v", got, want) |
| 191 | } |
| 192 | |
| 193 | fmt.Fprint(w, `{ |
| 194 | "sha": "5c6780ad2c68743383b740fd1dab6f6a33202b11", |
| 195 | "url": "https://api.github.com/repos/o/r/git/trees/5c6780ad2c68743383b740fd1dab6f6a33202b11", |
| 196 | "tree": [ |
| 197 | { |
| 198 | "mode": "100644", |
| 199 | "type": "blob", |
| 200 | "sha": "aad8feacf6f8063150476a7b2bd9770f2794c08b", |
| 201 | "path": "content.md", |
| 202 | "size": 12, |
| 203 | "url": "https://api.github.com/repos/o/r/git/blobs/aad8feacf6f8063150476a7b2bd9770f2794c08b" |
| 204 | } |
| 205 | ] |
| 206 | }`) |
| 207 | }) |
| 208 | |
| 209 | ctx := t.Context() |
| 210 | tree, _, err := client.Git.CreateTree(ctx, "o", "r", "b", input) |
| 211 | if err != nil { |
| 212 | t.Errorf("Git.CreateTree returned error: %v", err) |
| 213 | } |
| 214 | |
| 215 | want := Tree{ |
| 216 | Ptr("5c6780ad2c68743383b740fd1dab6f6a33202b11"), |
| 217 | []*TreeEntry{ |
| 218 | { |
| 219 | Path: Ptr("content.md"), |
| 220 | Mode: Ptr("100644"), |
| 221 | Type: Ptr("blob"), |
| 222 | Size: Ptr(12), |
| 223 | SHA: Ptr("aad8feacf6f8063150476a7b2bd9770f2794c08b"), |
| 224 | URL: Ptr("https://api.github.com/repos/o/r/git/blobs/aad8feacf6f8063150476a7b2bd9770f2794c08b"), |
| 225 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…