Skip to content

Commit f1d8916

Browse files
export API to set RefTime of Updater (#641)
* export API to set RefTime of Updater Signed-off-by: Adam Korczynski <[email protected]> * Update metadata/updater/updater.go Co-authored-by: Fredrik Skogman <[email protected]> Signed-off-by: AdamKorcz <[email protected]> * update name in test Signed-off-by: Adam Korczynski <[email protected]> * add comment to UnsafeSetRefTime Signed-off-by: Adam Korczynski <[email protected]> * Update metadata/updater/updater.go Co-authored-by: Fredrik Skogman <[email protected]> Signed-off-by: AdamKorcz <[email protected]> --------- Signed-off-by: Adam Korczynski <[email protected]> Signed-off-by: AdamKorcz <[email protected]> Co-authored-by: Fredrik Skogman <[email protected]>
1 parent 4186614 commit f1d8916

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

metadata/updater/updater.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,13 @@ func (update *Updater) GetTrustedMetadataSet() trustedmetadata.TrustedMetadata {
662662
return *update.trusted
663663
}
664664

665+
// UnsafeSetRefTime sets the reference time that the updater uses.
666+
// This should only be done in tests.
667+
// Using this function is useful when testing time-related behavior in go-tuf.
668+
func (update *Updater) UnsafeSetRefTime(t time.Time) {
669+
update.trusted.RefTime = t
670+
}
671+
665672
func IsWindowsPath(path string) bool {
666673
match, _ := regexp.MatchString(`^[a-zA-Z]:\\`, path)
667674
return match

metadata/updater/updater_top_level_update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func runRefresh(updaterConfig *config.UpdaterConfig, moveInTime time.Time) (Upda
9898
}
9999

100100
if moveInTime != time.Now() {
101-
updater.trusted.RefTime = moveInTime
101+
updater.UnsafeSetRefTime(moveInTime)
102102
}
103103

104104
return *updater, updater.Refresh()

0 commit comments

Comments
 (0)