@@ -19,7 +19,9 @@ package builder
19
19
import (
20
20
"errors"
21
21
"fmt"
22
+ "os"
22
23
"path/filepath"
24
+ "regexp"
23
25
"runtime"
24
26
"strings"
25
27
"testing"
@@ -851,8 +853,9 @@ RUN curl -I http://google.com
851
853
func TestBuildAttestation (t * testing.T ) {
852
854
nerdtest .Setup ()
853
855
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`
856
859
857
860
dockerfile := fmt .Sprintf (`FROM %s` , testutil .CommonImage )
858
861
@@ -892,7 +895,17 @@ func TestBuildAttestation(t *testing.T) {
892
895
Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
893
896
return & test.Expected {
894
897
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 )
896
909
},
897
910
}
898
911
},
@@ -914,7 +927,17 @@ func TestBuildAttestation(t *testing.T) {
914
927
Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
915
928
return & test.Expected {
916
929
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 )
918
941
},
919
942
}
920
943
},
@@ -937,8 +960,28 @@ func TestBuildAttestation(t *testing.T) {
937
960
Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
938
961
return & test.Expected {
939
962
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 )
942
985
},
943
986
}
944
987
},
0 commit comments