github.com/redhat-appstudio/release-service@v0.0.0-20240507045911-a8558ef3422a/tekton/utils/pipeline_test.go (about)

     1  /*
     2  Copyright 2023.
     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 utils
    18  
    19  import (
    20  	. "github.com/onsi/ginkgo/v2"
    21  	. "github.com/onsi/gomega"
    22  )
    23  
    24  var _ = Describe("Pipeline", func() {
    25  	var (
    26  		clusterRef PipelineRef
    27  		gitRef     PipelineRef
    28  		bundleRef  PipelineRef
    29  	)
    30  
    31  	BeforeEach(func() {
    32  		clusterRef = PipelineRef{
    33  			Resolver: "cluster",
    34  			Params: []Param{
    35  				{Name: "kind", Value: "pipeline"},
    36  				{Name: "name", Value: "my-cluster-pipeline"},
    37  				{Name: "namespace", Value: "my-namespace"},
    38  			},
    39  		}
    40  		gitRef = PipelineRef{
    41  			Resolver: "git",
    42  			Params: []Param{
    43  				{Name: "url", Value: "my-git-url"},
    44  				{Name: "revision", Value: "my-revision"},
    45  				{Name: "pathInRepo", Value: "my-path-in-repo"},
    46  			},
    47  		}
    48  		bundleRef = PipelineRef{
    49  			Resolver: "bundles",
    50  			Params: []Param{
    51  				{Name: "bundle", Value: "my-bundle"},
    52  				{Name: "name", Value: "my-pipeline"},
    53  				{Name: "kind", Value: "pipeline"},
    54  			},
    55  		}
    56  	})
    57  
    58  	When("ToTektonPipelineRef method is called", func() {
    59  		It("should return Tekton PipelineRef representation of the PipelineRef", func() {
    60  			ref := clusterRef.ToTektonPipelineRef()
    61  			Expect(string(ref.ResolverRef.Resolver)).To(Equal("cluster"))
    62  			params := ref.ResolverRef.Params
    63  			Expect(params[0].Name).To(Equal("kind"))
    64  			Expect(params[0].Value.StringVal).To(Equal("pipeline"))
    65  			Expect(params[1].Name).To(Equal("name"))
    66  			Expect(params[1].Value.StringVal).To(Equal("my-cluster-pipeline"))
    67  			Expect(params[2].Name).To(Equal("namespace"))
    68  			Expect(params[2].Value.StringVal).To(Equal("my-namespace"))
    69  
    70  			ref = gitRef.ToTektonPipelineRef()
    71  			Expect(string(ref.ResolverRef.Resolver)).To(Equal("git"))
    72  			params = ref.ResolverRef.Params
    73  			Expect(params[0].Name).To(Equal("url"))
    74  			Expect(params[0].Value.StringVal).To(Equal("my-git-url"))
    75  			Expect(params[1].Name).To(Equal("revision"))
    76  			Expect(params[1].Value.StringVal).To(Equal("my-revision"))
    77  			Expect(params[2].Name).To(Equal("pathInRepo"))
    78  			Expect(params[2].Value.StringVal).To(Equal("my-path-in-repo"))
    79  
    80  			ref = bundleRef.ToTektonPipelineRef()
    81  			Expect(string(ref.ResolverRef.Resolver)).To(Equal("bundles"))
    82  			params = ref.ResolverRef.Params
    83  			Expect(params[0].Name).To(Equal("bundle"))
    84  			Expect(params[0].Value.StringVal).To(Equal("my-bundle"))
    85  			Expect(params[1].Name).To(Equal("name"))
    86  			Expect(params[1].Value.StringVal).To(Equal("my-pipeline"))
    87  			Expect(params[2].Name).To(Equal("kind"))
    88  			Expect(params[2].Value.StringVal).To(Equal("pipeline"))
    89  		})
    90  	})
    91  
    92  	When("IsClusterScoped method is called", func() {
    93  		It("should return true for a cluster pipeline", func() {
    94  			Expect(clusterRef.IsClusterScoped()).To(BeTrue())
    95  		})
    96  
    97  		It("should return false for non-cluster pipelines", func() {
    98  			Expect(gitRef.IsClusterScoped()).To(BeFalse())
    99  			Expect(bundleRef.IsClusterScoped()).To(BeFalse())
   100  		})
   101  	})
   102  
   103  })