Skip to content

Commit

Permalink
Move to v1alpha2 to v1beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
othomann committed Mar 2, 2020
1 parent f103cf0 commit 392f0c2
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 146 deletions.
129 changes: 65 additions & 64 deletions pkg/apis/pipeline/v1alpha1/param_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/test/builder"
)

Expand Down Expand Up @@ -190,26 +191,26 @@ func TestArrayOrString_MarshalJSON(t *testing.T) {

func TestNewResultReference(t *testing.T) {
type args struct {
param v1alpha2.Param
param v1beta1.Param
}
tests := []struct {
name string
args args
want []*v1alpha2.ResultRef
want []*v1beta1.ResultRef
wantErr bool
}{
{
name: "Test valid expression",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(tasks.sumTask.results.sumResult)",
},
},
},
want: []*v1alpha2.ResultRef{
want: []*v1beta1.ResultRef{
{
PipelineTask: "sumTask",
Result: "sumResult",
Expand All @@ -219,15 +220,15 @@ func TestNewResultReference(t *testing.T) {
}, {
name: "Test valid expression: substitution within string",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "sum-will-go-here -> $(tasks.sumTask.results.sumResult)",
},
},
},
want: []*v1alpha2.ResultRef{
want: []*v1beta1.ResultRef{
{
PipelineTask: "sumTask",
Result: "sumResult",
Expand All @@ -237,15 +238,15 @@ func TestNewResultReference(t *testing.T) {
}, {
name: "Test valid expression: multiple substitution",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(tasks.sumTask1.results.sumResult) and another $(tasks.sumTask2.results.sumResult)",
},
},
},
want: []*v1alpha2.ResultRef{
want: []*v1beta1.ResultRef{
{
PipelineTask: "sumTask1",
Result: "sumResult",
Expand All @@ -258,10 +259,10 @@ func TestNewResultReference(t *testing.T) {
}, {
name: "Test invalid expression: first separator typo",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(task.sumTasks.results.sumResult)",
},
},
Expand All @@ -271,10 +272,10 @@ func TestNewResultReference(t *testing.T) {
}, {
name: "Test invalid expression: third separator typo",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(tasks.sumTasks.result.sumResult)",
},
},
Expand All @@ -284,10 +285,10 @@ func TestNewResultReference(t *testing.T) {
}, {
name: "Test invalid expression: param substitution shouldn't be considered result ref",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(params.paramName)",
},
},
Expand All @@ -297,10 +298,10 @@ func TestNewResultReference(t *testing.T) {
}, {
name: "Test invalid expression: One bad and good result substitution",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "good -> $(tasks.sumTask1.results.sumResult) bad-> $(task.sumTask2.results.sumResult)",
},
},
Expand All @@ -311,7 +312,7 @@ func TestNewResultReference(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1alpha2.NewResultRefs(tt.args.param)
got, err := v1beta1.NewResultRefs(tt.args.param)
if tt.wantErr != (err != nil) {
t.Errorf("TestNewResultReference/%s wantErr %v, error = %v", tt.name, tt.wantErr, err)
return
Expand All @@ -325,25 +326,25 @@ func TestNewResultReference(t *testing.T) {

func TestHasResultReference(t *testing.T) {
type args struct {
param v1alpha2.Param
param v1beta1.Param
}
tests := []struct {
name string
args args
wantRef []*v1alpha2.ResultRef
wantRef []*v1beta1.ResultRef
}{
{
name: "Test valid expression",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(tasks.sumTask.results.sumResult)",
},
},
},
wantRef: []*v1alpha2.ResultRef{
wantRef: []*v1beta1.ResultRef{
{
PipelineTask: "sumTask",
Result: "sumResult",
Expand All @@ -352,15 +353,15 @@ func TestHasResultReference(t *testing.T) {
}, {
name: "Test valid expression with dashes",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(tasks.sum-task.results.sum-result)",
},
},
},
wantRef: []*v1alpha2.ResultRef{
wantRef: []*v1beta1.ResultRef{
{
PipelineTask: "sum-task",
Result: "sum-result",
Expand All @@ -369,10 +370,10 @@ func TestHasResultReference(t *testing.T) {
}, {
name: "Test invalid expression: param substitution shouldn't be considered result ref",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(params.paramName)",
},
},
Expand All @@ -382,7 +383,7 @@ func TestHasResultReference(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, _ := v1alpha2.NewResultRefs(tt.args.param)
got, _ := v1beta1.NewResultRefs(tt.args.param)
if d := cmp.Diff(tt.wantRef, got); d != "" {
t.Errorf("TestHasResultReference/%s (-want, +got) = %v", tt.name, d)
}
Expand All @@ -392,7 +393,7 @@ func TestHasResultReference(t *testing.T) {

func TestLooksLikeResultRef(t *testing.T) {
type args struct {
param v1alpha2.Param
param v1beta1.Param
}
tests := []struct {
name string
Expand All @@ -402,10 +403,10 @@ func TestLooksLikeResultRef(t *testing.T) {
{
name: "test expression that is a result ref",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(tasks.sumTasks.results.sumResult)",
},
},
Expand All @@ -414,10 +415,10 @@ func TestLooksLikeResultRef(t *testing.T) {
}, {
name: "test expression: looks like result ref, but typo in 'task' separator",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(task.sumTasks.results.sumResult)",
},
},
Expand All @@ -426,10 +427,10 @@ func TestLooksLikeResultRef(t *testing.T) {
}, {
name: "test expression: looks like result ref, but typo in 'results' separator",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(tasks.sumTasks.result.sumResult)",
},
},
Expand All @@ -438,10 +439,10 @@ func TestLooksLikeResultRef(t *testing.T) {
}, {
name: "test expression: missing 'task' separator",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(sumTasks.results.sumResult)",
},
},
Expand All @@ -450,10 +451,10 @@ func TestLooksLikeResultRef(t *testing.T) {
}, {
name: "test expression: missing variable substitution",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "tasks.sumTasks.results.sumResult",
},
},
Expand All @@ -462,10 +463,10 @@ func TestLooksLikeResultRef(t *testing.T) {
}, {
name: "test expression: param substitution shouldn't be considered result ref",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(params.someParam)",
},
},
Expand All @@ -474,10 +475,10 @@ func TestLooksLikeResultRef(t *testing.T) {
}, {
name: "test expression: one good ref, one bad one should return true",
args: args{
param: v1alpha2.Param{
param: v1beta1.Param{
Name: "param",
Value: v1alpha2.ArrayOrString{
Type: v1alpha2.ParamTypeString,
Value: v1beta1.ArrayOrString{
Type: v1beta1.ParamTypeString,
StringVal: "$(tasks.sumTasks.results.sumResult) $(task.sumTasks.results.sumResult)",
},
},
Expand All @@ -487,7 +488,7 @@ func TestLooksLikeResultRef(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := v1alpha2.LooksLikeContainsResultRefs(tt.args.param); got != tt.want {
if got := v1beta1.LooksLikeContainsResultRefs(tt.args.param); got != tt.want {
t.Errorf("LooksLikeContainsResultRefs() = %v, want %v", got, tt.want)
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1alpha1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (pt PipelineTask) Deps() []string {
}
// Add any dependents from task results
for _, param := range pt.Params {
if resultRefs, err := v1alpha2.NewResultRefs(param); err == nil {
if resultRefs, err := v1beta1.NewResultRefs(param); err == nil {
for _, resultRef := range resultRefs {
deps = append(deps, resultRef.PipelineTask)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1alpha1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"strings"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha2"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/apis/validate"
"github.com/tektoncd/pipeline/pkg/list"
"github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag"
Expand Down Expand Up @@ -133,8 +133,8 @@ func validateGraph(tasks []PipelineTask) error {
func validateParamResults(tasks []PipelineTask) error {
for _, task := range tasks {
for _, param := range task.Params {
if v1alpha2.LooksLikeContainsResultRefs(param) {
if _, err := v1alpha2.NewResultRefs(param); err != nil {
if v1beta1.LooksLikeContainsResultRefs(param) {
if _, err := v1beta1.NewResultRefs(param); err != nil {
return err
}
}
Expand Down
Loading

0 comments on commit 392f0c2

Please sign in to comment.