Skip to content

Commit 0486c8a

Browse files
committed
Truncate timestamps for backup creation check to seconds
1 parent 63d6d5a commit 0486c8a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

upcloud/service/service_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,7 @@ func TestCreateBackup(t *testing.T) {
410410
// Create a backup
411411
t.Logf("Creating backup of storage with UUID %s ...", storageDetails.UUID)
412412

413-
utc, err := time.LoadLocation("UTC")
414-
handleError(err)
415-
416-
timeBeforeBackup := time.Now().In(utc)
413+
timeBeforeBackup := utcTimeWithSecondPrecision()
417414

418415
backupDetails, err := svc.CreateBackup(&request.CreateBackupRequest{
419416
UUID: storageDetails.UUID,
@@ -423,7 +420,7 @@ func TestCreateBackup(t *testing.T) {
423420
handleError(err)
424421
waitForStorageOnline(storageDetails.UUID)
425422

426-
timeAfterBackup := time.Now().In(utc)
423+
timeAfterBackup := utcTimeWithSecondPrecision()
427424

428425
t.Logf("Created backup with UUID %s", backupDetails.UUID)
429426

@@ -773,6 +770,17 @@ func waitForStorageOnline(uuid string) {
773770
handleError(err)
774771
}
775772

773+
// Returns the current UTC time with second precision (milliseconds truncated).
774+
// This is the format we usually get from the UpCloud API.
775+
func utcTimeWithSecondPrecision() time.Time {
776+
utc, err := time.LoadLocation("UTC")
777+
handleError(err)
778+
779+
t := time.Now().In(utc).Truncate(time.Second)
780+
781+
return t
782+
}
783+
776784
// Handles the error by panicing, thus stopping the test execution
777785
func handleError(err error) {
778786
if err != nil {

0 commit comments

Comments
 (0)