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

Function TestPutJSONIfExistsFailReturnsErrorWithoutStdout

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

Source from the content-addressed store, hash-verified

844}
845
846func TestPutJSONIfExistsFailReturnsErrorWithoutStdout(t *testing.T) {
847 tmpFile := filepath.Join(t.TempDir(), "test.txt")
848 if err := os.WriteFile(tmpFile, []byte("test"), 0644); err != nil {
849 t.Fatal(err)
850 }
851
852 mock := &mockFilesClient{
853 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
854 return putFileMetadata(arg.Path, 12), nil
855 },
856 uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) {
857 t.Fatal("upload should not be called for failed destination")
858 return nil, nil
859 },
860 }
861 stubFilesClient(t, mock)
862
863 var stdout bytes.Buffer
864 cmd := testPutJSONCmd(&stdout, nil)
865 if err := cmd.Flags().Set("if-exists", putIfExistsFail); err != nil {
866 t.Fatal(err)
867 }
868 err := put(cmd, []string{tmpFile, "/existing.txt"})
869 if err == nil {
870 t.Fatal("expected error")
871 }
872 details := jsonErrorDetails(err)
873 if details["operation"] != "upload" || details["from_path"] != tmpFile || details["to_path"] != "/existing.txt" {
874 t.Fatalf("details = %#v, want upload operation and source/destination", details)
875 }
876 if stdout.Len() != 0 {
877 t.Fatalf("stdout = %q, want empty on error", stdout.String())
878 }
879}
880
881func TestPutJSONStdinDoesNotExposeTempPath(t *testing.T) {
882 mock := &mockFilesClient{

Callers

nothing calls this directly

Calls 5

putFileMetadataFunction · 0.85
stubFilesClientFunction · 0.85
testPutJSONCmdFunction · 0.85
putFunction · 0.85
jsonErrorDetailsFunction · 0.85

Tested by

no test coverage detected