-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_test.go
720 lines (623 loc) · 25.1 KB
/
upload_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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
package main
import (
"testing"
"os"
"path/filepath"
"fmt"
"os/user"
"time"
"errors"
"encoding/json"
"strings"
)
func setupSourceForUploadTest() (string, error) {
src, err := os.MkdirTemp("", "")
if err != nil {
return "", fmt.Errorf("failed to create the temporary directory; %w", err)
}
err = os.WriteFile(filepath.Join(src, "evolution"), []byte("haunter"), 0644)
if err != nil {
return "", err
}
err = os.WriteFile(filepath.Join(src, "moves"), []byte("lick,confuse_ray,shadow_ball,dream_eater"), 0644)
if err != nil {
return "", err
}
return src, nil
}
func setupProjectForUploadTest(project string, globals *globalConfiguration) error {
self, err := user.Current()
if err != nil {
return fmt.Errorf("failed to determine the current user; %w", err)
}
err = createProject(project, nil, self.Username, globals)
if err != nil {
return err
}
return nil
}
func TestUploadHandlerSimple(t *testing.T) {
project := "original_series"
asset := "gastly"
version := "lavender"
reg, err := constructMockRegistry()
if err != nil {
t.Fatalf("failed to create the registry; %v", err)
}
globals := newGlobalConfiguration(reg)
src, err := setupSourceForUploadTest()
if err != nil {
t.Fatalf("failed to set up test directories; %v", err)
}
err = setupProjectForUploadTest(project, &globals)
if err != nil {
t.Fatalf("failed to set up project directory; %v", err)
}
req_string := fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s" }`, filepath.Base(src), project, asset, version)
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err != nil {
t.Fatalf("failed to perform the upload; %v", err)
}
// Checking a few manifest entries and files.
destination := filepath.Join(reg, project, asset, version)
man, err := readManifest(destination)
if err != nil {
t.Fatalf("failed to read the manifest; %v", err)
}
info, ok := man["evolution"]
if !ok || int(info.Size) != len("haunter") || info.Link != nil {
t.Fatal("unexpected manifest entry for 'evolution'")
}
err = verifyFileContents(filepath.Join(destination, "moves"), "lick,confuse_ray,shadow_ball,dream_eater")
if err != nil {
t.Fatalf("could not verify 'moves'; %v", err)
}
// Checking out the summary.
summ, err := readSummary(destination)
if err != nil {
t.Fatalf("failed to read the summary; %v", err)
}
self, err := user.Current()
if err != nil {
t.Fatalf("failed to determine the current user; %v", err)
}
if summ.UploadUserId != self.Username {
t.Fatalf("user in summary is not as expected (expected %q, got %q)", self.Username, summ.UploadUserId)
}
ustart, err := time.Parse(time.RFC3339, summ.UploadStart)
if err != nil {
t.Fatalf("upload start is not a valid time; %v", err)
}
ufinish, err := time.Parse(time.RFC3339, summ.UploadFinish)
if err != nil {
t.Fatalf("upload finish is not a valid time; %v", err)
}
if ustart.After(ufinish) {
t.Fatalf("upload finish should be at or after the upload start; %v", err)
}
if summ.OnProbation != nil {
t.Fatal("no probation property should be present")
}
// Checking out the usage.
project_dir := filepath.Join(reg, project)
used, err := readUsage(project_dir)
if err != nil {
t.Fatalf("failed to read the usage; %v", err)
}
expected_usage, err := computeUsage(project_dir, true)
if err != nil {
t.Fatalf("failed to compute the expected usage; %v", err)
}
if expected_usage != used.Total {
t.Fatalf("unexpected usage total (expected %d, got %d)", expected_usage, used.Total)
}
manifest_sum := int64(0)
for _, m := range man {
manifest_sum += m.Size
}
if expected_usage != manifest_sum {
t.Fatalf("usage total does not match with sum of sizes in manifest (expected %d, got %d)", expected_usage, manifest_sum)
}
// Checking out the latest version.
latest, err := readLatest(filepath.Join(reg, project, asset))
if err != nil {
t.Fatalf("failed to read the latest; %v", err)
}
if latest.Version != version {
t.Fatalf("unexpected latest version (expected %q, got %q)", latest.Version, version)
}
quota_raw, err := os.ReadFile(filepath.Join(reg, project, "..quota"))
if err != nil {
t.Fatalf("failed to read the quota; %v", err)
}
deets := struct {
Baseline int `json:"baseline"`
GrowthRate int `json:"growth_rate"`
Year int `json:"year"`
}{}
err = json.Unmarshal(quota_raw, &deets)
if err != nil {
t.Fatalf("failed to parse the quota; %v", err)
}
if !(deets.Baseline > 0 && deets.GrowthRate > 0 && deets.Year > 0) {
t.Fatalf("uninitialized fields in the quota")
}
// Checking that the logs have something in them.
logs, err := readAllLogs(reg)
if err != nil {
t.Fatalf("failed to read the logs; %v", err)
}
if len(logs) != 1 {
t.Fatalf("expected exactly one entry in the log directory")
}
if logs[0].Type != "add-version" ||
logs[0].Project == nil || *(logs[0].Project) != project ||
logs[0].Asset == nil || *(logs[0].Asset) != asset ||
logs[0].Version == nil || *(logs[0].Version) != version ||
logs[0].Latest == nil || !*(logs[0].Latest) {
t.Fatalf("unexpected contents for first log in %q", reg)
}
}
func TestUploadHandlerSimpleFailures(t *testing.T) {
reg, err := constructMockRegistry()
if err != nil {
t.Fatalf("failed to create the registry; %v", err)
}
globals := newGlobalConfiguration(reg)
src, err := setupSourceForUploadTest()
if err != nil {
t.Fatalf("failed to set up test directories; %v", err)
}
t.Run("bad source", func(t *testing.T) {
project := "test"
asset := "gastly"
version := "lavender"
err := setupProjectForUploadTest(project, &globals)
if err != nil {
t.Fatalf("failed to set up project directory; %v", err)
}
req_string := fmt.Sprintf(`{ "project": "%s", "asset": "%s", "version": "%s" }`, project, asset, version)
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err == nil || !strings.Contains(err.Error(), "expected a 'source'") {
t.Fatalf("configuration should have failed without a source")
}
req_string = fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s" }`, src, project, asset, version)
reqname, err = dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err == nil || !strings.Contains(err.Error(), "same directory as") {
t.Fatalf("configuration should have failed if the source is a path instead of a name")
}
})
t.Run("bad project", func(t *testing.T) {
req_string := fmt.Sprintf(`{ "source": "%s", "asset": "foo", "version": "bar" }`, filepath.Base(src))
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err == nil || !strings.Contains(err.Error(), "expected a 'project'") {
t.Fatal("configuration should fail for missing project")
}
req_string = fmt.Sprintf(`{ "source": "%s", "project": "bad/name", "asset": "foo", "version": "bar" }`, filepath.Base(src))
reqname, err = dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err == nil || !strings.Contains(err.Error(), "invalid project name") {
t.Fatal("configuration should fail for invalid project name")
}
})
t.Run("bad asset", func(t *testing.T) {
req_string := fmt.Sprintf(`{ "source": "%s", "project": "foo", "version": "bar" }`, filepath.Base(src))
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err == nil || !strings.Contains(err.Error(), "expected an 'asset'") {
t.Fatal("configuration should fail for missing asset")
}
req_string = fmt.Sprintf(`{ "source": "%s", "project": "foo", "asset": "..bar", "version": "bar" }`, filepath.Base(src))
reqname, err = dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err == nil || !strings.Contains(err.Error(), "invalid asset name") {
t.Fatal("configuration should fail for invalid asset name")
}
})
t.Run("bad version", func(t *testing.T) {
req_string := fmt.Sprintf(`{ "source": "%s", "project": "foo", "asset": "bar" }`, filepath.Base(src))
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err == nil || !strings.Contains(err.Error(), "expected a 'version'") {
t.Fatal("configuration should fail for missing version")
}
req_string = fmt.Sprintf(`{ "source": "%s", "project": "foo", "asset": "bar", "version": "" }`, filepath.Base(src))
reqname, err = dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err == nil || !strings.Contains(err.Error(), "invalid version name") {
t.Fatal("configuration should fail for invalid version name")
}
})
}
func TestUploadHandlerUpdate(t *testing.T) {
project := "original_series"
asset := "gastly"
version := "lavender"
reg, err := constructMockRegistry()
if err != nil {
t.Fatalf("failed to create the registry; %v", err)
}
globals := newGlobalConfiguration(reg)
src, err := setupSourceForUploadTest()
if err != nil {
t.Fatalf("failed to set up test directories; %v", err)
}
err = setupProjectForUploadTest(project, &globals)
if err != nil {
t.Fatalf("failed to set up project directory; %v", err)
}
// Uploading the first version.
old_usage := int64(0)
{
req_string := fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s" }`, filepath.Base(src), project, asset, version)
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err != nil {
t.Fatalf("failed to perform the upload; %v", err)
}
used, err := readUsage(filepath.Join(reg, project))
if err != nil {
t.Fatalf("failed to read the usage; %v", err)
}
old_usage = used.Total
}
// Executing another transfer on a different version.
t.Run("new version", func(t *testing.T) {
version := "cerulean"
req_string := fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s" }`, filepath.Base(src), project, asset, version)
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
all_evos := "haunter,gengar"
err = os.WriteFile(filepath.Join(src, "evolution"), []byte(all_evos), 0644)
if err != nil {
t.Fatalf("failed to update the 'evolution' file; %v", err)
}
err = uploadHandler(reqname, &globals)
if err != nil {
t.Fatalf("failed to perform the upload; %v", err)
}
destination := filepath.Join(reg, project, asset, version)
man, err := readManifest(destination)
if err != nil {
t.Fatalf("failed to read the manifest; %v", err)
}
info, ok := man["evolution"]
if !ok || int(info.Size) != len(all_evos) || info.Link != nil {
t.Fatal("unexpected manifest entry for 'evolution'")
}
minfo, ok := man["moves"]
if !ok || minfo.Link == nil {
t.Fatal("expected a link for 'moves' in the manifest")
}
err = verifyFileContents(filepath.Join(destination, "evolution"), all_evos)
if err != nil {
t.Fatalf("could not verify 'evolution'; %v", err)
}
// Ensuring that the usage accumulates.
project_dir := filepath.Join(reg, project)
usage, err := readUsage(project_dir)
if err != nil {
t.Fatalf("failed to read the usage; %v", err)
}
expected_usage, err := computeUsage(project_dir, true)
if err != nil {
t.Fatalf("failed to compute the expected usage; %v", err)
}
if expected_usage != usage.Total {
t.Fatalf("unexpected usage total (expected %d, got %d)", expected_usage, usage.Total)
}
for _, m := range man {
if m.Link == nil {
old_usage += m.Size
}
}
if usage.Total != old_usage {
t.Fatalf("usage total should equal the sum of non-link sizes (expected %d, got %d)", old_usage, usage.Total)
}
// Confirming that we updated to the latest version.
latest, err := readLatest(filepath.Join(reg, project, asset))
if err != nil {
t.Fatalf("failed to read the latest; %v", err)
}
if latest.Version != version {
t.Fatalf("unexpected latest version (expected %q, got %q)", version, latest.Version)
}
})
t.Run("new version", func(t *testing.T) {
req_string := fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s" }`, filepath.Base(src), project, asset, version)
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err == nil || !strings.Contains(err.Error(), "already exists") {
t.Fatal("configuration should fail for an existing version")
}
})
}
func setupProjectForUploadTestWithPermissions(project string, owners []string, uploaders []unsafeUploaderEntry, globals *globalConfiguration) error {
self, err := user.Current()
if err != nil {
return fmt.Errorf("failed to determine the current user; %w", err)
}
err = createProject(project, &unsafePermissionsMetadata{ Owners: owners, Uploaders: uploaders }, self.Username, globals)
if err != nil {
return err
}
return nil
}
func TestUploadHandlerUnauthorized(t *testing.T) {
reg, err := constructMockRegistry()
if err != nil {
t.Fatalf("failed to create the registry; %v", err)
}
globals := newGlobalConfiguration(reg)
src, err := setupSourceForUploadTest()
if err != nil {
t.Fatalf("failed to set up test directories; %v", err)
}
// Making a project with explicitly no permissions.
project := "aaron"
err = setupProjectForUploadTestWithPermissions(project, []string{}, nil, &globals)
if err != nil {
t.Fatalf("failed to create the project; %v", err)
}
// Now making the request.
asset := "BAR"
version := "whee"
req_string := fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s" }`, filepath.Base(src), project, asset, version)
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err == nil || !strings.Contains(err.Error(), "not authorized") {
t.Fatalf("failed to reject upload from non-authorized user")
}
}
func TestUploadHandlerGlobalWrite(t *testing.T) {
reg, err := constructMockRegistry()
if err != nil {
t.Fatalf("failed to create the registry; %v", err)
}
globals := newGlobalConfiguration(reg)
src, err := setupSourceForUploadTest()
if err != nil {
t.Fatalf("failed to set up test directories; %v", err)
}
// Making a project with global write permissions.
project := "hyperbole"
self, err := user.Current()
if err != nil {
t.Fatalf("failed to determine the current user; %v", err)
}
global_write := true
err = createProject(project, &unsafePermissionsMetadata{ Owners: []string{}, Uploaders: nil, GlobalWrite: &global_write }, self.Username, &globals)
if err != nil {
t.Fatalf("failed to create the project; %v", err)
}
// Now making the request.
asset := "BAR"
version := "whee"
req_string := fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s" }`, filepath.Base(src), project, asset, version)
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err != nil {
t.Fatalf("failed to perform a global write upload; %v", err)
}
// Checking that permissions are set up correctly.
perms, err := readPermissions(filepath.Join(globals.Registry, project))
if err != nil {
t.Fatalf("failed to read the new permissions; %v", err)
}
if len(perms.Uploaders) != 1 || perms.Uploaders[0].Id != self.Username || *(perms.Uploaders[0].Asset) != asset {
t.Fatalf("global write upload did not update the uploaders; %v", err)
}
// Check that the upload completed.
destination := filepath.Join(reg, project, asset, version)
man, err := readManifest(destination)
info, ok := man["evolution"]
if !ok || int(info.Size) != len("haunter") || info.Link != nil {
t.Fatal("unexpected manifest entry for 'evolution'")
}
}
func TestUploadHandlerProbation(t *testing.T) {
reg, err := constructMockRegistry()
if err != nil {
t.Fatalf("failed to create the registry; %v", err)
}
globals := newGlobalConfiguration(reg)
src, err := setupSourceForUploadTest()
if err != nil {
t.Fatalf("failed to set up test directories; %v", err)
}
project := "setsuna"
asset := "yuki"
version := "nakagawa"
err = setupProjectForUploadTest(project, &globals)
if err != nil {
t.Fatalf("failed to set up project directory; %v", err)
}
req_string := fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s", "on_probation": true }`, filepath.Base(src), project, asset, version)
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err != nil {
t.Fatalf("failed to perform the upload; %v", err)
}
// Summary file states that it's on probation.
summ, err := readSummary(filepath.Join(reg, project, asset, version))
if err != nil {
t.Fatalf("failed to read the summary; %v", err)
}
if !summ.IsProbational() {
t.Fatal("expected version to be on probation")
}
// No latest file should be created for probational projects.
_, err = readLatest(filepath.Join(reg, project, asset))
if err == nil || !errors.Is(err, os.ErrNotExist) {
t.Fatal("no ..latest file should be created on probation")
}
// No logs should be created either.
logs, err := os.ReadDir(filepath.Join(reg, logDirName))
if err != nil {
t.Fatalf("failed to read the log directory")
}
if len(logs) != 0 {
t.Fatalf("no logs should be created on probation")
}
}
func TestUploadHandlerUpdateOnProbation(t *testing.T) {
reg, err := constructMockRegistry()
if err != nil {
t.Fatalf("failed to create the registry; %v", err)
}
globals := newGlobalConfiguration(reg)
src, err := setupSourceForUploadTest()
if err != nil {
t.Fatalf("failed to set up test directories; %v", err)
}
self, err := user.Current()
if err != nil {
t.Fatalf("could not identify the current user; %v", err)
}
self_name := self.Username
// Uploaders are not trusted by default.
t.Run("untrusted uploader", func(t *testing.T) {
project := "ghost"
err := setupProjectForUploadTestWithPermissions(project, []string{}, []unsafeUploaderEntry{ unsafeUploaderEntry{ Id: &self_name } }, &globals)
if err != nil {
t.Fatalf("failed to create the project; %v", err)
}
asset := "gastly"
version := "shadow_ball"
req_string := fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s" }`, filepath.Base(src), project, asset, version)
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err != nil {
t.Fatalf("failed to perform the upload; %v", err)
}
summ, err := readSummary(filepath.Join(reg, project, asset, version))
if err != nil {
t.Fatalf("failed to read the summary file; %v", err)
}
if !summ.IsProbational() {
t.Fatal("expected 'on_probation' to be 'true'")
}
})
// Checking that trusted uploaders do not get probation.
t.Run("trusted uploader", func(t *testing.T) {
project := "pokemon_adventures" // changing the project name to get a new project.
trusted := true
err := setupProjectForUploadTestWithPermissions(project, []string{}, []unsafeUploaderEntry{ unsafeUploaderEntry{ Id: &self_name, Trusted: &trusted } }, &globals)
if err != nil {
t.Fatalf("failed to create the project; %v", err)
}
asset := "gastly"
version := "dream_eater"
req_string := fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s" }`, filepath.Base(src), project, asset, version)
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err != nil {
t.Fatalf("failed to perform the upload; %v", err)
}
summ, err := readSummary(filepath.Join(reg, project, asset, version))
if err != nil {
t.Fatalf("failed to read the summary file; %v", err)
}
if summ.OnProbation != nil {
t.Fatal("expected no 'on_probation' entry to be present")
}
// ... unless they specifically ask for it.
version = "hypnosis"
req_string = fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s", "on_probation": true }`, filepath.Base(src), project, asset, version)
reqname, err = dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err != nil {
t.Fatalf("failed to perform the upload; %v", err)
}
summ, err = readSummary(filepath.Join(reg, project, asset, version))
if err != nil {
t.Fatalf("failed to read the summary file; %v", err)
}
if !summ.IsProbational() {
t.Fatal("expected 'on_probation' to be 'true'")
}
})
// Owners are free from probation.
t.Run("owner", func(t *testing.T) {
project := "ss_anne" // changing project name again.
err := setupProjectForUploadTestWithPermissions(project, []string{ self_name }, nil, &globals)
if err != nil {
t.Fatalf("failed to create the project; %v", err)
}
asset := "gastly"
version := "confuse_ray"
req_string := fmt.Sprintf(`{ "source": "%s", "project": "%s", "asset": "%s", "version": "%s" }`, filepath.Base(src), project, asset, version)
reqname, err := dumpRequest("upload", req_string)
if err != nil {
t.Fatalf("failed to create upload request; %v", err)
}
err = uploadHandler(reqname, &globals)
if err != nil {
t.Fatalf("failed to perform the upload; %v", err)
}
summ, err := readSummary(filepath.Join(reg, project, asset, version))
if err != nil {
t.Fatalf("failed to read the summary file; %v", err)
}
if summ.OnProbation != nil {
t.Fatal("expected no 'on_probation' entry to be present")
}
})
}