(t *testing.T)
| 1239 | } |
| 1240 | |
| 1241 | func TestPutFileIfExistsFailUploadsMissingFileWithAddMode(t *testing.T) { |
| 1242 | tmpFile := filepath.Join(t.TempDir(), "test.txt") |
| 1243 | if err := os.WriteFile(tmpFile, []byte("test"), 0644); err != nil { |
| 1244 | t.Fatal(err) |
| 1245 | } |
| 1246 | |
| 1247 | var mode string |
| 1248 | var strictConflict bool |
| 1249 | mock := &mockFilesClient{ |
| 1250 | getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) { |
| 1251 | return nil, getMetadataNotFoundError() |
| 1252 | }, |
| 1253 | uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) { |
| 1254 | mode = arg.Mode.Tag |
| 1255 | strictConflict = arg.StrictConflict |
| 1256 | return &files.FileMetadata{}, nil |
| 1257 | }, |
| 1258 | } |
| 1259 | stubFilesClient(t, mock) |
| 1260 | |
| 1261 | err := putFile(tmpFile, "/new.txt", putOptions{ |
| 1262 | chunkSize: 1 << 24, |
| 1263 | workers: 4, |
| 1264 | ifExists: putIfExistsFail, |
| 1265 | }) |
| 1266 | if err != nil { |
| 1267 | t.Fatalf("putFile error: %v", err) |
| 1268 | } |
| 1269 | if mode != files.WriteModeAdd { |
| 1270 | t.Errorf("write mode = %q, want %q", mode, files.WriteModeAdd) |
| 1271 | } |
| 1272 | if !strictConflict { |
| 1273 | t.Error("strict conflict = false, want true") |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | func TestPutFileIfExistsOverwriteUsesOverwriteMode(t *testing.T) { |
| 1278 | tmpFile := filepath.Join(t.TempDir(), "test.txt") |
nothing calls this directly
no test coverage detected