test: ttlFor, HEAD 500/cached-index, rpm full-metadata xml, generic content-type
This commit is contained in:
@@ -413,6 +413,44 @@ func TestRevalidationUpstreamError(t *testing.T) {
|
||||
res.Reader.Close()
|
||||
}
|
||||
|
||||
func TestTTLFor(t *testing.T) {
|
||||
e := &Engine{}
|
||||
if got := e.ttlFor(models.Remote{ImmutableTTL: 100}, ClassImmutable); got != 100*time.Second {
|
||||
t.Errorf("immutable ttl = %v", got)
|
||||
}
|
||||
if got := e.ttlFor(models.Remote{ImmutableTTL: 0}, ClassImmutable); got != 0 {
|
||||
t.Errorf("immutable ttl=0 (forever) = %v", got)
|
||||
}
|
||||
if got := e.ttlFor(models.Remote{MutableTTL: 50}, ClassMutable); got != 50*time.Second {
|
||||
t.Errorf("mutable ttl = %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeadUpstreamStatusError(t *testing.T) {
|
||||
requireStack(t)
|
||||
r := seed(t, genericRemote("eng-head500"))
|
||||
if _, err := testEngine.Head(context.Background(), r, "err500", prov(t, models.PackageGeneric)); err == nil {
|
||||
t.Error("expected error for HEAD of 500 upstream")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeadCachedIndex(t *testing.T) {
|
||||
requireStack(t)
|
||||
ctx := context.Background()
|
||||
r := seed(t, models.Remote{Name: "eng-headidx", PackageType: models.PackageNPM, RepoType: models.RepoTypeRemote, BaseURL: upstream.URL, CheckMutable: true, MutableTTL: 3600})
|
||||
p := prov(t, models.PackageNPM)
|
||||
// Cache the mutable index, then HEAD is answered from the stored index.
|
||||
res, err := testEngine.Fetch(ctx, r, "pkg", p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res.Reader.Close()
|
||||
h, err := testEngine.Head(ctx, r, "pkg", p)
|
||||
if err != nil || h.Source != "cache" {
|
||||
t.Errorf("head of cached index: %+v %v", h, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpstreamErrorUnwrap(t *testing.T) {
|
||||
base := context.DeadlineExceeded
|
||||
ue := &UpstreamError{Err: base}
|
||||
|
||||
Reference in New Issue
Block a user