-
Notifications
You must be signed in to change notification settings - Fork 41
/
build_pipeline_test.go
135 lines (121 loc) · 4.64 KB
/
build_pipeline_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
Copyright 2024 Red Hat Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package tekton_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"knative.dev/pkg/apis"
v1 "knative.dev/pkg/apis/duck/v1"
"time"
tekton "github.com/konflux-ci/integration-service/tekton"
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var _ = Describe("build pipeline", func() {
var (
buildPipelineRun *tektonv1.PipelineRun
)
BeforeEach(func() {
buildPipelineRun = &tektonv1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinerun-build-sample",
Namespace: "default",
Labels: map[string]string{
"pipelines.appstudio.openshift.io/type": "build",
"pipelines.openshift.io/used-by": "build-cloud",
"pipelines.openshift.io/runtime": "nodejs",
"pipelines.openshift.io/strategy": "s2i",
"appstudio.openshift.io/component": "component-sample",
"build.appstudio.redhat.com/target_branch": "main",
"pipelinesascode.tekton.dev/pull-request": "1",
"pipelinesascode.tekton.dev/event-type": "pull_request",
},
Annotations: map[string]string{
"appstudio.redhat.com/updateComponentOnSuccess": "false",
"pipelinesascode.tekton.dev/on-target-branch": "[main,master]",
"build.appstudio.openshift.io/repo": "https://github.com/devfile-samples/devfile-sample-go-basic?rev=c713067b0e65fb3de50d1f7c457eb51c2ab0dbb0",
"foo": "bar",
"chains.tekton.dev/signed": "true",
"pipelinesascode.tekton.dev/source-branch": "sourceBranch",
"pipelinesascode.tekton.dev/url-org": "redhat",
},
},
Spec: tektonv1.PipelineRunSpec{
PipelineRef: &tektonv1.PipelineRef{
Name: "build-pipeline-pass",
ResolverRef: tektonv1.ResolverRef{
Resolver: "bundle",
Params: tektonv1.Params{
{Name: "bundle",
Value: tektonv1.ParamValue{Type: "string", StringVal: "quay.io/redhat-appstudio/example-tekton-bundle:test"},
},
{Name: "name",
Value: tektonv1.ParamValue{Type: "string", StringVal: "test-task"},
},
},
},
},
Params: []tektonv1.Param{
{
Name: "output-image",
Value: tektonv1.ParamValue{
Type: tektonv1.ParamTypeString,
StringVal: "quay.io/redhat-appstudio/example-tekton-bundle:test",
},
},
},
},
}
Expect(k8sClient.Create(ctx, buildPipelineRun)).Should(Succeed())
buildPipelineRun.Status = tektonv1.PipelineRunStatus{
PipelineRunStatusFields: tektonv1.PipelineRunStatusFields{
StartTime: &metav1.Time{Time: time.Now()},
},
Status: v1.Status{
Conditions: v1.Conditions{
apis.Condition{
Reason: "Completed",
Status: "True",
Type: apis.ConditionSucceeded,
},
},
},
}
Expect(k8sClient.Status().Update(ctx, buildPipelineRun)).Should(Succeed())
})
AfterEach(func() {
err := k8sClient.Delete(ctx, buildPipelineRun)
Expect(err == nil || k8serrors.IsNotFound(err)).To(BeTrue())
})
Context("When a build pipelineRun exists", func() {
It("can get PR group from build pipelineRun", func() {
Expect(tekton.IsPLRCreatedByPACPushEvent(buildPipelineRun)).To(BeFalse())
prGroup := tekton.GetPRGroupFromBuildPLR(buildPipelineRun)
Expect(prGroup).To(Equal("sourceBranch"))
Expect(tekton.GenerateSHA(prGroup)).NotTo(BeNil())
})
It("can get PR group from build pipelineRun is source branch is main", func() {
buildPipelineRun.Annotations[tekton.PipelineAsCodeSourceBranchAnnotation] = "main"
prGroup := tekton.GetPRGroupFromBuildPLR(buildPipelineRun)
Expect(prGroup).To(Equal("main-redhat"))
Expect(tekton.GenerateSHA(prGroup)).NotTo(BeNil())
})
It("can get PR group from build pipelineRun is source branch has @ charactor", func() {
buildPipelineRun.Annotations[tekton.PipelineAsCodeSourceBranchAnnotation] = "myfeature@change1"
prGroup := tekton.GetPRGroupFromBuildPLR(buildPipelineRun)
Expect(prGroup).To(Equal("myfeature"))
Expect(tekton.GenerateSHA(prGroup)).NotTo(BeNil())
})
})
})