github.com/redhat-appstudio/release-service@v0.0.0-20240507045911-a8558ef3422a/tekton/predicates_test.go (about) 1 /* 2 Copyright 2022 Red Hat Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package tekton 18 19 import ( 20 . "github.com/onsi/ginkgo/v2" 21 . "github.com/onsi/gomega" 22 "github.com/redhat-appstudio/release-service/metadata" 23 "github.com/redhat-appstudio/release-service/tekton/utils" 24 v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" 25 26 "sigs.k8s.io/controller-runtime/pkg/event" 27 ) 28 29 var _ = Describe("Predicates", Ordered, func() { 30 When("testing ReleasePipelineRunSucceededPredicate predicate", func() { 31 var err error 32 var pipelineRun *v1.PipelineRun 33 34 BeforeAll(func() { 35 pipelineRun, err = utils.NewPipelineRunBuilder("pipeline-run", "default").Build() 36 Expect(err).NotTo(HaveOccurred()) 37 }) 38 39 It("should ignore creating events", func() { 40 contextEvent := event.CreateEvent{ 41 Object: pipelineRun, 42 } 43 Expect(ReleasePipelineRunSucceededPredicate().Create(contextEvent)).To(BeFalse()) 44 }) 45 46 It("should ignore deleting events", func() { 47 contextEvent := event.DeleteEvent{ 48 Object: pipelineRun, 49 } 50 Expect(ReleasePipelineRunSucceededPredicate().Delete(contextEvent)).To(BeFalse()) 51 }) 52 53 It("should ignore generic events", func() { 54 contextEvent := event.GenericEvent{ 55 Object: pipelineRun, 56 } 57 Expect(ReleasePipelineRunSucceededPredicate().Generic(contextEvent)).To(BeFalse()) 58 }) 59 60 It("should return true when an updated event is received for a succeeded managed PipelineRun", func() { 61 var releasePipelineRun *v1.PipelineRun 62 releasePipelineRun, err = utils.NewPipelineRunBuilder("pipeline-run", "default"). 63 WithLabels(map[string]string{metadata.PipelinesTypeLabel: metadata.ManagedPipelineType}). 64 Build() 65 Expect(err).NotTo(HaveOccurred()) 66 contextEvent := event.UpdateEvent{ 67 ObjectOld: pipelineRun, 68 ObjectNew: releasePipelineRun, 69 } 70 releasePipelineRun.Status.MarkRunning("Predicate function tests", "Set it to Unknown") 71 Expect(ReleasePipelineRunSucceededPredicate().Update(contextEvent)).To(BeFalse()) 72 73 releasePipelineRun.Status.MarkSucceeded("Predicate function tests", "Set it to Succeeded") 74 Expect(ReleasePipelineRunSucceededPredicate().Update(contextEvent)).To(BeTrue()) 75 }) 76 }) 77 })