(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func 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 | |
| 115 | func TestDocsCreate_Pageless(t *testing.T) { |
| 116 | t.Parallel() |
nothing calls this directly
no test coverage detected