diff --git a/metadata/updater/updater.go b/metadata/updater/updater.go index 7d723dfa..8433cefb 100644 --- a/metadata/updater/updater.go +++ b/metadata/updater/updater.go @@ -662,6 +662,13 @@ func (update *Updater) GetTrustedMetadataSet() trustedmetadata.TrustedMetadata { return *update.trusted } +// UnsafeSetRefTime sets the reference time that the updater uses. +// This should only be done in tests. +// Using this function is useful when testing time-related behavior in go-tuf. +func (update *Updater) UnsafeSetRefTime(t time.Time) { + update.trusted.RefTime = t +} + func IsWindowsPath(path string) bool { match, _ := regexp.MatchString(`^[a-zA-Z]:\\`, path) return match diff --git a/metadata/updater/updater_top_level_update_test.go b/metadata/updater/updater_top_level_update_test.go index 42715fb0..214105b4 100644 --- a/metadata/updater/updater_top_level_update_test.go +++ b/metadata/updater/updater_top_level_update_test.go @@ -98,7 +98,7 @@ func runRefresh(updaterConfig *config.UpdaterConfig, moveInTime time.Time) (Upda } if moveInTime != time.Now() { - updater.trusted.RefTime = moveInTime + updater.UnsafeSetRefTime(moveInTime) } return *updater, updater.Refresh()