Skip to content

Commit

Permalink
try haydens comments
Browse files Browse the repository at this point in the history
Signed-off-by: Asra Ali <asraa@google.com>
  • Loading branch information
asraa committed May 27, 2022
1 parent 9b337a5 commit 81a86c3
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 798 deletions.
380 changes: 91 additions & 289 deletions pkg/cosign/tuf/client.go

Large diffs are not rendered by default.

37 changes: 29 additions & 8 deletions pkg/cosign/tuf/client_test.go
Expand Up @@ -94,24 +94,33 @@ func TestNoCache(t *testing.T) {
td := t.TempDir()
t.Setenv("TUF_ROOT", td)

// First initialization, populate the cache.
tuf, err := NewFromEnv(ctx)
if err != nil {
t.Fatal(err)
}
checkTargetsAndMeta(t, tuf)
tuf.Close()

// Force expiration so we have some content to download
forceExpiration(t, true)

tuf, err := NewFromEnv(ctx)
tuf, err = NewFromEnv(ctx)
if err != nil {
t.Fatal(err)
}
checkTargetsAndMeta(t, tuf)
tuf.Close()

// No filesystem writes when using SIGSTORE_NO_CACHE.
if l := dirLen(t, td); l != 0 {
t.Errorf("expected no filesystem writes, got %d entries", l)
}
}

func TestCache(t *testing.T) {
ctx := context.Background()
// Once more with NO_CACHE
// Once more with cache.
t.Setenv("SIGSTORE_NO_CACHE", "false")
td := t.TempDir()
t.Setenv("TUF_ROOT", td)
Expand All @@ -121,26 +130,38 @@ func TestCache(t *testing.T) {
t.Errorf("expected no filesystem writes, got %d entries", l)
}

// Nothing should get downloaded if everything is up to date
forceExpiration(t, false)
// First initialization, populate the cache. Expect disk writes.
tuf, err := NewFromEnv(ctx)
if err != nil {
t.Fatal(err)
}
checkTargetsAndMeta(t, tuf)
tuf.Close()
cachedDirLen := dirLen(t, td)
if cachedDirLen == 0 {
t.Errorf("expected filesystem writes, got %d entries", cachedDirLen)
}

if l := dirLen(t, td); l != 0 {
t.Errorf("expected no filesystem writes, got %d entries", l)
// Nothing should get downloaded if everything is up to date.
forceExpiration(t, false)
tuf, err = NewFromEnv(ctx)
if err != nil {
t.Fatal(err)
}
tuf.Close()

// Force expiration so that content gets downloaded. This should write to disk
if l := dirLen(t, td); cachedDirLen != l {
t.Errorf("expected no filesystem writes, got %d entries", l-cachedDirLen)
}

// Forcing expiration, but expect no disk writes because all targets up to date.
forceExpiration(t, true)
tuf, err = NewFromEnv(ctx)
if err != nil {
t.Fatal(err)
}

if l := dirLen(t, td); l == 0 {
if l := dirLen(t, td); l != cachedDirLen {
t.Errorf("expected filesystem writes, got %d entries", l)
}
checkTargetsAndMeta(t, tuf)
Expand Down
130 changes: 0 additions & 130 deletions pkg/cosign/tuf/repository/1.root.json

This file was deleted.

144 changes: 0 additions & 144 deletions pkg/cosign/tuf/repository/2.root.json

This file was deleted.

23 changes: 0 additions & 23 deletions pkg/cosign/tuf/repository/rekor.json

This file was deleted.

0 comments on commit 81a86c3

Please sign in to comment.