-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackup_test.go
56 lines (48 loc) · 1.13 KB
/
backup_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
package main
import (
"testing"
"time"
"github.com/flynn/flynn/pkg/random"
)
func TestRepo(t *testing.T) {
repo, err := NewBackupRepo(db)
if err != nil {
t.Fatal(err)
}
id := random.UUID()
b, err := repo.NewBackup(id)
if err != nil {
t.Fatal(err)
}
if b.AppID != id {
t.Error("app id did not match")
}
backups, err := repo.GetBackups(id)
if err != nil {
t.Fatal(err)
}
if len(backups) != 1 {
t.Error("expected 1 app")
}
if backups[0].AppID != id {
t.Error("wrong id")
}
backup, err := repo.GetBackup(b.BackupID)
if err != nil || backup == nil {
t.Error("could not retrieve backup by id")
}
repo.CompleteBackup(b, 1234)
backups, _ = repo.GetBackups(id)
// PG time resolution is lower, so rounding is necessary
if backups[0].CompletedAt.Round(time.Second) != b.CompletedAt.Round(time.Second) {
t.Errorf("completed at time mismatch %s %s", backups[0].CompletedAt, b.CompletedAt)
}
if backups[0].Bytes != 1234 {
t.Errorf("expected 1234 bytes got %d", backups[0].Bytes)
}
repo.DeleteBackup(b)
backups, _ = repo.GetBackups(id)
if len(backups) != 0 {
t.Errorf("expected 0 backups, got %d", len(backups))
}
}