MCPcopy Create free account
hub / github.com/openclaw/gogcli / TestGmailDraftsCreateCmd_JSON

Function TestGmailDraftsCreateCmd_JSON

internal/cmd/gmail_drafts_cmd_test.go:290–325  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

288}
289
290func TestGmailDraftsCreateCmd_JSON(t *testing.T) {
291 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
292 if strings.Contains(r.URL.Path, "/gmail/v1/users/me/drafts") && r.Method == http.MethodPost {
293 w.Header().Set("Content-Type", "application/json")
294 _ = json.NewEncoder(w).Encode(map[string]any{
295 "id": "d1",
296 "message": map[string]any{
297 "id": "m1",
298 },
299 })
300 return
301 }
302 http.NotFound(w, r)
303 }))
304 defer srv.Close()
305
306 svc := newGmailServiceFromServer(t, srv)
307 flags := &RootFlags{Account: "a@b.com"}
308
309 var jsonOut bytes.Buffer
310 ctx := withGmailTestService(newCmdRuntimeJSONOutputContext(t, &jsonOut, io.Discard), svc)
311 if err := runKong(t, &GmailDraftsCreateCmd{}, []string{"--to", "a@example.com", "--subject", "S", "--body", "Hello"}, ctx, flags); err != nil {
312 t.Fatalf("execute: %v", err)
313 }
314
315 var parsed struct {
316 DraftID string `json:"draftId"`
317 ThreadID string `json:"threadId"`
318 }
319 if err := json.Unmarshal(jsonOut.Bytes(), &parsed); err != nil {
320 t.Fatalf("json parse: %v", err)
321 }
322 if parsed.DraftID != "d1" {
323 t.Fatalf("unexpected json: %#v", parsed)
324 }
325}
326
327func TestGmailDraftsCreateCmd_BodyHTMLFile(t *testing.T) {
328 htmlPath := filepath.Join(t.TempDir(), "body.html")

Callers

nothing calls this directly

Calls 6

withGmailTestServiceFunction · 0.85
runKongFunction · 0.85
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected