github.com/paketo-buildpacks/packit@v1.3.2-0.20211206231111-86b75c657449/paketosbom/sbom_test.go (about)

     1  package paketosbom_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/sclevine/spec"
     7  
     8  	. "github.com/onsi/gomega"
     9  
    10  	//nolint Ignore SA1019, usage of deprecated package within a deprecated test case
    11  	"github.com/paketo-buildpacks/packit/paketosbom"
    12  )
    13  
    14  func testPaketoSBOM(t *testing.T, context spec.G, it spec.S) {
    15  	var (
    16  		Expect = NewWithT(t).Expect
    17  	)
    18  
    19  	context("GetBOMChecksumAlgorithm", func() {
    20  		context("given an algorithm string with the exact name of a CycloneDX algorithm", func() {
    21  			it("returns the same algorithm name", func() {
    22  				algorithm512, err := paketosbom.GetBOMChecksumAlgorithm("SHA-512")
    23  				Expect(err).ToNot(HaveOccurred())
    24  				Expect(algorithm512).To(Equal(paketosbom.SHA512))
    25  			})
    26  		})
    27  		context("given an algorithm string with a lowercase version of a CycloneDX algorithm", func() {
    28  			it("returns the Cyclonedx algorithm name", func() {
    29  				algorithm512, err := paketosbom.GetBOMChecksumAlgorithm("sha-512")
    30  				Expect(err).ToNot(HaveOccurred())
    31  				Expect(algorithm512).To(Equal(paketosbom.SHA512))
    32  			})
    33  			context("it also does not contain a dash", func() {
    34  				it("returns the Cyclonedx algorithm name", func() {
    35  					algorithm512, err := paketosbom.GetBOMChecksumAlgorithm("sha512")
    36  					Expect(err).ToNot(HaveOccurred())
    37  					Expect(algorithm512).To(Equal(paketosbom.SHA512))
    38  				})
    39  			})
    40  		})
    41  		context("failure cases", func() {
    42  			context("when the attempted BOM checksum algorithm is not supported", func() {
    43  				it("persists a build.toml", func() {
    44  					_, err := paketosbom.GetBOMChecksumAlgorithm("RANDOM-ALG")
    45  					Expect(err).To(MatchError("failed to get supported BOM checksum algorithm: RANDOM-ALG is not valid"))
    46  				})
    47  			})
    48  		})
    49  	})
    50  }