github.com/benchkram/bob@v0.0.0-20240314204020-b7a57f2f9be9/test/integration/task/hash_test.go (about)

     1  package tasktest
     2  
     3  import (
     4  	"github.com/benchkram/bob/bobtask"
     5  
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  var _ = Describe("Test task-related functionality", func() {
    11  	Context("in a fresh environment", func() {
    12  
    13  		It("should produce the same hash for two tasks with the same exported structure", func() {
    14  			t1 := bobtask.Make()
    15  			t1h, err := t1.HashIn()
    16  			Expect(err).NotTo(HaveOccurred())
    17  
    18  			t2 := bobtask.Make()
    19  			t2h, err := t2.HashIn()
    20  			Expect(err).NotTo(HaveOccurred())
    21  
    22  			Expect(t1h).To(Equal(t2h))
    23  		})
    24  
    25  		It("should produce the same hash for two tasks with same environment", func() {
    26  			t1 := bobtask.Make(bobtask.WithEnvironment([]string{
    27  				"PATH=/usr/bin",
    28  			}))
    29  			t1h, err := t1.HashIn()
    30  			Expect(err).NotTo(HaveOccurred())
    31  
    32  			t2 := bobtask.Make(bobtask.WithEnvironment([]string{
    33  				"PATH=/usr/bin",
    34  			}))
    35  			t2h, err := t2.HashIn()
    36  			Expect(err).NotTo(HaveOccurred())
    37  			Expect(t1h).To(Equal(t2h))
    38  
    39  		})
    40  
    41  		It("should produce different hashes for two tasks with a different environments", func() {
    42  			t1 := bobtask.Make(bobtask.WithEnvironment([]string{
    43  				"PATH=/usr/bin",
    44  			}))
    45  			t1h, err := t1.HashIn()
    46  			Expect(err).NotTo(HaveOccurred())
    47  
    48  			t2 := bobtask.Make(bobtask.WithEnvironment([]string{
    49  				"PATH=/usr/etc",
    50  			}))
    51  			t2h, err := t2.HashIn()
    52  			Expect(err).NotTo(HaveOccurred())
    53  
    54  			Expect(t1h).NotTo(Equal(t2h))
    55  		})
    56  
    57  	})
    58  })