@@ -66,9 +66,12 @@ func TestNewSPDXJSONCrafter(t *testing.T) {
6666
6767func TestSPDXJSONCraft (t * testing.T ) {
6868 testCases := []struct {
69- name string
70- filePath string
71- wantErr string
69+ name string
70+ filePath string
71+ wantErr string
72+ wantDigest string
73+ wantFilename string
74+ annotations map [string ]string
7275 }{
7376 {
7477 name : "invalid sbom format" ,
@@ -86,8 +89,26 @@ func TestSPDXJSONCraft(t *testing.T) {
8689 wantErr : "unexpected material type" ,
8790 },
8891 {
89- name : "valid artifact type" ,
90- filePath : "./testdata/sbom-spdx.json" ,
92+ name : "valid artifact type" ,
93+ filePath : "./testdata/sbom-spdx.json" ,
94+ wantDigest : "sha256:fe2636fb6c698a29a315278b762b2000efd5959afe776ee4f79f1ed523365a33" ,
95+ wantFilename : "sbom-spdx.json" ,
96+ annotations : map [string ]string {
97+ "chainloop.material.tool.name" : "syft" ,
98+ "chainloop.material.tool.version" : "0.73.0" ,
99+ "chainloop.material.tools" : `["syft@0.73.0"]` ,
100+ },
101+ },
102+ {
103+ name : "multiple tools" ,
104+ filePath : "./testdata/sbom-spdx-multiple-tools.json" ,
105+ wantDigest : "sha256:c1a61566c7c0224ac02ad9cd21d90234e5a71de26971e33df2205c1a2eb319fc" ,
106+ wantFilename : "sbom-spdx-multiple-tools.json" ,
107+ annotations : map [string ]string {
108+ "chainloop.material.tool.name" : "spdxgen" ,
109+ "chainloop.material.tool.version" : "1.0.0" ,
110+ "chainloop.material.tools" : `["spdxgen@1.0.0","scanner@2.1.5"]` ,
111+ },
91112 },
92113 }
93114
@@ -123,10 +144,17 @@ func TestSPDXJSONCraft(t *testing.T) {
123144 assert .Equal (contractAPI .CraftingSchema_Material_SBOM_SPDX_JSON .String (), got .MaterialType .String ())
124145 assert .True (got .UploadedToCas )
125146
126- // // The result includes the digest reference
147+ // The result includes the digest reference
127148 assert .Equal (got .GetArtifact (), & attestationApi.Attestation_Material_Artifact {
128- Id : "test" , Digest : "sha256:fe2636fb6c698a29a315278b762b2000efd5959afe776ee4f79f1ed523365a33" , Name : "sbom-spdx.json" ,
149+ Id : "test" , Digest : tc . wantDigest , Name : tc . wantFilename ,
129150 })
151+
152+ // Validate annotations if specified
153+ if tc .annotations != nil {
154+ for k , v := range tc .annotations {
155+ assert .Equal (v , got .Annotations [k ])
156+ }
157+ }
130158 })
131159 }
132160}
0 commit comments