@@ -28,12 +28,15 @@ import (
2828 v1 "github.com/chainloop-dev/chainloop/internal/attestation/crafter/api/attestation/v1"
2929 "github.com/chainloop-dev/chainloop/internal/attestation/crafter/runners"
3030 "github.com/chainloop-dev/chainloop/internal/attestation/crafter/statemanager/filesystem"
31+ "github.com/chainloop-dev/chainloop/internal/casclient"
32+ mUploader "github.com/chainloop-dev/chainloop/internal/casclient/mocks"
33+
3134 "github.com/go-git/go-git/v5"
3235 "github.com/go-git/go-git/v5/plumbing/object"
36+ "github.com/stretchr/testify/assert"
3337 "github.com/stretchr/testify/require"
34- "google.golang.org/protobuf/proto"
35-
3638 "github.com/stretchr/testify/suite"
39+ "google.golang.org/protobuf/proto"
3740)
3841
3942type crafterSuite struct {
@@ -417,3 +420,79 @@ func (s *crafterSuite) SetupTest() {
417420func TestSuite (t * testing.T ) {
418421 suite .Run (t , new (crafterSuite ))
419422}
423+
424+ func (s * crafterSuite ) TestAddMaterialsAutomatic () {
425+ testCases := []struct {
426+ name string
427+ materialPath string
428+ expectedType schemaapi.CraftingSchema_Material_MaterialType
429+ wantErr bool
430+ }{
431+ {
432+ name : "sarif" ,
433+ materialPath : "./materials/testdata/report.sarif" ,
434+ expectedType : schemaapi .CraftingSchema_Material_SARIF ,
435+ },
436+ {
437+ name : "openvex" ,
438+ materialPath : "./materials/testdata/openvex_v0.2.0.json" ,
439+ expectedType : schemaapi .CraftingSchema_Material_OPENVEX ,
440+ },
441+ {
442+ name : "HELM CHART" ,
443+ materialPath : "./materials/testdata/valid-chart.tgz" ,
444+ expectedType : schemaapi .CraftingSchema_Material_HELM_CHART ,
445+ },
446+ {
447+ name : "junit" ,
448+ materialPath : "./materials/testdata/junit.xml" ,
449+ expectedType : schemaapi .CraftingSchema_Material_JUNIT_XML ,
450+ },
451+ {
452+ name : "artifact" ,
453+ materialPath : "./materials/testdata/missing-empty.tgz" ,
454+ expectedType : schemaapi .CraftingSchema_Material_ARTIFACT ,
455+ },
456+ {
457+ name : "artifact - invalid junit" ,
458+ materialPath : "./materials/testdata/junit-invalid.xml" ,
459+ expectedType : schemaapi .CraftingSchema_Material_ARTIFACT ,
460+ },
461+ {
462+ name : "artifact - random file" ,
463+ materialPath : "./materials/testdata/random.json" ,
464+ expectedType : schemaapi .CraftingSchema_Material_ARTIFACT ,
465+ },
466+ {
467+ name : "random string" ,
468+ materialPath : "random-string" ,
469+ expectedType : schemaapi .CraftingSchema_Material_STRING ,
470+ wantErr : true ,
471+ },
472+ }
473+
474+ for _ , tc := range testCases {
475+ s .Run (tc .name , func () {
476+ var runner crafter.SupportedRunner = runners .NewGeneric ()
477+ contract := "testdata/contracts/empty_generic.yaml"
478+ uploader := mUploader .NewUploader (s .T ())
479+
480+ if ! tc .wantErr {
481+ uploader .On ("UploadFile" , context .Background (), tc .materialPath ).
482+ Return (& casclient.UpDownStatus {
483+ Digest : "deadbeef" ,
484+ Filename : "simple.txt" ,
485+ }, nil )
486+ }
487+
488+ backend := & casclient.CASBackend {Uploader : uploader }
489+
490+ c , err := newInitializedCrafter (s .T (), contract , & v1.WorkflowMetadata {}, false , "" , runner )
491+ require .NoError (s .T (), err )
492+
493+ kind , err := c .AddMaterialContactFreeAutomatic (context .Background (), "random-id" , tc .materialPath , backend , nil )
494+ require .NoError (s .T (), err )
495+ assert .Equal (s .T (), tc .expectedType .String (), kind .String ())
496+ })
497+ }
498+ }
0 commit comments