(t *testing.T)
| 1209 | } |
| 1210 | |
| 1211 | func 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 | |
| 1241 | func TestPutFileIfExistsFailUploadsMissingFileWithAddMode(t *testing.T) { |
| 1242 | tmpFile := filepath.Join(t.TempDir(), "test.txt") |
nothing calls this directly
no test coverage detected