Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions internal/handler/cooldown_expiry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestHandlersAskCooldownThroughRecorder(t *testing.T) {
func TestHandlerRewriteExpiresWithWithheldVersion(t *testing.T) {
for _, c := range validatorCases {
t.Run(c.ecosystem, func(t *testing.T) {
u := cooldownUpstream(t) // the newest version was published 2h ago
u, published := cooldownUpstreamPublished(t)
proxy, _, clock := validatorProxyWithDB(t, u, time.Hour)
// Cooldown compares with the wall clock, so the proxy's clock
// follows it here.
Expand All @@ -167,10 +167,8 @@ func TestHandlerRewriteExpiresWithWithheldVersion(t *testing.T) {
}
for _, el := range proxy.rewrites.entries {
expires := el.Value.(*rewriteEntry).expires
// Published 2h ago with a 3h cooldown: available in an hour,
// to the second the publish time was given in.
if want := time.Now().Add(time.Hour); expires.Before(want.Add(-2*time.Second)) || expires.After(want.Add(time.Second)) {
t.Errorf("rewrite expires %v, want about %v when the withheld version is available", expires, want)
if want := published.Add(3 * time.Hour); !expires.Equal(want) {
t.Errorf("rewrite expires %v, want %v, when the withheld version is available", expires, want)
}
}
})
Expand Down
13 changes: 11 additions & 2 deletions internal/handler/metadata_validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,16 @@ func TestRewrittenMetadataLastModifiedWithClockSkew(t *testing.T) {
// and a cooldown of an hour keeps it.
func cooldownUpstream(t *testing.T) *validatorUpstream {
t.Helper()
recent := time.Now().Add(-2 * time.Hour).UTC().Format(time.RFC3339)
u, _ := cooldownUpstreamPublished(t)
return u
}

// cooldownUpstreamPublished is cooldownUpstream, also returning when the
// newest version was published.
func cooldownUpstreamPublished(t *testing.T) (*validatorUpstream, time.Time) {
t.Helper()
published := time.Now().Add(-2 * time.Hour).UTC().Truncate(time.Second)
recent := published.Format(time.RFC3339)
u := newValidatorUpstream(t)
u.set(
`{"name":"left-pad","dist-tags":{"latest":"1.4.0"},"versions":{`+
Expand All @@ -699,7 +708,7 @@ func cooldownUpstream(t *testing.T) *validatorUpstream {
`{"version":"1.0.0","time":"2016-01-01T00:00:00Z","dist":{"type":"zip","url":"https://example.com/pkg-1.0.0.zip"}},`+
`{"version":"1.1.0","time":"`+recent+`","dist":{"type":"zip","url":"https://example.com/pkg-1.1.0.zip"}}]}}`,
)
return u
return u, published
}

// TestRewrittenMetadataETagWithCooldownFollowsKeptVersions checks that with
Expand Down
Loading