27 lines
865 B
Go
27 lines
865 B
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestLatestBackups(t *testing.T) {
|
|
items := []BackupItem{
|
|
{VMID: 100, CreatedAt: 10, Storage: "old"},
|
|
{VMID: 100, CreatedAt: 20, Storage: "new"},
|
|
{VMID: 101, CreatedAt: 15, Storage: "only"},
|
|
}
|
|
latest := latestBackups(items)
|
|
if len(latest) != 2 || latest[0].Storage != "new" {
|
|
t.Fatalf("неожиданный список последних копий: %+v", latest)
|
|
}
|
|
if latest[0].PreviousSizeBytes != 0 {
|
|
t.Fatalf("unexpected previous size: %+v", latest[0])
|
|
}
|
|
}
|
|
|
|
func TestLatestBackupsComparesSize(t *testing.T) {
|
|
items := []BackupItem{{VMID: 100, CreatedAt: 20, SizeBytes: 120}, {VMID: 100, CreatedAt: 10, SizeBytes: 100}}
|
|
latest := latestBackups(items)
|
|
if len(latest) != 1 || latest[0].SizeChangePercent == nil || *latest[0].SizeChangePercent != 20 {
|
|
t.Fatalf("unexpected comparison: %+v", latest)
|
|
}
|
|
}
|