forked from tektoncd/pipeline
/
yaml.go
163 lines (147 loc) · 4.6 KB
/
yaml.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
Copyright 2021 The Tekton Authors
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 parse
import (
"testing"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme"
"k8s.io/apimachinery/pkg/runtime"
)
// MustParseV1alpha1StepAction takes YAML and parses it into a *v1alpha1.StepAction
func MustParseV1alpha1StepAction(t *testing.T, yaml string) *v1alpha1.StepAction {
t.Helper()
var sa v1alpha1.StepAction
yaml = `apiVersion: tekton.dev/v1alpha1
kind: StepAction
` + yaml
mustParseYAML(t, yaml, &sa)
return &sa
}
// MustParseV1beta1TaskRun takes YAML and parses it into a *v1beta1.TaskRun
func MustParseV1beta1TaskRun(t *testing.T, yaml string) *v1beta1.TaskRun {
t.Helper()
var tr v1beta1.TaskRun
yaml = `apiVersion: tekton.dev/v1beta1
kind: TaskRun
` + yaml
mustParseYAML(t, yaml, &tr)
return &tr
}
// MustParseV1TaskRun takes YAML and parses it into a *v1.TaskRun
func MustParseV1TaskRun(t *testing.T, yaml string) *v1.TaskRun {
t.Helper()
var tr v1.TaskRun
yaml = `apiVersion: tekton.dev/v1
kind: TaskRun
` + yaml
mustParseYAML(t, yaml, &tr)
return &tr
}
// MustParseV1beta1Task takes YAML and parses it into a *v1beta1.Task
func MustParseV1beta1Task(t *testing.T, yaml string) *v1beta1.Task {
t.Helper()
var task v1beta1.Task
yaml = `apiVersion: tekton.dev/v1beta1
kind: Task
` + yaml
mustParseYAML(t, yaml, &task)
return &task
}
// MustParseCustomRun takes YAML and parses it into a *v1beta1.CustomRun
func MustParseCustomRun(t *testing.T, yaml string) *v1beta1.CustomRun {
t.Helper()
var r v1beta1.CustomRun
yaml = `apiVersion: tekton.dev/v1beta1
kind: CustomRun
` + yaml
mustParseYAML(t, yaml, &r)
return &r
}
// MustParseV1Task takes YAML and parses it into a *v1.Task
func MustParseV1Task(t *testing.T, yaml string) *v1.Task {
t.Helper()
var task v1.Task
yaml = `apiVersion: tekton.dev/v1
kind: Task
` + yaml
mustParseYAML(t, yaml, &task)
return &task
}
// MustParseClusterTask takes YAML and parses it into a *v1beta1.ClusterTask
func MustParseClusterTask(t *testing.T, yaml string) *v1beta1.ClusterTask {
t.Helper()
var clusterTask v1beta1.ClusterTask
yaml = `apiVersion: tekton.dev/v1beta1
kind: ClusterTask
` + yaml
mustParseYAML(t, yaml, &clusterTask)
return &clusterTask
}
// MustParseV1beta1PipelineRun takes YAML and parses it into a *v1beta1.PipelineRun
func MustParseV1beta1PipelineRun(t *testing.T, yaml string) *v1beta1.PipelineRun {
t.Helper()
var pr v1beta1.PipelineRun
yaml = `apiVersion: tekton.dev/v1beta1
kind: PipelineRun
` + yaml
mustParseYAML(t, yaml, &pr)
return &pr
}
// MustParseV1PipelineRun takes YAML and parses it into a *v1.PipelineRun
func MustParseV1PipelineRun(t *testing.T, yaml string) *v1.PipelineRun {
t.Helper()
var pr v1.PipelineRun
yaml = `apiVersion: tekton.dev/v1
kind: PipelineRun
` + yaml
mustParseYAML(t, yaml, &pr)
return &pr
}
// MustParseV1beta1Pipeline takes YAML and parses it into a *v1beta1.Pipeline
func MustParseV1beta1Pipeline(t *testing.T, yaml string) *v1beta1.Pipeline {
t.Helper()
var pipeline v1beta1.Pipeline
yaml = `apiVersion: tekton.dev/v1beta1
kind: Pipeline
` + yaml
mustParseYAML(t, yaml, &pipeline)
return &pipeline
}
// MustParseV1Pipeline takes YAML and parses it into a *v1.Pipeline
func MustParseV1Pipeline(t *testing.T, yaml string) *v1.Pipeline {
t.Helper()
var pipeline v1.Pipeline
yaml = `apiVersion: tekton.dev/v1
kind: Pipeline
` + yaml
mustParseYAML(t, yaml, &pipeline)
return &pipeline
}
// MustParseVerificationPolicy takes YAML and parses it into a *v1alpha1.VerificationPolicy
func MustParseVerificationPolicy(t *testing.T, yaml string) *v1alpha1.VerificationPolicy {
t.Helper()
var v v1alpha1.VerificationPolicy
yaml = `apiVersion: tekton.dev/v1alpha1
kind: VerificationPolicy
` + yaml
mustParseYAML(t, yaml, &v)
return &v
}
func mustParseYAML(t *testing.T, yaml string, i runtime.Object) {
t.Helper()
if _, _, err := scheme.Codecs.UniversalDeserializer().Decode([]byte(yaml), nil, i); err != nil {
t.Fatalf("mustParseYAML (%s): %v", yaml, err)
}
}