github.com/redhat-appstudio/release-service@v0.0.0-20240507045911-a8558ef3422a/tekton/utils_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  )
    25  
    26  var _ = Describe("Utils", Ordered, func() {
    27  	When("isReleasePipelineRun is called", func() {
    28  		It("should return false when the PipelineRun is not of type 'managed'", func() {
    29  			pipelineRun, err := utils.NewPipelineRunBuilder("pipeline-run", "default").Build()
    30  			Expect(err).NotTo(HaveOccurred())
    31  			Expect(isReleasePipelineRun(pipelineRun)).To(BeFalse())
    32  		})
    33  
    34  		It("should return true when the PipelineRun is of type 'managed'", func() {
    35  			pipelineRun, err := utils.NewPipelineRunBuilder("pipeline-run", "default").
    36  				WithLabels(map[string]string{metadata.PipelinesTypeLabel: metadata.ManagedPipelineType}).
    37  				Build()
    38  			Expect(err).NotTo(HaveOccurred())
    39  			Expect(isReleasePipelineRun(pipelineRun)).To(BeTrue())
    40  		})
    41  	})
    42  
    43  	When("hasPipelineSucceeded is called", func() {
    44  		It("should return false when the PipelineRun has not succeeded", func() {
    45  			pipelineRun, err := utils.NewPipelineRunBuilder("pipeline-run", "default").Build()
    46  			Expect(err).NotTo(HaveOccurred())
    47  			Expect(hasPipelineSucceeded(pipelineRun)).To(BeFalse())
    48  		})
    49  
    50  		It("should return true when the PipelineRun is of type 'managed'", func() {
    51  			pipelineRun, err := utils.NewPipelineRunBuilder("pipeline-run", "default").Build()
    52  			Expect(err).NotTo(HaveOccurred())
    53  			pipelineRun.Status.MarkSucceeded("", "")
    54  			Expect(hasPipelineSucceeded(pipelineRun)).To(BeTrue())
    55  		})
    56  	})
    57  })