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

Function TestKeepCreate_JSON

internal/cmd/keep_test.go:607–641  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

605}
606
607func TestKeepCreate_JSON(t *testing.T) {
608 home := t.TempDir()
609 t.Setenv("HOME", home)
610 t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, "xdg-config"))
611
612 account := "a@b.com"
613 _ = writeKeepSA(t)
614
615 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
616 if r.Method == http.MethodPost && r.URL.Path == "/v1/notes" {
617 _, _ = io.WriteString(w, `{"name":"notes/new3","title":"T","createTime":"2026-01-01T00:00:00Z","updateTime":"2026-01-01T00:00:00Z"}`)
618 return
619 }
620 http.NotFound(w, r)
621 }))
622 t.Cleanup(srv.Close)
623
624 svc := newKeepTestServiceFromServer(t, srv)
625 result := executeWithKeepTestService(t, []string{
626 "--json", "keep", "create", "--text", "body", "--account", account,
627 }, svc)
628 if result.err != nil {
629 t.Fatalf("Execute: %v\nstderr=%q", result.err, result.stderr)
630 }
631
632 var payload struct {
633 Note map[string]any `json:"note"`
634 }
635 if err := json.Unmarshal([]byte(result.stdout), &payload); err != nil {
636 t.Fatalf("json parse: %v\nout=%q", err, result.stdout)
637 }
638 if payload.Note["name"] != "notes/new3" {
639 t.Fatalf("unexpected note: %#v", payload.Note)
640 }
641}
642
643func TestKeepCreate_MissingBody(t *testing.T) {
644 err := (&KeepCreateCmd{}).Run(context.Background(), nil, nil)

Callers

nothing calls this directly

Calls 4

writeKeepSAFunction · 0.85
CleanupMethod · 0.80

Tested by

no test coverage detected