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

Function TestPutJSONIfExistsSkipOutputsSkippedResult

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

Source from the content-addressed store, hash-verified

802}
803
804func TestPutJSONIfExistsSkipOutputsSkippedResult(t *testing.T) {
805 tmpFile := filepath.Join(t.TempDir(), "test.txt")
806 if err := os.WriteFile(tmpFile, []byte("test"), 0644); err != nil {
807 t.Fatal(err)
808 }
809
810 mock := &mockFilesClient{
811 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
812 return putFileMetadata(arg.Path, 12), nil
813 },
814 uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) {
815 t.Fatal("upload should not be called for skipped destination")
816 return nil, nil
817 },
818 }
819 stubFilesClient(t, mock)
820
821 var stdout, stderr bytes.Buffer
822 cmd := testPutJSONCmd(&stdout, &stderr)
823 if err := cmd.Flags().Set("if-exists", putIfExistsSkip); err != nil {
824 t.Fatal(err)
825 }
826 if err := put(cmd, []string{tmpFile, "/existing.txt"}); err != nil {
827 t.Fatalf("put error: %v", err)
828 }
829
830 got := decodePutOutput(t, &stdout)
831 if len(got.Results) != 1 {
832 t.Fatalf("results len = %d, want 1", len(got.Results))
833 }
834 result := got.Results[0]
835 if result.Status != putStatusSkipped || result.Kind != putKindFile {
836 t.Fatalf("result status/kind = %s/%s", result.Status, result.Kind)
837 }
838 if result.Result == nil || result.Result.PathDisplay != "/existing.txt" {
839 t.Fatalf("metadata = %+v", result.Result)
840 }
841 if !strings.Contains(stderr.String(), "Skipping /existing.txt") {
842 t.Fatalf("stderr = %q, want skip status", stderr.String())
843 }
844}
845
846func TestPutJSONIfExistsFailReturnsErrorWithoutStdout(t *testing.T) {
847 tmpFile := filepath.Join(t.TempDir(), "test.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