github.com/benchkram/bob@v0.0.0-20240314204020-b7a57f2f9be9/test/e2e/task-decoration/decoration_test.go (about)

     1  package taskdecorationtest
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo"
     5  	. "github.com/onsi/gomega"
     6  )
     7  
     8  var _ = Describe("Testing decoration of imported tasks", func() {
     9  	When("a task from second level gets decorated", func() {
    10  		It("will update that task with correct dependsOn", func() {
    11  			useBobfile("with_decoration")
    12  			defer releaseBobfile("with_decoration")
    13  
    14  			useSecondLevelBobfile("with_decoration")
    15  			defer releaseSecondLevelBobfile("with_decoration")
    16  
    17  			b, err := BobSetup()
    18  			Expect(err).NotTo(HaveOccurred())
    19  
    20  			ag, err := b.Aggregate()
    21  			Expect(err).NotTo(HaveOccurred())
    22  
    23  			Expect(len(ag.BTasks)).To(Equal(3))
    24  
    25  			decoratedTask, ok := ag.BTasks["second/build"]
    26  			Expect(ok).To(BeTrue())
    27  			Expect(decoratedTask.DependsOn).To(Equal([]string{"before", "second/hello"}))
    28  		})
    29  	})
    30  
    31  	When("a task from second and third level get decorated", func() {
    32  		It("will update decorated task with correct dependsOn", func() {
    33  			useBobfile("with_thirdlevel_decoration")
    34  			defer releaseBobfile("with_thirdlevel_decoration")
    35  
    36  			useSecondLevelBobfile("with_thirdlevel_decoration")
    37  			defer releaseSecondLevelBobfile("with_thirdlevel_decoration")
    38  
    39  			useThirdLevelBobfile("with_thirdlevel_decoration")
    40  			defer releaseThirdLevelBobfile("with_thirdlevel_decoration")
    41  
    42  			b, err := BobSetup()
    43  			Expect(err).NotTo(HaveOccurred())
    44  
    45  			ag, err := b.Aggregate()
    46  			Expect(err).NotTo(HaveOccurred())
    47  
    48  			Expect(len(ag.BTasks)).To(Equal(6))
    49  
    50  			decoratedTaskSecond, ok := ag.BTasks["second/build"]
    51  			Expect(ok).To(BeTrue())
    52  			Expect(decoratedTaskSecond.DependsOn).To(Equal([]string{"before", "second/create"}))
    53  
    54  			decoratedTaskThird, ok := ag.BTasks["second/third/build"]
    55  			Expect(ok).To(BeTrue())
    56  			Expect(decoratedTaskThird.DependsOn).To(Equal([]string{"second/hello", "second/third/hello"}))
    57  		})
    58  	})
    59  
    60  	When("attempting to decorate a missing child task", func() {
    61  		It("should fail with task does not exist error", func() {
    62  			useBobfile("with_missed_decoration")
    63  			defer releaseBobfile("with_missed_decoration")
    64  
    65  			b, err := BobSetup()
    66  			Expect(err).NotTo(HaveOccurred())
    67  
    68  			_, err = b.Aggregate()
    69  			Expect(err).Should(HaveOccurred())
    70  			Expect(err.Error()).To(Equal("you are modifying an imported task `second/build` that does not exist"))
    71  		})
    72  	})
    73  
    74  	When("a decorated task contain more than dependsOn node", func() {
    75  		It("should fail because with an error", func() {
    76  			useBobfile("with_invalid_decoration")
    77  			defer releaseBobfile("with_invalid_decoration")
    78  
    79  			useSecondLevelBobfile("with_invalid_decoration")
    80  			defer releaseSecondLevelBobfile("with_invalid_decoration")
    81  
    82  			b, err := BobSetup()
    83  			Expect(err).NotTo(HaveOccurred())
    84  
    85  			_, err = b.Aggregate()
    86  			Expect(err).Should(HaveOccurred())
    87  			Expect(err.Error()).To(Equal("task `second/build` modifies an imported task. It can only contain a `dependsOn` property"))
    88  		})
    89  	})
    90  })