@@ -19,7 +19,9 @@ package builder
1919import (
2020 "errors"
2121 "fmt"
22+ "os"
2223 "path/filepath"
24+ "regexp"
2325 "runtime"
2426 "strings"
2527 "testing"
@@ -851,8 +853,9 @@ RUN curl -I http://google.com
851853func TestBuildAttestation (t * testing.T ) {
852854 nerdtest .Setup ()
853855
854- const testSBOMFileName = "sbom.spdx.json"
855- const testProvenanceFileName = "provenance.json"
856+ // Using regex patterns to match SBOM and provenance files with optional platform suffix
857+ const testSBOMFilePattern = `sbom\.spdx(?:\.[a-z0-9_]+)?\.json`
858+ const testProvenanceFilePattern = `provenance(?:\.[a-z0-9_]+)?\.json`
856859
857860 dockerfile := fmt .Sprintf (`FROM %s` , testutil .CommonImage )
858861
@@ -892,7 +895,17 @@ func TestBuildAttestation(t *testing.T) {
892895 Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
893896 return & test.Expected {
894897 Output : func (stdout , info string , t * testing.T ) {
895- data .Temp ().Exists ("dir-for-bom" , testSBOMFileName )
898+ files , err := os .ReadDir (data .Temp ().Path ("dir-for-bom" ))
899+ assert .NilError (t , err , "failed to read directory" )
900+
901+ found := false
902+ for _ , file := range files {
903+ if ! file .IsDir () && regexp .MustCompile (testSBOMFilePattern ).MatchString (file .Name ()) {
904+ found = true
905+ break
906+ }
907+ }
908+ assert .Assert (t , found , "no SBOM file matching pattern %s found" , testSBOMFilePattern )
896909 },
897910 }
898911 },
@@ -914,7 +927,17 @@ func TestBuildAttestation(t *testing.T) {
914927 Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
915928 return & test.Expected {
916929 Output : func (stdout , info string , t * testing.T ) {
917- data .Temp ().Exists ("dir-for-prov" , testProvenanceFileName )
930+ files , err := os .ReadDir (data .Temp ().Path ("dir-for-prov" ))
931+ assert .NilError (t , err , "failed to read directory" )
932+
933+ found := false
934+ for _ , file := range files {
935+ if ! file .IsDir () && regexp .MustCompile (testProvenanceFilePattern ).MatchString (file .Name ()) {
936+ found = true
937+ break
938+ }
939+ }
940+ assert .Assert (t , found , "no provenance file matching pattern %s found" , testProvenanceFilePattern )
918941 },
919942 }
920943 },
@@ -937,8 +960,28 @@ func TestBuildAttestation(t *testing.T) {
937960 Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
938961 return & test.Expected {
939962 Output : func (stdout , info string , t * testing.T ) {
940- data .Temp ().Exists ("dir-for-attest" , testSBOMFileName )
941- data .Temp ().Exists ("dir-for-attest" , testProvenanceFileName )
963+ // Check if any file in the directory matches the SBOM file pattern
964+ files , err := os .ReadDir (data .Temp ().Path ("dir-for-attest" ))
965+ assert .NilError (t , err , "failed to read directory" )
966+
967+ sbomFound := false
968+ for _ , file := range files {
969+ if ! file .IsDir () && regexp .MustCompile (testSBOMFilePattern ).MatchString (file .Name ()) {
970+ sbomFound = true
971+ break
972+ }
973+ }
974+ assert .Assert (t , sbomFound , "no SBOM file matching pattern %s found" , testSBOMFilePattern )
975+
976+ // Check if any file in the directory matches the provenance file pattern
977+ provenanceFound := false
978+ for _ , file := range files {
979+ if ! file .IsDir () && regexp .MustCompile (testProvenanceFilePattern ).MatchString (file .Name ()) {
980+ provenanceFound = true
981+ break
982+ }
983+ }
984+ assert .Assert (t , provenanceFound , "no provenance file matching pattern %s found" , testProvenanceFilePattern )
942985 },
943986 }
944987 },
0 commit comments