Skip to content

Commit 9bd534d

Browse files
committed
chore: add more tests
1 parent e35fb2d commit 9bd534d

File tree

2 files changed

+148
-3
lines changed

2 files changed

+148
-3
lines changed

pkg/reconciler/pipelinerun/resources/apply.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ func ApplyTaskResults(targets PipelineRunState, resolvedResultRefs ResolvedResul
246246
pipelineTask.TaskRef.Params = pipelineTask.TaskRef.Params.ReplaceVariables(stringReplacements, arrayReplacements, objectReplacements)
247247
}
248248
pipelineTask.DisplayName = substitution.ApplyReplacements(pipelineTask.DisplayName, stringReplacements)
249-
for _, workspace := range pipelineTask.Workspaces {
250-
workspace.SubPath = substitution.ApplyReplacements(workspace.SubPath, stringReplacements)
249+
for i, workspace := range pipelineTask.Workspaces {
250+
pipelineTask.Workspaces[i].SubPath = substitution.ApplyReplacements(workspace.SubPath, stringReplacements)
251251
}
252252
resolvedPipelineRunTask.PipelineTask = pipelineTask
253253
}

pkg/reconciler/pipelinerun/resources/apply_test.go

+146-1
Original file line numberDiff line numberDiff line change
@@ -3204,7 +3204,33 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) {
32043204
DisplayName: "Result value --> aResultValue",
32053205
},
32063206
}},
3207-
}} {
3207+
},
3208+
{
3209+
name: "Test result substitution on embedded variable substitution expression - workspace.subPath",
3210+
resolvedResultRefs: resources.ResolvedResultRefs{{
3211+
Value: *v1.NewStructuredValues("aResultValue"),
3212+
ResultReference: v1.ResultRef{
3213+
PipelineTask: "aTask",
3214+
Result: "aResult",
3215+
},
3216+
FromTaskRun: "aTaskRun",
3217+
}},
3218+
targets: resources.PipelineRunState{{
3219+
PipelineTask: &v1.PipelineTask{
3220+
Name: "bTask",
3221+
TaskRef: &v1.TaskRef{Name: "bTask"},
3222+
Workspaces: []v1.WorkspacePipelineTaskBinding{{Name: "ws-1", Workspace: "ws-1", SubPath: "$(tasks.aTask.results.aResult)"}},
3223+
},
3224+
}},
3225+
want: resources.PipelineRunState{{
3226+
PipelineTask: &v1.PipelineTask{
3227+
Name: "bTask",
3228+
TaskRef: &v1.TaskRef{Name: "bTask"},
3229+
Workspaces: []v1.WorkspacePipelineTaskBinding{{Name: "ws-1", Workspace: "ws-1", SubPath: "aResultValue"}},
3230+
},
3231+
}},
3232+
},
3233+
} {
32083234
t.Run(tt.name, func(t *testing.T) {
32093235
resources.ApplyTaskResults(tt.targets, tt.resolvedResultRefs)
32103236
if d := cmp.Diff(tt.want, tt.targets); d != "" {
@@ -4967,6 +4993,48 @@ func TestApplyParametersToWorkspaceBindings(t *testing.T) {
49674993
},
49684994
},
49694995
},
4996+
{
4997+
name: "pvc object params",
4998+
ps: &v1.PipelineSpec{
4999+
Params: []v1.ParamSpec{
5000+
{Name: "pvc-object", Type: v1.ParamTypeObject, Properties: map[string]v1.PropertySpec{
5001+
"name": {Type: v1.ParamTypeString},
5002+
}},
5003+
},
5004+
},
5005+
pr: &v1.PipelineRun{
5006+
Spec: v1.PipelineRunSpec{
5007+
Params: []v1.Param{
5008+
{Name: "pvc-object", Value: v1.ParamValue{Type: v1.ParamTypeObject, ObjectVal: map[string]string{
5009+
"name": "pvc-object-value",
5010+
}}},
5011+
},
5012+
Workspaces: []v1.WorkspaceBinding{
5013+
{
5014+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
5015+
ClaimName: "$(params.pvc-object.name)",
5016+
},
5017+
},
5018+
},
5019+
},
5020+
},
5021+
expectedPr: &v1.PipelineRun{
5022+
Spec: v1.PipelineRunSpec{
5023+
Params: []v1.Param{
5024+
{Name: "pvc-object", Value: v1.ParamValue{Type: v1.ParamTypeObject, ObjectVal: map[string]string{
5025+
"name": "pvc-object-value",
5026+
}}},
5027+
},
5028+
Workspaces: []v1.WorkspaceBinding{
5029+
{
5030+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
5031+
ClaimName: "pvc-object-value",
5032+
},
5033+
},
5034+
},
5035+
},
5036+
},
5037+
},
49705038
}
49715039

49725040
for _, tt := range testCases {
@@ -5219,6 +5287,83 @@ func TestApplyResultsToWorkspaceBindings(t *testing.T) {
52195287
},
52205288
},
52215289
},
5290+
{
5291+
name: "pvc object-result",
5292+
trResults: map[string][]v1.TaskRunResult{
5293+
"task1": {
5294+
{
5295+
Name: "pvc-object",
5296+
Type: v1.ResultsTypeObject,
5297+
Value: v1.ResultValue{Type: v1.ParamTypeObject, ObjectVal: map[string]string{
5298+
"name": "pvc-object-value",
5299+
}},
5300+
},
5301+
},
5302+
},
5303+
pr: &v1.PipelineRun{
5304+
Spec: v1.PipelineRunSpec{
5305+
Workspaces: []v1.WorkspaceBinding{
5306+
{
5307+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
5308+
ClaimName: "$(tasks.task1.results.pvc-object.name)",
5309+
},
5310+
},
5311+
},
5312+
},
5313+
},
5314+
expectedPr: &v1.PipelineRun{
5315+
Spec: v1.PipelineRunSpec{
5316+
Workspaces: []v1.WorkspaceBinding{
5317+
{
5318+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
5319+
ClaimName: "pvc-object-value",
5320+
},
5321+
},
5322+
},
5323+
},
5324+
},
5325+
},
5326+
{
5327+
name: "pvc object-result - along with array-result (no effect)",
5328+
trResults: map[string][]v1.TaskRunResult{
5329+
"task1": {
5330+
{
5331+
Name: "pvc-object",
5332+
Type: v1.ResultsTypeObject,
5333+
Value: v1.ResultValue{Type: v1.ParamTypeObject, ObjectVal: map[string]string{
5334+
"name": "pvc-object-value",
5335+
}},
5336+
},
5337+
{
5338+
Name: "pvc-array",
5339+
Type: v1.ResultsTypeArray,
5340+
Value: v1.ResultValue{Type: v1.ParamTypeArray, ArrayVal: []string{"name-1", "name-2"}},
5341+
},
5342+
},
5343+
},
5344+
pr: &v1.PipelineRun{
5345+
Spec: v1.PipelineRunSpec{
5346+
Workspaces: []v1.WorkspaceBinding{
5347+
{
5348+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
5349+
ClaimName: "$(tasks.task1.results.pvc-object.name)",
5350+
},
5351+
},
5352+
},
5353+
},
5354+
},
5355+
expectedPr: &v1.PipelineRun{
5356+
Spec: v1.PipelineRunSpec{
5357+
Workspaces: []v1.WorkspaceBinding{
5358+
{
5359+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
5360+
ClaimName: "pvc-object-value",
5361+
},
5362+
},
5363+
},
5364+
},
5365+
},
5366+
},
52225367
}
52235368

52245369
for _, tc := range testCases {

0 commit comments

Comments
 (0)