-
Notifications
You must be signed in to change notification settings - Fork 41
/
utils_test.go
116 lines (100 loc) · 3.47 KB
/
utils_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
/*
Copyright 2022 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 (
"fmt"
"github.com/konflux-ci/integration-service/tekton"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
klog "k8s.io/klog/v2"
)
var _ = Describe("Utils", func() {
var pipelineRun *tektonv1.PipelineRun
BeforeEach(func() {
pipelineRun = &tektonv1.PipelineRun{
ObjectMeta: v1.ObjectMeta{},
Spec: tektonv1.PipelineRunSpec{
Params: []tektonv1.Param{
{
Name: "output-image",
Value: tektonv1.ParamValue{
StringVal: "test-image",
},
},
},
},
Status: tektonv1.PipelineRunStatus{
PipelineRunStatusFields: tektonv1.PipelineRunStatusFields{
Results: []tektonv1.PipelineRunResult{
{
Name: "IMAGE_DIGEST",
Value: *tektonv1.NewStructuredValues("image_digest_value"),
},
{
Name: "IMAGE_URL",
Value: *tektonv1.NewStructuredValues("test-image"),
},
{
Name: "CHAINS-GIT_URL",
Value: *tektonv1.NewStructuredValues("https://github.com/devfile-samples/devfile-sample-java-springboot-basic"),
},
{
Name: "CHAINS-GIT_COMMIT",
Value: *tektonv1.NewStructuredValues("a2ba645d50e471d5f084b"),
},
},
},
},
}
})
It("can get output-image", func() {
image, _ := tekton.GetOutputImage(pipelineRun)
if image != "test-image" {
Fail(fmt.Sprintf("Expected image is test-image, but got %s", image))
}
klog.Infoln("Got expected image")
})
It("can get output-image-digest", func() {
image_digest, _ := tekton.GetOutputImageDigest(pipelineRun)
if image_digest != "image_digest_value" {
Fail(fmt.Sprintf("Expected image_digest is image_digest_value, but got %s", image_digest))
}
klog.Infoln("Got expected git_url")
})
It("can get git-url", func() {
git_url, _ := tekton.GetComponentSourceGitUrl(pipelineRun)
if git_url != "https://github.com/devfile-samples/devfile-sample-java-springboot-basic" {
Fail(fmt.Sprintf("Expected git_url is https://github.com/devfile-samples/devfile-sample-java-springboot-basic, but got %s", git_url))
}
klog.Infoln("Got expected git_url")
})
It("can return err when can't find result for CHAINS-GIT_URL", func() {
pipelineRun.Status.PipelineRunStatusFields.Results = []tektonv1.PipelineRunResult{}
_, err := tekton.GetComponentSourceGitUrl(pipelineRun)
Expect(err).ToNot(BeNil())
})
It("can get git-commit", func() {
commit, _ := tekton.GetComponentSourceGitCommit(pipelineRun)
if commit != "a2ba645d50e471d5f084b" {
Fail(fmt.Sprintf("Expected commit is a2ba645d50e471d5f084b, but got %s", commit))
}
klog.Infoln("Got expected commit")
})
It("can return err when can't find result CHAINS-GIT_COMMIT", func() {
pipelineRun.Status.PipelineRunStatusFields.Results = []tektonv1.PipelineRunResult{}
_, err := tekton.GetComponentSourceGitCommit(pipelineRun)
Expect(err).ToNot(BeNil())
})
})