Skip to content

Commit a221b6c

Browse files
perf(crafter): avoid redundant SHA256 pass on every CAS upload (#3142)
Signed-off-by: Matías Insaurralde <matias@chainloop.dev>
1 parent c81540b commit a221b6c

26 files changed

Lines changed: 76 additions & 49 deletions

pkg/attestation/crafter/crafter_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023-2025 The Chainloop Authors.
2+
// Copyright 2023-2026 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -40,6 +40,7 @@ import (
4040
"github.com/go-git/go-git/v6/config"
4141
"github.com/go-git/go-git/v6/plumbing/object"
4242
"github.com/stretchr/testify/assert"
43+
"github.com/stretchr/testify/mock"
4344
"github.com/stretchr/testify/require"
4445
"github.com/stretchr/testify/suite"
4546
"google.golang.org/protobuf/encoding/protojson"
@@ -609,7 +610,7 @@ func (s *crafterSuite) TestAddMaterialsAutomatic() {
609610
uploader := mUploader.NewUploader(s.T())
610611

611612
if !tc.uploadArtifact {
612-
uploader.On("UploadFile", context.Background(), tc.materialPath).
613+
uploader.On("Upload", context.Background(), mock.Anything, mock.Anything, mock.Anything).
613614
Return(&casclient.UpDownStatus{
614615
Digest: "deadbeef",
615616
Filename: "simple.txt",

pkg/attestation/crafter/materials/artifact_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
mUploader "github.com/chainloop-dev/chainloop/pkg/casclient/mocks"
2929
"github.com/rs/zerolog"
3030
"github.com/stretchr/testify/assert"
31+
"github.com/stretchr/testify/mock"
3132
"github.com/stretchr/testify/require"
3233
)
3334

@@ -76,7 +77,7 @@ func TestArtifactCraft(t *testing.T) {
7677

7778
// Mock uploader
7879
uploader := mUploader.NewUploader(t)
79-
uploader.On("UploadFile", context.TODO(), "./testdata/simple.txt").
80+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
8081
Return(&casclient.UpDownStatus{
8182
Digest: "deadbeef",
8283
Filename: "simple.txt",

pkg/attestation/crafter/materials/asyncapi_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
mUploader "github.com/chainloop-dev/chainloop/pkg/casclient/mocks"
2828
"github.com/rs/zerolog"
2929
"github.com/stretchr/testify/assert"
30+
"github.com/stretchr/testify/mock"
3031
"github.com/stretchr/testify/require"
3132
)
3233

@@ -143,7 +144,7 @@ func TestAsyncAPICraft(t *testing.T) {
143144
t.Run(tc.name, func(t *testing.T) {
144145
uploader := mUploader.NewUploader(t)
145146
if tc.wantErr == "" {
146-
uploader.On("UploadFile", context.TODO(), tc.filePath).
147+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
147148
Return(&casclient.UpDownStatus{
148149
Digest: "deadbeef",
149150
Filename: "spec.json",
@@ -178,7 +179,7 @@ func TestAsyncAPICraft(t *testing.T) {
178179
func TestAsyncAPICraftNoStrictValidation(t *testing.T) {
179180
l := zerolog.Nop()
180181
uploader := mUploader.NewUploader(t)
181-
uploader.On("UploadFile", context.TODO(), "./testdata/asyncapi-invalid.json").
182+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
182183
Return(&casclient.UpDownStatus{
183184
Digest: "deadbeef",
184185
Filename: "spec.json",

pkg/attestation/crafter/materials/attestation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2024-2025 The Chainloop Authors.
2+
// Copyright 2024-2026 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -136,7 +136,7 @@ func TestAttestationCraft(t *testing.T) {
136136
// Mock uploader
137137
uploader := mUploader.NewUploader(t)
138138
if !tc.expectErr {
139-
uploader.On("UploadFile", context.Background(), mock.Anything).
139+
uploader.On("Upload", context.Background(), mock.Anything, mock.Anything, mock.Anything).
140140
Return(&casclient.UpDownStatus{
141141
Digest: "deadbeef",
142142
Filename: "attestation.json",

pkg/attestation/crafter/materials/blackduck_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2024-2025 The Chainloop Authors.
2+
// Copyright 2024-2026 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import (
2626
mUploader "github.com/chainloop-dev/chainloop/pkg/casclient/mocks"
2727
"github.com/rs/zerolog"
2828
"github.com/stretchr/testify/assert"
29+
"github.com/stretchr/testify/mock"
2930
"github.com/stretchr/testify/require"
3031
)
3132

@@ -77,7 +78,7 @@ func TestBlackduckJSONCraft(t *testing.T) {
7778
// Mock uploader
7879
uploader := mUploader.NewUploader(t)
7980
if tc.wantErr == "" {
80-
uploader.On("UploadFile", context.TODO(), tc.filePath).
81+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
8182
Return(&casclient.UpDownStatus{}, nil)
8283
}
8384

pkg/attestation/crafter/materials/chainloop_ai_agent_config_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
mUploader "github.com/chainloop-dev/chainloop/pkg/casclient/mocks"
3030
"github.com/rs/zerolog"
3131
"github.com/stretchr/testify/assert"
32+
"github.com/stretchr/testify/mock"
3233
"github.com/stretchr/testify/require"
3334
)
3435

@@ -288,7 +289,7 @@ func TestChainloopAIAgentConfigCrafter_AgentNameAnnotation(t *testing.T) {
288289
}
289290

290291
uploader := mUploader.NewUploader(t)
291-
uploader.On("UploadFile", context.TODO(), tc.filePath).
292+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
292293
Return(&casclient.UpDownStatus{
293294
Digest: "deadbeef",
294295
Filename: tc.filePath,

pkg/attestation/crafter/materials/chainloop_ai_coding_session_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
mUploader "github.com/chainloop-dev/chainloop/pkg/casclient/mocks"
3030
"github.com/rs/zerolog"
3131
"github.com/stretchr/testify/assert"
32+
"github.com/stretchr/testify/mock"
3233
"github.com/stretchr/testify/require"
3334
)
3435

@@ -327,7 +328,7 @@ func TestChainloopAICodingSessionCrafter_Annotations(t *testing.T) {
327328
}
328329

329330
uploader := mUploader.NewUploader(t)
330-
uploader.On("UploadFile", context.TODO(), tc.filePath).
331+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
331332
Return(&casclient.UpDownStatus{
332333
Digest: "deadbeef",
333334
Filename: tc.filePath,

pkg/attestation/crafter/materials/csaf_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
mUploader "github.com/chainloop-dev/chainloop/pkg/casclient/mocks"
2929
"github.com/rs/zerolog"
3030
"github.com/stretchr/testify/assert"
31+
"github.com/stretchr/testify/mock"
3132
"github.com/stretchr/testify/require"
3233
)
3334

@@ -220,7 +221,7 @@ func TestCSAFCraft(t *testing.T) {
220221
// Mock uploader
221222
uploader := mUploader.NewUploader(t)
222223
if tc.wantErr == "" {
223-
uploader.On("UploadFile", context.TODO(), tc.filePath).
224+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
224225
Return(&casclient.UpDownStatus{
225226
Digest: "deadbeef",
226227
Filename: "vex.json",

pkg/attestation/crafter/materials/cyclonedxjson_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
mUploader "github.com/chainloop-dev/chainloop/pkg/casclient/mocks"
2727
"github.com/rs/zerolog"
2828
"github.com/stretchr/testify/assert"
29+
"github.com/stretchr/testify/mock"
2930
"github.com/stretchr/testify/require"
3031
)
3132

@@ -212,7 +213,7 @@ func TestCyclonedxJSONCraft(t *testing.T) {
212213
// Mock uploader
213214
uploader := mUploader.NewUploader(t)
214215
if tc.wantErr == "" {
215-
uploader.On("UploadFile", context.TODO(), tc.filePath).
216+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
216217
Return(&casclient.UpDownStatus{}, nil)
217218
}
218219

@@ -304,7 +305,7 @@ func TestCycloneDXJSONCraftNoStrictValidation(t *testing.T) {
304305
// Mock uploader
305306
uploader := mUploader.NewUploader(t)
306307
if tc.wantErr == "" {
307-
uploader.On("UploadFile", context.TODO(), tc.filePath).
308+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
308309
Return(&casclient.UpDownStatus{}, nil)
309310
}
310311

@@ -358,7 +359,7 @@ func TestCycloneDXJSONCraft_SkipUpload(t *testing.T) {
358359
// Mock uploader - only expect upload call if not skipped
359360
uploader := mUploader.NewUploader(t)
360361
if tc.wantUpload {
361-
uploader.On("UploadFile", context.TODO(), filePath).
362+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
362363
Return(&casclient.UpDownStatus{
363364
Digest: "deadbeef",
364365
Filename: "sbom.cyclonedx.json",

pkg/attestation/crafter/materials/evidence_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
mUploader "github.com/chainloop-dev/chainloop/pkg/casclient/mocks"
2929
"github.com/rs/zerolog"
3030
"github.com/stretchr/testify/assert"
31+
"github.com/stretchr/testify/mock"
3132
"github.com/stretchr/testify/require"
3233
)
3334

@@ -76,7 +77,7 @@ func TestEvidenceCraft(t *testing.T) {
7677

7778
// Mock uploader
7879
uploader := mUploader.NewUploader(t)
79-
uploader.On("UploadFile", context.TODO(), "./testdata/simple.txt").
80+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
8081
Return(&casclient.UpDownStatus{
8182
Digest: "deadbeef",
8283
Filename: "simple.txt",
@@ -213,7 +214,7 @@ func TestEvidenceCraftWithJSONAnnotations(t *testing.T) {
213214

214215
// Create a new mock uploader for each test case
215216
uploader := mUploader.NewUploader(t)
216-
uploader.On("UploadFile", context.TODO(), tc.filePath).
217+
uploader.On("Upload", context.TODO(), mock.Anything, mock.Anything, mock.Anything).
217218
Return(&casclient.UpDownStatus{
218219
Digest: "deadbeef",
219220
Filename: tc.filePath,

0 commit comments

Comments
 (0)