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

Function TestDocsCreateCopyCat_JSON

internal/cmd/docs_commands_test.go:59–113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func TestDocsCreateCopyCat_JSON(t *testing.T) {
60 t.Parallel()
61
62 export := func(context.Context, *drive.Service, string, string) (*http.Response, error) {
63 return &http.Response{
64 StatusCode: http.StatusOK,
65 Body: io.NopCloser(strings.NewReader("doc text")),
66 }, nil
67 }
68
69 srv := httptest.NewServer(docsCreateCopyCatHandler())
70 defer srv.Close()
71
72 svc, err := drive.NewService(context.Background(),
73 option.WithoutAuthentication(),
74 option.WithHTTPClient(srv.Client()),
75 option.WithEndpoint(srv.URL+"/"),
76 )
77 if err != nil {
78 t.Fatalf("NewService: %v", err)
79 }
80
81 docSvc, err := docs.NewService(context.Background(),
82 option.WithoutAuthentication(),
83 option.WithHTTPClient(srv.Client()),
84 option.WithEndpoint(srv.URL+"/"),
85 )
86 if err != nil {
87 t.Fatalf("NewDocsService: %v", err)
88 }
89 flags := &RootFlags{Account: "a@b.com"}
90 var stdout, stderr bytes.Buffer
91 ctx := withDriveTestOperations(newCmdRuntimeJSONOutputContext(t, &stdout, &stderr), svc, nil, export)
92 ctx = withDocsTestService(ctx, docSvc)
93
94 cmd := &DocsCreateCmd{}
95 if err := runKong(t, cmd, []string{"Doc"}, ctx, flags); err != nil {
96 t.Fatalf("create: %v", err)
97 }
98
99 stdout.Reset()
100 cmdCopy := &DocsCopyCmd{}
101 if err := runKong(t, cmdCopy, []string{"doc1", "Copy"}, ctx, flags); err != nil {
102 t.Fatalf("copy: %v", err)
103 }
104
105 stdout.Reset()
106 cmdCat := &DocsCatCmd{}
107 if err := runKong(t, cmdCat, []string{"doc1"}, ctx, flags); err != nil {
108 t.Fatalf("cat: %v", err)
109 }
110 if !strings.Contains(stdout.String(), "doc text") {
111 t.Fatalf("unexpected cat output: %q", stdout.String())
112 }
113}
114
115func TestDocsCreate_Pageless(t *testing.T) {
116 t.Parallel()

Callers

nothing calls this directly

Calls 7

docsCreateCopyCatHandlerFunction · 0.85
withDriveTestOperationsFunction · 0.85
withDocsTestServiceFunction · 0.85
runKongFunction · 0.85
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected