(t *testing.T)
| 1137 | } |
| 1138 | |
| 1139 | func TestPutFileUsesSourceModifiedTime(t *testing.T) { |
| 1140 | tmpFile := filepath.Join(t.TempDir(), "mtime.txt") |
| 1141 | if err := os.WriteFile(tmpFile, []byte("test"), 0644); err != nil { |
| 1142 | t.Fatal(err) |
| 1143 | } |
| 1144 | sourceModTime := time.Date(2020, 4, 23, 14, 37, 4, 0, time.FixedZone("source", -7*60*60)) |
| 1145 | if err := os.Chtimes(tmpFile, sourceModTime, sourceModTime); err != nil { |
| 1146 | t.Fatal(err) |
| 1147 | } |
| 1148 | |
| 1149 | var uploadedClientModified *dropbox.DBXTime |
| 1150 | mock := &mockFilesClient{ |
| 1151 | uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) { |
| 1152 | uploadedClientModified = arg.ClientModified |
| 1153 | if _, err := io.ReadAll(content); err != nil { |
| 1154 | t.Fatal(err) |
| 1155 | } |
| 1156 | return &files.FileMetadata{}, nil |
| 1157 | }, |
| 1158 | } |
| 1159 | stubFilesClient(t, mock) |
| 1160 | |
| 1161 | if err := putFile(tmpFile, "/mtime.txt", putOptions{ |
| 1162 | chunkSize: 1 << 24, |
| 1163 | workers: 4, |
| 1164 | ifExists: putIfExistsOverwrite, |
| 1165 | }); err != nil { |
| 1166 | t.Fatalf("putFile error: %v", err) |
| 1167 | } |
| 1168 | |
| 1169 | if uploadedClientModified == nil { |
| 1170 | t.Fatal("ClientModified = nil, want source file modified time") |
| 1171 | } |
| 1172 | got := time.Time(*uploadedClientModified) |
| 1173 | want := sourceModTime.UTC().Round(time.Second) |
| 1174 | if !got.Equal(want) { |
| 1175 | t.Fatalf("ClientModified = %s, want %s", got.Format(time.RFC3339Nano), want.Format(time.RFC3339Nano)) |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | func TestPutFileIfExistsSkipSkipsExistingFile(t *testing.T) { |
| 1180 | tmpFile := filepath.Join(t.TempDir(), "test.txt") |
nothing calls this directly
no test coverage detected