MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestPutJSONSingleFileOutputsUploadedResult

Function TestPutJSONSingleFileOutputsUploadedResult

cmd/put_test.go:717–768  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

715}
716
717func TestPutJSONSingleFileOutputsUploadedResult(t *testing.T) {
718 tmpFile := filepath.Join(t.TempDir(), "test.txt")
719 if err := os.WriteFile(tmpFile, []byte("test"), 0644); err != nil {
720 t.Fatal(err)
721 }
722
723 mock := &mockFilesClient{
724 uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) {
725 if arg.Path != "/uploaded.txt" {
726 t.Fatalf("upload path = %q, want /uploaded.txt", arg.Path)
727 }
728 if _, err := io.ReadAll(content); err != nil {
729 t.Fatal(err)
730 }
731 return putFileMetadata(arg.Path, 4), nil
732 },
733 }
734 stubFilesClient(t, mock)
735
736 var stdout, stderr bytes.Buffer
737 cmd := testPutJSONCmd(&stdout, &stderr)
738 if err := put(cmd, []string{tmpFile, "/uploaded.txt"}); err != nil {
739 t.Fatalf("put error: %v", err)
740 }
741
742 got := decodePutOutput(t, &stdout)
743 if got.Input.Source != tmpFile || got.Input.Target != "/uploaded.txt" || got.Input.Recursive || got.Input.Stdin {
744 t.Fatalf("input = %+v", got.Input)
745 }
746 if got.Input.IfExists != putIfExistsOverwrite {
747 t.Fatalf("if_exists = %q", got.Input.IfExists)
748 }
749 if len(got.Results) != 1 {
750 t.Fatalf("results len = %d, want 1", len(got.Results))
751 }
752 result := got.Results[0]
753 if result.Status != putStatusUploaded || result.Kind != putKindFile {
754 t.Fatalf("result status/kind = %s/%s", result.Status, result.Kind)
755 }
756 if result.Input.Source != tmpFile || result.Input.Target != "/uploaded.txt" {
757 t.Fatalf("result input = %+v", result.Input)
758 }
759 if result.Result == nil {
760 t.Fatal("result metadata is nil")
761 }
762 if result.Result.Type != "file" || result.Result.PathDisplay != "/uploaded.txt" || result.Result.PathLower != "/uploaded.txt" {
763 t.Fatalf("metadata = %+v", result.Result)
764 }
765 if result.Result.Size == nil || *result.Result.Size != 4 {
766 t.Fatalf("size = %v, want 4", result.Result.Size)
767 }
768}
769
770func TestPutJSONDefaultTargetUsesComputedPath(t *testing.T) {
771 tmpFile := filepath.Join(t.TempDir(), "local.txt")

Callers

nothing calls this directly

Calls 5

putFileMetadataFunction · 0.85
stubFilesClientFunction · 0.85
testPutJSONCmdFunction · 0.85
putFunction · 0.85
decodePutOutputFunction · 0.85

Tested by

no test coverage detected