-
Notifications
You must be signed in to change notification settings - Fork 0
/
summary_test.go
62 lines (54 loc) · 1.58 KB
/
summary_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
package main
import (
"testing"
"os"
"path/filepath"
)
func TestReadSummary(t *testing.T) {
f, err := os.MkdirTemp("", "test-")
if err != nil {
t.Fatalf("failed to create tempdir; %v", err)
}
err = os.WriteFile(
filepath.Join(f, summaryFileName),
[]byte(`
{
"upload_user_id": "aaron",
"upload_start": "2020-02-02T02:20:02Z",
"upload_finish": "2021-12-20T21:20:11Z"
}`),
0644,
)
if err != nil {
t.Fatalf("failed to create test summary; %v", err)
}
out, err := readSummary(f)
if err != nil {
t.Fatalf("failed to read test summary; %v", err)
}
if out.UploadUserId != "aaron" || out.UploadStart != "2020-02-02T02:20:02Z" || out.UploadFinish != "2021-12-20T21:20:11Z" || out.OnProbation != nil {
t.Fatalf("unexpected values in the test summary; %v", err)
}
// Trying again with the probational flag.
err = os.WriteFile(
filepath.Join(f, summaryFileName),
[]byte(`
{
"upload_user_id": "aaron",
"upload_start": "2020-02-02T02:20:02Z",
"upload_finish": "2021-12-20T21:20:11Z",
"on_probation": true
}`),
0644,
)
if err != nil {
t.Fatalf("failed to create test summary; %v", err)
}
out, err = readSummary(f)
if err != nil {
t.Fatalf("failed to read test summary; %v", err)
}
if out.UploadUserId != "aaron" || out.UploadStart != "2020-02-02T02:20:02Z" || out.UploadFinish != "2021-12-20T21:20:11Z" || !out.IsProbational() {
t.Fatalf("unexpected values in the test summary; %v", err)
}
}