2026-04-28 18:44:16 +03:00
|
|
|
package boxstore
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"warpbox/lib/models"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestStartRetentionWaitsForEveryFileToFinish(t *testing.T) {
|
|
|
|
|
manifest := models.BoxManifest{
|
|
|
|
|
RetentionSecs: 10,
|
|
|
|
|
Files: []models.BoxFile{
|
|
|
|
|
{ID: "one", Status: models.FileStatusReady},
|
|
|
|
|
{ID: "two", Status: models.FileStatusWork},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startRetentionIfTerminalUnlocked(&manifest)
|
|
|
|
|
|
|
|
|
|
if !manifest.ExpiresAt.IsZero() {
|
|
|
|
|
t.Fatalf("expected retention to stay unset while a file is still uploading, got %s", manifest.ExpiresAt)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestStartRetentionBeginsWhenEveryFileIsTerminal(t *testing.T) {
|
|
|
|
|
manifest := models.BoxManifest{
|
|
|
|
|
RetentionSecs: 10,
|
|
|
|
|
Files: []models.BoxFile{
|
|
|
|
|
{ID: "one", Status: models.FileStatusReady},
|
|
|
|
|
{ID: "two", Status: models.FileStatusFailed},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
before := time.Now().UTC()
|
|
|
|
|
|
|
|
|
|
startRetentionIfTerminalUnlocked(&manifest)
|
|
|
|
|
|
|
|
|
|
if manifest.ExpiresAt.IsZero() {
|
|
|
|
|
t.Fatal("expected retention to start once every file is complete or failed")
|
|
|
|
|
}
|
|
|
|
|
if manifest.ExpiresAt.Before(before.Add(9 * time.Second)) {
|
|
|
|
|
t.Fatalf("expected retention to start from completion time, got %s", manifest.ExpiresAt)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-28 19:41:23 +03:00
|
|
|
|
|
|
|
|
func TestStartRetentionSkipsOneTimeDownload(t *testing.T) {
|
|
|
|
|
manifest := models.BoxManifest{
|
|
|
|
|
RetentionSecs: 10,
|
|
|
|
|
OneTimeDownload: true,
|
|
|
|
|
Files: []models.BoxFile{
|
|
|
|
|
{ID: "one", Status: models.FileStatusReady},
|
|
|
|
|
{ID: "two", Status: models.FileStatusReady},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startRetentionIfTerminalUnlocked(&manifest)
|
|
|
|
|
|
|
|
|
|
if !manifest.ExpiresAt.IsZero() {
|
|
|
|
|
t.Fatalf("expected one-time download box to avoid retention expiry, got %s", manifest.ExpiresAt)
|
|
|
|
|
}
|
|
|
|
|
}
|