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

Function TestPutFileIfExistsSkipSkipsExistingFile

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

Source from the content-addressed store, hash-verified

1177}
1178
1179func TestPutFileIfExistsSkipSkipsExistingFile(t *testing.T) {
1180 tmpFile := filepath.Join(t.TempDir(), "test.txt")
1181 if err := os.WriteFile(tmpFile, []byte("test"), 0644); err != nil {
1182 t.Fatal(err)
1183 }
1184
1185 mock := &mockFilesClient{
1186 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
1187 return &files.FileMetadata{Metadata: files.Metadata{PathDisplay: arg.Path}}, nil
1188 },
1189 uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) {
1190 t.Fatal("upload should not be called for existing destination with --if-exists skip")
1191 return nil, nil
1192 },
1193 }
1194 stubFilesClient(t, mock)
1195
1196 stderr := captureStderr(t, func() {
1197 err := putFile(tmpFile, "/existing.txt", putOptions{
1198 chunkSize: 1 << 24,
1199 workers: 4,
1200 ifExists: putIfExistsSkip,
1201 })
1202 if err != nil {
1203 t.Fatalf("putFile error: %v", err)
1204 }
1205 })
1206 if !bytes.Contains([]byte(stderr), []byte("Skipping /existing.txt")) {
1207 t.Errorf("stderr = %q, want skip message", stderr)
1208 }
1209}
1210
1211func TestPutFileIfExistsFailFailsExistingFile(t *testing.T) {
1212 tmpFile := filepath.Join(t.TempDir(), "test.txt")

Callers

nothing calls this directly

Calls 3

stubFilesClientFunction · 0.85
captureStderrFunction · 0.85
putFileFunction · 0.85

Tested by

no test coverage detected