Skip to content

Commit

Permalink
Tidy up action cache asset store
Browse files Browse the repository at this point in the history
The Action Cache Asset Store is a bit hard to work with at the moment.  Lots of
logic is included in the `Get` and `Put` methods that can be extracted and
shared, while also clarifying what's really going on in these methods.

I've also modified some of the utility functions to be more generic which has
removed a load of boilerplate.
  • Loading branch information
tomcoldrick-ct authored and jjardon committed Oct 31, 2024
1 parent 8ec38db commit 4926e8e
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 254 deletions.
8 changes: 4 additions & 4 deletions pkg/fetch/caching_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestFetchBlobCaching(t *testing.T) {
Uris: []string{uri},
}
blobDigest := &remoteexecution.Digest{Hash: "d0d829c4c0ce64787cb1c998a9c29a109f8ed005633132fda4f29982487b04db", SizeBytes: 123}
refDigest, err := storage.AssetReferenceToDigest(storage.NewAssetReference([]string{uri}, []*remoteasset.Qualifier{}), instanceName)
refDigest, err := storage.ProtoToDigest(storage.NewAssetReference([]string{uri}, []*remoteasset.Qualifier{}), instanceName)
require.NoError(t, err)

t.Logf("Ref digest was %v", refDigest)
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestFetchDirectoryCaching(t *testing.T) {
Uris: []string{uri},
}
dirDigest := &remoteexecution.Digest{Hash: "d0d829c4c0ce64787cb1c998a9c29a109f8ed005633132fda4f29982487b04db", SizeBytes: 123}
refDigest, err := storage.AssetReferenceToDigest(storage.NewAssetReference([]string{uri}, []*remoteasset.Qualifier{}), instanceName)
refDigest, err := storage.ProtoToDigest(storage.NewAssetReference([]string{uri}, []*remoteasset.Qualifier{}), instanceName)
require.NoError(t, err)

backend := mock.NewMockBlobAccess(ctrl)
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestCachingFetcherExpiry(t *testing.T) {
InstanceName: "foo",
Uris: []string{uri},
}
refDigest, err := storage.AssetReferenceToDigest(storage.NewAssetReference([]string{uri}, []*remoteasset.Qualifier{}), instanceName)
refDigest, err := storage.ProtoToDigest(storage.NewAssetReference([]string{uri}, []*remoteasset.Qualifier{}), instanceName)
require.NoError(t, err)

backend := mock.NewMockBlobAccess(ctrl)
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestCachingFetcherOldestContentAccepted(t *testing.T) {
Uris: []string{uri},
OldestContentAccepted: timestamppb.Now(),
}
refDigest, err := storage.AssetReferenceToDigest(storage.NewAssetReference([]string{uri}, []*remoteasset.Qualifier{}), instanceName)
refDigest, err := storage.ProtoToDigest(storage.NewAssetReference([]string{uri}, []*remoteasset.Qualifier{}), instanceName)
require.NoError(t, err)

backend := mock.NewMockBlobAccess(ctrl)
Expand Down
8 changes: 4 additions & 4 deletions pkg/fetch/remote_execution_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (rf *remoteExecutionFetcher) fetchCommon(ctx context.Context, req *remoteas
}
for _, uri := range req.Uris {
command := commandGenerator(uri)
commandDigest, err := storage.ProtoToDigest(command)
_, commandDigest, err := storage.ProtoSerialise(command)
if err != nil {
return nil, "", "", err
}
Expand All @@ -59,7 +59,7 @@ func (rf *remoteExecutionFetcher) fetchCommon(ctx context.Context, req *remoteas
CommandDigest: commandDigest,
InputRootDigest: storage.EmptyDigest,
}
actionDigest, err := storage.ProtoToDigest(action)
_, actionDigest, err := storage.ProtoSerialise(action)
if err != nil {
return nil, "", "", err
}
Expand Down Expand Up @@ -208,7 +208,7 @@ func (rf *remoteExecutionFetcher) FetchDirectory(ctx context.Context, req *remot
return nil, err
}
root := tree.(*remoteexecution.Tree).Root
rootDigest, err := storage.ProtoToDigest(root)
_, rootDigest, err := storage.ProtoSerialise(root)
if err != nil {
return nil, err
}
Expand All @@ -221,7 +221,7 @@ func (rf *remoteExecutionFetcher) FetchDirectory(ctx context.Context, req *remot
return nil, err
}
for _, child := range tree.(*remoteexecution.Tree).Children {
childDigest, err := storage.ProtoToDigest(child)
_, childDigest, err := storage.ProtoSerialise(child)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/push/push_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestPushServerPushBlobSuccess(t *testing.T) {
BlobDigest: blobDigest,
Qualifiers: qualifiers,
}
refDigest, err := storage.AssetReferenceToDigest(storage.NewAssetReference([]string{uri}, qualifiers), instanceName)
refDigest, err := storage.ProtoToDigest(storage.NewAssetReference([]string{uri}, qualifiers), instanceName)
require.NoError(t, err)

backend := mock.NewMockBlobAccess(ctrl)
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestPushServerPushDirectorySuccess(t *testing.T) {
RootDirectoryDigest: rootDirectoryDigest,
Qualifiers: qualifiers,
}
refDigest, err := storage.AssetReferenceToDigest(storage.NewAssetReference([]string{uri}, qualifiers), instanceName)
refDigest, err := storage.ProtoToDigest(storage.NewAssetReference([]string{uri}, qualifiers), instanceName)
require.NoError(t, err)

backend := mock.NewMockBlobAccess(ctrl)
Expand Down
Loading

0 comments on commit 4926e8e

Please sign in to comment.