-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathzboxcli_file_update_test.go
536 lines (418 loc) · 24.5 KB
/
zboxcli_file_update_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
package cli_tests
import (
"encoding/base64"
"encoding/json"
"fmt"
"math"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"testing"
"time"
climodel "github.com/0chain/system_test/internal/cli/model"
"github.com/0chain/system_test/internal/api/util/test"
cliutils "github.com/0chain/system_test/internal/cli/util"
"github.com/stretchr/testify/require"
)
func TestFileUpdate(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
t.SetSmokeTests("update file with thumbnail")
t.Parallel()
t.Run("update file with thumbnail", func(t *test.SystemTest) {
// this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": 10 * MB,
"lock": 9,
})
filesize := int64(0.5 * MB)
remotepath := "/"
localFilePath := generateFileAndUpload(t, allocationID, remotepath, filesize)
os.Remove(localFilePath) //nolint: errcheck
newPath := generateRandomTestFileName(t)
err := createFileWithSize(newPath, filesize+1024)
require.Nil(t, err)
thumbnailFile, thumbnailSize := updateFileWithThumbnail(t, allocationID, "/"+filepath.Base(localFilePath), newPath, int64(filesize+1024))
os.Remove(thumbnailFile) //nolint: errcheck
os.Remove(newPath) //nolint: errcheck
remotepath += filepath.Base(localFilePath)
output, err := downloadFile(t, configPath, createParams(map[string]interface{}{
"allocation": allocationID,
"remotepath": remotepath,
"localpath": thumbnailFile,
"thumbnail": true,
}), true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 2)
stats, err := os.Stat(thumbnailFile)
require.Nil(t, err, strings.Join(output, "\n"))
require.Equal(t, thumbnailSize, int(stats.Size()))
createAllocationTestTeardown(t, allocationID)
})
t.Run("File Update with same size - Users should not be charged, blobber should not be paid", func(t *test.SystemTest) {
// Logic: Upload a 1 MB file, get the write pool info. Update said file with another file
// of size 1 MB. Get write pool info and check nothing has been deducted.
createWallet(t)
// Lock 0.5 token for allocation
allocParams := createParams(map[string]interface{}{
"lock": "5",
"size": 4 * MB,
})
output, err := createNewAllocation(t, configPath, allocParams)
require.Nil(t, err, "Failed to create new allocation", strings.Join(output, "\n"))
require.Len(t, output, 1)
require.Regexp(t, regexp.MustCompile("Allocation created: ([a-f0-9]{64})"), output[0], "Allocation creation output did not match expected")
allocationID := strings.Fields(output[0])[2]
fileSize := int64(math.Floor(1 * MB))
// Upload 1 MB file
localpath := uploadRandomlyGeneratedFile(t, allocationID, "/", fileSize)
cliutils.Wait(t, 30*time.Second)
// initial write pool
initialAllocation := getAllocation(t, allocationID)
// Update with same size
remotepath := "/" + filepath.Base(localpath)
updateFileWithRandomlyGeneratedData(t, allocationID, remotepath, fileSize)
// Get expected upload cost
output, _ = getUploadCostInUnit(t, configPath, allocationID, localpath)
expectedUploadCostInZCN, err := strconv.ParseFloat(strings.Fields(output[0])[0], 64)
require.Nil(t, err, "Cost couldn't be parsed to float", strings.Join(output, "\n"))
unit := strings.Fields(output[0])[1]
expectedUploadCostInZCN = unitToZCN(expectedUploadCostInZCN, unit)
// Expected cost is given in "per 720 hours", we need 1 hour
// Expected cost takes into account data+parity, so we divide by that
actualExpectedUploadCostInZCN := expectedUploadCostInZCN / ((2 + 2) * 720)
finalAllocation := getAllocation(t, allocationID)
actualCost := initialAllocation.WritePool - finalAllocation.WritePool
require.True(t, actualCost == 0 || intToZCN(actualCost) == actualExpectedUploadCostInZCN)
createAllocationTestTeardown(t, allocationID)
})
t.Run("update thumbnail of uploaded file", func(t *test.SystemTest) {
// this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": 10 * MB,
"lock": 9,
})
filesize := int64(0.5 * MB)
remotepath := "/"
thumbnail := escapedTestName(t) + "thumbnail.png"
generateThumbnail(t, thumbnail) //nolint
localFilePath := generateFileAndUploadWithParam(t, allocationID, remotepath, filesize, map[string]interface{}{"thumbnailpath": thumbnail})
os.Remove(thumbnail) //nolint: errcheck
os.Remove(localFilePath) //nolint: errcheck
downloadDir, _ := filepath.Split(localFilePath)
output, err := downloadFile(t, configPath, createParams(map[string]interface{}{
"allocation": allocationID,
"remotepath": remotepath + filepath.Base(localFilePath),
"localpath": downloadDir,
"thumbnail": true,
}), true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 2)
// Update with new thumbnail
os.Remove(localFilePath) //nolint: errcheck
newPath := generateRandomTestFileName(t)
err = createFileWithSize(newPath, filesize+1024)
require.Nil(t, err)
newThumbnail, newThumbnailSize := updateFileWithThumbnail(t, allocationID, "/"+filepath.Base(localFilePath), newPath, int64(filesize+1024))
os.Remove(newThumbnail) //nolint: errcheck
os.Remove(newPath) //nolint: errcheck
downloadNewThumbnailDir := newThumbnail + "down"
defer os.RemoveAll(downloadNewThumbnailDir) //nolint: errcheck
output, err = downloadFile(t, configPath, createParams(map[string]interface{}{
"allocation": allocationID,
"remotepath": remotepath + filepath.Base(localFilePath),
"localpath": downloadNewThumbnailDir,
"thumbnail": true,
}), true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 2)
localNewThumbnail := filepath.Join(downloadNewThumbnailDir, filepath.Base(remotepath))
stat, err := os.Stat(localNewThumbnail)
require.Nil(t, err)
require.Equal(t, newThumbnailSize, int(stat.Size()))
createAllocationTestTeardown(t, allocationID)
})
t.Run("update with another file of same size should work", func(t *test.SystemTest) {
// this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards
allocationID := setupAllocation(t, configPath, map[string]interface{}{"size": 10 * MB})
filesize := int64(0.5 * MB)
remotepath := "/"
localFilePath := generateFileAndUpload(t, allocationID, remotepath, filesize)
output, err := getFileMeta(t, configPath, createParams(map[string]interface{}{
"allocation": allocationID,
"json": "",
"remotepath": remotepath + filepath.Base(localFilePath),
}), true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 1)
var meta climodel.FileMetaResult
err = json.NewDecoder(strings.NewReader(output[0])).Decode(&meta)
require.Nil(t, err, strings.Join(output, "\n"))
require.Equal(t, filesize, meta.ActualFileSize, "file size should be same as uploaded")
updateFileWithRandomlyGeneratedData(t, allocationID, "/"+filepath.Base(localFilePath), int64(filesize))
output, err = getFileMeta(t, configPath, createParams(map[string]interface{}{
"allocation": allocationID,
"json": "",
"remotepath": remotepath + filepath.Base(localFilePath),
}), true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 1)
err = json.NewDecoder(strings.NewReader(output[0])).Decode(&meta)
require.Nil(t, err, strings.Join(output, "\n"))
require.Equal(t, filesize, meta.ActualFileSize)
createAllocationTestTeardown(t, allocationID)
})
t.Run("update with another file of bigger size should work", func(t *test.SystemTest) {
// this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards
allocationID := setupAllocation(t, configPath, map[string]interface{}{"size": 10 * MB})
filesize := int64(0.5 * MB)
remotepath := "/"
localFilePath := generateFileAndUpload(t, allocationID, remotepath, filesize)
output, err := getFileMeta(t, configPath, createParams(map[string]interface{}{
"allocation": allocationID,
"json": "",
"remotepath": remotepath + filepath.Base(localFilePath),
}), true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 1)
var meta climodel.FileMetaResult
err = json.NewDecoder(strings.NewReader(output[0])).Decode(&meta)
require.Nil(t, err, strings.Join(output, "\n"))
require.Equal(t, filesize, meta.ActualFileSize, "file size should be same as uploaded")
newFileSize := int64(1.5 * MB)
updateFileWithRandomlyGeneratedData(t, allocationID, "/"+filepath.Base(localFilePath), int64(newFileSize))
output, err = getFileMeta(t, configPath, createParams(map[string]interface{}{
"allocation": allocationID,
"json": "",
"remotepath": remotepath + filepath.Base(localFilePath),
}), true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 1)
err = json.NewDecoder(strings.NewReader(output[0])).Decode(&meta)
require.Nil(t, err, strings.Join(output, "\n"))
require.Equal(t, newFileSize, meta.ActualFileSize)
createAllocationTestTeardown(t, allocationID)
})
t.Run("update non-encrypted file with encrypted file should work", func(t *test.SystemTest) {
// this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": 10 * MB,
"lock": 9,
})
filesize := int64(0.5 * MB)
remotepath := "/"
localFilePath := generateFileAndUpload(t, allocationID, remotepath, filesize)
localfile := generateRandomTestFileName(t)
err := createFileWithSize(localfile, int64(filesize))
require.Nil(t, err)
params := createParams(map[string]interface{}{"allocation": allocationID, "remotepath": "/"})
output, err := listFilesInAllocation(t, configPath, params, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 3)
isEncrypted := strings.Split(output[2], "|")[8]
require.Equal(t, "NO", strings.TrimSpace(isEncrypted))
// update with encrypted file
output, err = updateFile(t, configPath, map[string]interface{}{
"allocation": allocationID,
"remotepath": "/" + filepath.Base(localFilePath),
"localpath": localfile,
"encrypt": true,
}, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 2)
params = createParams(map[string]interface{}{"allocation": allocationID, "remotepath": "/"})
output, err = listFilesInAllocation(t, configPath, params, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 3)
isEncrypted = strings.Split(output[2], "|")[8]
require.Equal(t, "YES", strings.TrimSpace(isEncrypted))
createAllocationTestTeardown(t, allocationID)
})
t.Run("update encrypted file with non-encrypted file should work", func(t *test.SystemTest) {
// this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": 10 * MB,
"lock": 9,
})
filesize := int64(0.5 * MB)
remotepath := "/"
localFilePath := generateFileAndUploadWithParam(t, allocationID, remotepath, filesize, map[string]interface{}{"encrypt": true})
localfile := generateRandomTestFileName(t)
err := createFileWithSize(localfile, int64(filesize))
require.Nil(t, err)
params := createParams(map[string]interface{}{"allocation": allocationID, "remotepath": "/"})
output, err := listFilesInAllocation(t, configPath, params, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 3)
isEncrypted := strings.Split(output[2], "|")[8]
require.Equal(t, "YES", strings.TrimSpace(isEncrypted))
// update with encrypted file
output, err = updateFile(t, configPath, map[string]interface{}{
"allocation": allocationID,
"remotepath": "/" + filepath.Base(localFilePath),
"localpath": localfile,
}, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 2)
params = createParams(map[string]interface{}{"allocation": allocationID, "remotepath": "/"})
output, err = listFilesInAllocation(t, configPath, params, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 3)
yes := strings.Split(output[2], "|")[8]
require.Equal(t, "NO", strings.TrimSpace(yes))
createAllocationTestTeardown(t, allocationID)
})
t.Run("update encrypted file with encrypted file should work", func(t *test.SystemTest) {
// this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": 10 * MB,
"lock": 9,
})
filesize := int64(0.5 * MB)
remotepath := "/"
localFilePath := generateFileAndUploadWithParam(t, allocationID, remotepath, filesize, map[string]interface{}{"encrypt": true})
params := createParams(map[string]interface{}{"allocation": allocationID, "remotepath": "/"})
output, err := listFilesInAllocation(t, configPath, params, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 3)
isEncrypted := strings.Split(output[2], "|")[8]
require.Equal(t, "YES", strings.TrimSpace(isEncrypted))
filename := strings.Split(output[2], "|")[1]
require.Equal(t, filepath.Base(localFilePath), strings.TrimSpace(filename))
localfile := generateRandomTestFileName(t)
err = createFileWithSize(localfile, int64(filesize))
require.Nil(t, err)
// update with encrypted file
output, err = updateFile(t, configPath, map[string]interface{}{
"allocation": allocationID,
"remotepath": "/" + filepath.Base(localFilePath),
"localpath": localfile,
"encrypt": true,
}, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 2)
params = createParams(map[string]interface{}{"allocation": allocationID, "remotepath": "/"})
output, err = listFilesInAllocation(t, configPath, params, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 3)
yes := strings.Split(output[2], "|")[8]
require.Equal(t, "YES", strings.Trim(yes, " "))
filename = strings.Split(output[2], "|")[1]
require.Equal(t, filepath.Base(localFilePath), strings.TrimSpace(filename))
createAllocationTestTeardown(t, allocationID)
})
t.Run("update file that does not exists should fail", func(t *test.SystemTest) {
// this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards
allocationID := setupAllocation(t, configPath, map[string]interface{}{"size": 10 * MB})
filesize := int64(0.5 * MB)
localfile := generateRandomTestFileName(t)
err := createFileWithSize(localfile, filesize)
require.Nil(t, err)
output, err := updateFile(t, configPath, map[string]interface{}{
"allocation": allocationID,
"remotepath": "/" + filepath.Base(localfile),
"localpath": localfile,
}, false)
require.NotNil(t, err, strings.Join(output, "\n"))
aggregatedOutput := strings.Join(output, " ")
require.Contains(t, aggregatedOutput, "File at path does not exist for update")
createAllocationTestTeardown(t, allocationID)
})
t.Run("update with another file of size larger than allocation should fail", func(t *test.SystemTest) {
// this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards
allocationID := setupAllocation(t, configPath, map[string]interface{}{"size": 1 * MB})
filesize := int64(0.5 * MB)
remotepath := "/"
localFilePath := generateFileAndUpload(t, allocationID, remotepath, filesize)
newFileSize := 2 * MB
localfile := generateRandomTestFileName(t)
err := createFileWithSize(localfile, int64(newFileSize))
require.Nil(t, err)
output, err := updateFile(t, configPath, map[string]interface{}{
"allocation": allocationID,
"remotepath": "/" + filepath.Base(localFilePath),
"localpath": localfile,
}, false)
require.NotNil(t, err, strings.Join(output, "\n"))
require.True(t, strings.Contains(strings.Join(output, "\n"), "max_allocation_size"), strings.Join(output, "\n"))
createAllocationTestTeardown(t, allocationID)
})
t.Run("update with allocation update file option forbidden should fail", func(t *test.SystemTest) {
// this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards
allocationID := setupAllocation(t, configPath, map[string]interface{}{"size": 10 * MB, "forbid_update": nil})
filesize := int64(0.5 * MB)
remotepath := "/"
localFilePath := generateFileAndUpload(t, allocationID, remotepath, filesize)
newFileSize := 2 * MB
localfile := generateRandomTestFileName(t)
err := createFileWithSize(localfile, int64(newFileSize))
require.Nil(t, err)
output, err := updateFile(t, configPath, map[string]interface{}{
"allocation": allocationID,
"remotepath": "/" + filepath.Base(localFilePath),
"localpath": localfile,
}, false)
require.NotNil(t, err, strings.Join(output, "\n"))
require.True(t, strings.Contains(strings.Join(output, "\n"), "this options for this file is not permitted for this allocation"), strings.Join(output, "\n"))
createAllocationTestTeardown(t, allocationID)
})
t.RunWithTimeout("File Update with a different size - Blobbers should be paid for the extra file size", (3*time.Minute)+(30*time.Second), func(t *test.SystemTest) {
// Logic: Upload a 0.5 MB file and get the upload cost. Update the 0.5 MB file with a 1 MB file
// and see that blobber's write pool balances are deduced again for the cost of uploading extra
// 0.5 MBs.
createWallet(t)
// Lock 0.5 token for allocation
allocParams := createParams(map[string]interface{}{
"lock": "1",
"size": 10 * MB,
})
output, err := createNewAllocation(t, configPath, allocParams)
require.Nil(t, err, "Failed to create new allocation", strings.Join(output, "\n"))
require.Len(t, output, 1)
require.Regexp(t, regexp.MustCompile("Allocation created: ([a-f0-9]{64})"), output[0], "Allocation creation output did not match expected")
allocationID := strings.Fields(output[0])[2]
fileSize := int64(0.5 * MB)
// Get expected upload cost for 0.5 MB
localpath := uploadRandomlyGeneratedFile(t, allocationID, "/", fileSize)
output, _ = getUploadCostInUnit(t, configPath, allocationID, localpath)
expectedUploadCostInZCN, err := strconv.ParseFloat(strings.Fields(output[0])[0], 64)
require.Nil(t, err, "Cost couldn't be parsed to float", strings.Join(output, "\n"))
unit := strings.Fields(output[0])[1]
expectedUploadCostInZCN = unitToZCN(expectedUploadCostInZCN, unit)
fmt.Println("expectedUploadCostInZCN", expectedUploadCostInZCN)
// Wait for write pool balance to be deduced for initial 0.5 MB
cliutils.Wait(t, 20*time.Second)
initialAllocation := getAllocation(t, allocationID)
require.InEpsilon(t, expectedUploadCostInZCN, intToZCN(initialAllocation.MovedToChallenge), 0.05)
remotepath := "/" + filepath.Base(localpath)
updateFileWithRandomlyGeneratedData(t, allocationID, remotepath, int64(1*MB))
// Wait before fetching final write pool
cliutils.Wait(t, 20*time.Second)
finalAllocation := getAllocation(t, allocationID)
require.InEpsilon(t, expectedUploadCostInZCN*2, intToZCN(finalAllocation.MovedToChallenge), 0.2)
createAllocationTestTeardown(t, allocationID)
})
}
func generateThumbnail(t *test.SystemTest, localpath string) int {
//nolint
thumbnailBytes, _ := base64.StdEncoding.DecodeString(`iVBORw0KGgoAAAANSUhEUgAAANgAAADpCAMAAABx2AnXAAAAwFBMVEX///8REiQAAADa2ttlZWWlpaU5OTnIyMiIiIhzc3ODg4OVlZXExMT6+vr39/fOzs7v7+9dXV0rKyvf399GRkbn5+dBQUEREREAABp5eXmxsbFsbGxaWlqfn59gYGC4uLgAABWrq6sAAByXl5dOTk4LCwscHBwvLy88PDwkJCR5eYGUlJpBQUxtbnYAAA8ZGyojJTNiY2sAAB82N0OFhYxSU10uLjxKSlQeHy1+f4ebnaRNUFmLjZNdXWWqq7JoaXKY6lzbAAAMKUlEQVR4nO2dC1u6PhvHETARORlhchA8ZYVa+tM0+2u9/3f17N5AUdG0ELBnn666pgzal+3e4d4GDEOhUCgUCoVCoVAoFAqFQqFQKBQKhUKhUCiUP4pqPrNst2NknY6E0Rw2oJh1Us7FsIotST508IFdY6aarN+i1oJUa3FHlWc2QiftxP0CYZNsNeZwBQ48Whwn4ijXY2eVaIbo+8fh6y4uphIEhbTT91NULOjRde5xoPYU4AQVRSmSTXAPnrNL6nncQcItFNBsdps7BY63IMOCuBx8rcRdRZMqQkM9VP1kgQ5pbZFwd0eZCF8WUcANIhvwbUwNIxPzY5+tlFJ9AthugnBrR9gzZI6FAjeRyA/719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/3HskNtteTU2YDj5tKAmw1SzbF6XMnfMY92uw3fwd961FQCYc1l4Ws4bA6HY5ad/lsW2KH/9jJQ9cWwP1LZ8ac0YUcGF/uPLsdsuJq811/fB81RuzBY/jeoj+qF1ylK/gz9FF7fm+PV9G25mE9Xk+V4OZuu2M+2v6hHhdVRlFV//OUP6s3pv4+X5td03n5h29yiM/fYiVd6eRkZ6qh9JBnJ0576w8/hdP658v3PwXLyOfS/lnNvyPqr4XDR7y/GPuu/fS5Zf7zq+NNFcfhWZP2vdlRYof3pvy/rs1G/8L4aD1eF/uqt/TFcllDx44aS3/f8QWnOvaQqrL5AyubLwYc/XnZmX8uP6XjxMfmcjpbzxbj/tZx8vPn+YPkxHE6m1r/+23LpS7NVv7ktbPjeni39+mjpv4zZr+n7bFZ/qyzqzdX8X3/18jLsz4bsMOWqAxW2QWE2eS0MUNEbtGdtVCgno9mkOa8P6u+jwmA0exvMXtGfl9Fo0pyNXkbtMInrdgwyEGyoWQeLxKrbzTr+rgmGiSrMPLZi9fWfHf4/ex7XDBV2bfwPF18HmekEj6sAAAAASUVORK5CYII=`)
err := os.WriteFile(localpath, thumbnailBytes, os.ModePerm) //nolint:gosec
require.Nil(t, err, "failed to generate thumbnail", err)
return len(thumbnailBytes)
}
// nolint
func updateFileWithThumbnail(t *test.SystemTest, allocationID, remotePath, localpath string, size int64) (string, int) {
thumbnail := escapedTestName(t) + "thumbnail.png"
thumbnailSize := generateThumbnail(t, thumbnail)
output, err := updateFile(t, configPath, map[string]interface{}{
"allocation": allocationID,
"remotepath": remotePath,
"localpath": localpath,
"thumbnailpath": thumbnail,
}, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 2)
require.True(t, strings.HasPrefix(output[1], "Status completed callback.") && strings.HasSuffix(output[1], "Name = "+filepath.Base(remotePath)))
return thumbnail, thumbnailSize
}