github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/pluginaction/checksum_test.go (about)

     1  package pluginaction_test
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  
     7  	. "code.cloudfoundry.org/cli/actor/pluginaction"
     8  	"code.cloudfoundry.org/cli/actor/pluginaction/pluginactionfakes"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("Checksums", func() {
    14  	var (
    15  		actor      *Actor
    16  		fakeConfig *pluginactionfakes.FakeConfig
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		fakeConfig = new(pluginactionfakes.FakeConfig)
    21  		actor = NewActor(fakeConfig, nil)
    22  	})
    23  
    24  	Describe("ValidateFileChecksum", func() {
    25  		var file *os.File
    26  		BeforeEach(func() {
    27  			var err error
    28  			file, err = ioutil.TempFile("", "")
    29  			Expect(err).NotTo(HaveOccurred())
    30  			defer file.Close()
    31  
    32  			err = ioutil.WriteFile(file.Name(), []byte("foo"), 0600)
    33  			Expect(err).NotTo(HaveOccurred())
    34  		})
    35  
    36  		AfterEach(func() {
    37  			err := os.Remove(file.Name())
    38  			Expect(err).NotTo(HaveOccurred())
    39  		})
    40  
    41  		When("the checksums match", func() {
    42  			It("returns true", func() {
    43  				Expect(actor.ValidateFileChecksum(file.Name(), "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")).To(BeTrue())
    44  			})
    45  		})
    46  
    47  		When("the checksums do not match", func() {
    48  			It("returns false", func() {
    49  				Expect(actor.ValidateFileChecksum(file.Name(), "blah")).To(BeFalse())
    50  			})
    51  		})
    52  	})
    53  })