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

Function TestPutFileIfExistsFailFailsExistingFile

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

Source from the content-addressed store, hash-verified

1209}
1210
1211func TestPutFileIfExistsFailFailsExistingFile(t *testing.T) {
1212 tmpFile := filepath.Join(t.TempDir(), "test.txt")
1213 if err := os.WriteFile(tmpFile, []byte("test"), 0644); err != nil {
1214 t.Fatal(err)
1215 }
1216
1217 mock := &mockFilesClient{
1218 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
1219 return &files.FileMetadata{Metadata: files.Metadata{PathDisplay: arg.Path}}, nil
1220 },
1221 uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) {
1222 t.Fatal("upload should not be called for existing destination with --if-exists fail")
1223 return nil, nil
1224 },
1225 }
1226 stubFilesClient(t, mock)
1227
1228 err := putFile(tmpFile, "/existing.txt", putOptions{
1229 chunkSize: 1 << 24,
1230 workers: 4,
1231 ifExists: putIfExistsFail,
1232 })
1233 if err == nil {
1234 t.Fatal("expected existing destination error")
1235 }
1236 if !bytes.Contains([]byte(err.Error()), []byte("already exists")) {
1237 t.Errorf("error = %q, want already exists", err.Error())
1238 }
1239}
1240
1241func TestPutFileIfExistsFailUploadsMissingFileWithAddMode(t *testing.T) {
1242 tmpFile := filepath.Join(t.TempDir(), "test.txt")

Callers

nothing calls this directly

Calls 3

stubFilesClientFunction · 0.85
putFileFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected