diff --git a/pkg/apis/pipeline/v1/matrix_types_test.go b/pkg/apis/pipeline/v1/matrix_types_test.go index c1ca04efd80..26b83f83c25 100644 --- a/pkg/apis/pipeline/v1/matrix_types_test.go +++ b/pkg/apis/pipeline/v1/matrix_types_test.go @@ -11,574 +11,575 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package v1_test import ( "testing" "github.com/google/go-cmp/cmp" + v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/tektoncd/pipeline/test/diff" ) func TestMatrix_FanOut(t *testing.T) { tests := []struct { name string - matrix Matrix - want []Params + matrix v1.Matrix + want []v1.Params }{{ name: "matrix with no params", - matrix: Matrix{ - Params: Params{}, + matrix: v1.Matrix{ + Params: v1.Params{}, }, - want: []Params{}, + want: []v1.Params{}, }, { name: "single array in matrix", - matrix: Matrix{ - Params: Params{{ + matrix: v1.Matrix{ + Params: v1.Params{{ Name: "platform", - Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}}, + Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}}, }}, }, - want: []Params{{ + want: []v1.Params{{ { Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux"}, }, }, { { Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "mac"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "mac"}, }, }, { { Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "windows"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "windows"}, }, }}, }, { name: "multiple arrays in matrix", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1.Matrix{ + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{}}, + Include: v1.IncludeParamsList{{}}, }, - want: []Params{{ + want: []v1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }}, }, { name: "Fan out explicit combinations, no matrix params", - matrix: Matrix{ - Include: IncludeParamsList{{ + matrix: v1.Matrix{ + Include: v1.IncludeParamsList{{ Name: "build-1", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Params: v1.Params{{ + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + Name: "DOCKERFILE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, }, { Name: "build-2", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-2"}, + Params: v1.Params{{ + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-2"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile2"}}}, + Name: "DOCKERFILE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile2"}}}, }, { Name: "build-3", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-3"}, + Params: v1.Params{{ + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-3"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile3"}}}, + Name: "DOCKERFILE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile3"}}}, }}, }, - want: []Params{{ + want: []v1.Params{{ { Name: "DOCKERFILE", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile1"}, }, { Name: "IMAGE", - Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-1"}, }, }, { { Name: "DOCKERFILE", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile2"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile2"}, }, { Name: "IMAGE", - Value: ParamValue{Type: ParamTypeString, StringVal: "image-2"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-2"}, }, }, { { Name: "DOCKERFILE", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile3"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile3"}, }, { Name: "IMAGE", - Value: ParamValue{Type: ParamTypeString, StringVal: "image-3"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-3"}, }, }}, }, { name: "matrix include unknown param name, append to all combinations", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1.Matrix{ + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1.Params{{ + Name: "package", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, - want: []Params{{ + want: []v1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }}, }, { name: "matrix include param value does not exist, generate a new combination", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1.Matrix{ + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1.IncludeParamsList{{ Name: "non-existent-arch", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "I-do-not-exist"}}}, + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "I-do-not-exist"}}}, }}, }, - want: []Params{{ + want: []v1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "I-do-not-exist"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "I-do-not-exist"}, }, }}, }, { name: "Matrix include filters single parameter and appends missing values", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1.Matrix{ + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1.IncludeParamsList{{ Name: "s390x-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}}, + Name: "flags", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}}}, }}, }, - want: []Params{{ + want: []v1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }}, }, { name: "Matrix include filters multiple parameters and append new parameters", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1.Matrix{ + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{ + Include: v1.IncludeParamsList{ { Name: "390x-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}}, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}, { - Name: "version", Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}}}, + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}}, { + Name: "flags", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}}, { + Name: "version", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}}}, }, { Name: "amd64-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}}, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}, { - Name: "version", Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}}}, + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}}, { + Name: "flags", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}}, { + Name: "version", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}}}, }, }, }, - want: []Params{{ + want: []v1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }}, }, { name: "Matrix params and include params handles filter, appending, and generating new combinations at once", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1.Matrix{ + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1.Params{{ + Name: "package", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }, { Name: "s390x-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}}, + Name: "flags", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}}}, }, { Name: "go117-context", - Params: Params{{ - Name: "version", Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Params: v1.Params{{ + Name: "version", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, { - Name: "context", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}}}, + Name: "context", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/go117/context"}}}, }, { Name: "non-existent-arch", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "I-do-not-exist"}}, + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "I-do-not-exist"}}, }, }}, }, - want: []Params{{ + want: []v1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "context", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/go117/context"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "context", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/go117/context"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "context", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/go117/context"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}, { + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}}, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "I-do-not-exist"}, + Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "I-do-not-exist"}, }, }}, }} @@ -594,7 +595,7 @@ func TestMatrix_FanOut(t *testing.T) { func TestMatrix_HasParams(t *testing.T) { testCases := []struct { name string - matrix *Matrix + matrix *v1.Matrix want bool }{ { @@ -604,37 +605,37 @@ func TestMatrix_HasParams(t *testing.T) { }, { name: "empty matrix", - matrix: &Matrix{}, + matrix: &v1.Matrix{}, want: false, }, { name: "matrixed with params", - matrix: &Matrix{ - Params: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + matrix: &v1.Matrix{ + Params: v1.Params{{Name: "platform", Value: v1.ParamValue{ArrayVal: []string{"linux", "windows"}}}}, }, want: true, }, { name: "matrixed with include", - matrix: &Matrix{ - Include: IncludeParamsList{{ + matrix: &v1.Matrix{ + Include: v1.IncludeParamsList{{ Name: "build-1", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Params: v1.Params{{ + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + Name: "DOCKERFILE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, }}, }, want: false, }, { name: "matrixed with params and include", - matrix: &Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: &v1.Matrix{ + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: IncludeParamsList{{ + Include: v1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1.Params{{ + Name: "package", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, want: true, @@ -652,7 +653,7 @@ func TestMatrix_HasParams(t *testing.T) { func TestMatrix_HasInclude(t *testing.T) { testCases := []struct { name string - matrix *Matrix + matrix *v1.Matrix want bool }{ { @@ -662,37 +663,37 @@ func TestMatrix_HasInclude(t *testing.T) { }, { name: "empty matrix", - matrix: &Matrix{}, + matrix: &v1.Matrix{}, want: false, }, { name: "matrixed with params", - matrix: &Matrix{ - Params: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + matrix: &v1.Matrix{ + Params: v1.Params{{Name: "platform", Value: v1.ParamValue{ArrayVal: []string{"linux", "windows"}}}}, }, want: false, }, { name: "matrixed with include", - matrix: &Matrix{ - Include: IncludeParamsList{{ + matrix: &v1.Matrix{ + Include: v1.IncludeParamsList{{ Name: "build-1", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Params: v1.Params{{ + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + Name: "DOCKERFILE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, }}, }, want: true, }, { name: "matrixed with params and include", - matrix: &Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: &v1.Matrix{ + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: IncludeParamsList{{ + Include: v1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1.Params{{ + Name: "package", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, want: true, @@ -710,8 +711,8 @@ func TestMatrix_HasInclude(t *testing.T) { func TestMatrix_GetAllParams(t *testing.T) { testCases := []struct { name string - matrix *Matrix - want Params + matrix *v1.Matrix + want v1.Params }{ { name: "nil matrix", @@ -720,47 +721,47 @@ func TestMatrix_GetAllParams(t *testing.T) { }, { name: "empty matrix", - matrix: &Matrix{}, + matrix: &v1.Matrix{}, want: nil, }, { name: "matrixed with params", - matrix: &Matrix{ - Params: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + matrix: &v1.Matrix{ + Params: v1.Params{{Name: "platform", Value: v1.ParamValue{ArrayVal: []string{"linux", "windows"}}}}, }, - want: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + want: v1.Params{{Name: "platform", Value: v1.ParamValue{ArrayVal: []string{"linux", "windows"}}}}, }, { name: "matrixed with include", - matrix: &Matrix{ - Include: IncludeParamsList{{ + matrix: &v1.Matrix{ + Include: v1.IncludeParamsList{{ Name: "build-1", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Params: v1.Params{{ + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + Name: "DOCKERFILE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, }}, }, - want: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + want: v1.Params{{ + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + Name: "DOCKERFILE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, }, { name: "matrixed with params and include", - matrix: &Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: &v1.Matrix{ + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: IncludeParamsList{{ + Include: v1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1.Params{{ + Name: "package", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, - want: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + want: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Name: "package", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}, }}, }, } @@ -776,141 +777,141 @@ func TestMatrix_GetAllParams(t *testing.T) { func TestPipelineTask_CountCombinations(t *testing.T) { tests := []struct { name string - matrix *Matrix + matrix *v1.Matrix want int }{{ name: "combinations count is zero", - matrix: &Matrix{ - Params: Params{{}}}, + matrix: &v1.Matrix{ + Params: v1.Params{{}}}, want: 0, }, { name: "combinations count is one from one parameter", - matrix: &Matrix{ - Params: Params{{ - Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo"}}, + matrix: &v1.Matrix{ + Params: v1.Params{{ + Name: "foo", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"foo"}}, }}}, want: 1, }, { name: "combinations count is one from two parameters", - matrix: &Matrix{ - Params: Params{{ - Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo"}}, + matrix: &v1.Matrix{ + Params: v1.Params{{ + Name: "foo", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"foo"}}, }, { - Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar"}}, + Name: "bar", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"bar"}}, }}}, want: 1, }, { name: "combinations count is two from one parameter", - matrix: &Matrix{ - Params: Params{{ - Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, + matrix: &v1.Matrix{ + Params: v1.Params{{ + Name: "foo", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, want: 2, }, { name: "combinations count is nine", - matrix: &Matrix{ - Params: Params{{ - Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, + matrix: &v1.Matrix{ + Params: v1.Params{{ + Name: "foo", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, }, { - Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, + Name: "bar", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, }}}, want: 9, }, { name: "combinations count is large", - matrix: &Matrix{ - Params: Params{{ - Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, + matrix: &v1.Matrix{ + Params: v1.Params{{ + Name: "foo", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, }, { - Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, + Name: "bar", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, }, { - Name: "quz", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"q", "u", "x"}}, + Name: "quz", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"q", "u", "x"}}, }, { - Name: "xyzzy", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"x", "y", "z", "z", "y"}}, + Name: "xyzzy", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"x", "y", "z", "z", "y"}}, }}}, want: 135, }, { name: "explicit combinations in the matrix", - matrix: &Matrix{ - Include: IncludeParamsList{{ + matrix: &v1.Matrix{ + Include: v1.IncludeParamsList{{ Name: "build-1", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Params: v1.Params{{ + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}, + Name: "DOCKERFILE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile1"}, }}, }, { Name: "build-2", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-2"}, + Params: v1.Params{{ + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-2"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile2"}, + Name: "DOCKERFILE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile2"}, }}, }, { Name: "build-3", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-3"}, + Params: v1.Params{{ + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-3"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile3"}, + Name: "DOCKERFILE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile3"}, }}, }}, }, want: 3, }, { name: "params and include in matrix with overriding combinations params", - matrix: &Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: &v1.Matrix{ + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1.Params{{ + Name: "package", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }, { Name: "s390x-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}}, + Name: "flags", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}}}, }, { Name: "go117-context", - Params: Params{{ - Name: "version", Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Params: v1.Params{{ + Name: "version", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, { - Name: "context", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}}}, + Name: "context", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/go117/context"}}}, }}, }, want: 6, }, { name: "params and include in matrix with overriding combinations params and one new combination", - matrix: &Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: &v1.Matrix{ + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1.Params{{ + Name: "package", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }, { Name: "s390x-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}}, + Name: "flags", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "-cover -v"}}}, }, { Name: "go117-context", - Params: Params{{ - Name: "version", Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Params: v1.Params{{ + Name: "version", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "go1.17"}, }, { - Name: "context", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}}}, + Name: "context", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/go117/context"}}}, }, { Name: "non-existent-arch", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "I-do-not-exist"}}, + Params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "I-do-not-exist"}}, }}, }}, want: 7, diff --git a/pkg/apis/pipeline/v1/taskref_types_test.go b/pkg/apis/pipeline/v1/taskref_types_test.go index 6001db6478b..f73513479e4 100644 --- a/pkg/apis/pipeline/v1/taskref_types_test.go +++ b/pkg/apis/pipeline/v1/taskref_types_test.go @@ -5,7 +5,7 @@ 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 + 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, @@ -14,39 +14,43 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package v1_test -import "testing" +import ( + "testing" + + v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" +) func TestTaskRef_IsCustomTask(t *testing.T) { tests := []struct { name string - tr *TaskRef + tr *v1.TaskRef want bool }{{ name: "not a custom task - apiVersion and Kind are not set", - tr: &TaskRef{ + tr: &v1.TaskRef{ Name: "foo", }, want: false, }, { // related issue: https://github.com/tektoncd/pipeline/issues/6459 name: "not a custom task - apiVersion is not set", - tr: &TaskRef{ + tr: &v1.TaskRef{ Name: "foo", Kind: "Example", }, want: false, }, { name: "not a custom task - kind is not set", - tr: &TaskRef{ + tr: &v1.TaskRef{ Name: "foo", APIVersion: "example/v0", }, want: false, }, { name: "custom task with name", - tr: &TaskRef{ + tr: &v1.TaskRef{ Name: "foo", Kind: "Example", APIVersion: "example/v0", @@ -54,7 +58,7 @@ func TestTaskRef_IsCustomTask(t *testing.T) { want: true, }, { name: "custom task without name", - tr: &TaskRef{ + tr: &v1.TaskRef{ Kind: "Example", APIVersion: "example/v0", }, diff --git a/pkg/apis/pipeline/v1beta1/cluster_task_conversion_test.go b/pkg/apis/pipeline/v1beta1/cluster_task_conversion_test.go index 6dda3ba2987..8dce05a0e3f 100644 --- a/pkg/apis/pipeline/v1beta1/cluster_task_conversion_test.go +++ b/pkg/apis/pipeline/v1beta1/cluster_task_conversion_test.go @@ -14,15 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1beta1 +package v1beta1_test import ( "context" "testing" + + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" ) func TestClusterTaskConversionBadType(t *testing.T) { - good, bad := &ClusterTask{}, &Pipeline{} + good, bad := &v1beta1.ClusterTask{}, &v1beta1.Pipeline{} if err := good.ConvertTo(context.Background(), bad); err == nil { t.Errorf("ConvertTo() = %#v, wanted error", bad) diff --git a/pkg/apis/pipeline/v1beta1/matrix_types_test.go b/pkg/apis/pipeline/v1beta1/matrix_types_test.go index dfde9bf84d6..601eed19f35 100644 --- a/pkg/apis/pipeline/v1beta1/matrix_types_test.go +++ b/pkg/apis/pipeline/v1beta1/matrix_types_test.go @@ -11,574 +11,575 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1beta1 +package v1beta1_test import ( "testing" "github.com/google/go-cmp/cmp" + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/test/diff" ) func TestMatrix_FanOut(t *testing.T) { tests := []struct { name string - matrix Matrix - want []Params + matrix v1beta1.Matrix + want []v1beta1.Params }{{ name: "matrix with no params", - matrix: Matrix{ - Params: Params{}, + matrix: v1beta1.Matrix{ + Params: v1beta1.Params{}, }, - want: []Params{}, + want: []v1beta1.Params{}, }, { name: "single array in matrix", - matrix: Matrix{ - Params: Params{{ + matrix: v1beta1.Matrix{ + Params: v1beta1.Params{{ Name: "platform", - Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}}, }}, }, - want: []Params{{ + want: []v1beta1.Params{{ { Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux"}, }, }, { { Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "mac"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "mac"}, }, }, { { Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "windows"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "windows"}, }, }}, }, { name: "multiple arrays in matrix", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1beta1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{}}, + Include: v1beta1.IncludeParamsList{{}}, }, - want: []Params{{ + want: []v1beta1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }}, }, { name: "Fan out explicit combinations, no matrix params", - matrix: Matrix{ - Include: IncludeParamsList{{ + matrix: v1beta1.Matrix{ + Include: v1beta1.IncludeParamsList{{ Name: "build-1", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Params: v1beta1.Params{{ + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + Name: "DOCKERFILE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, }, { Name: "build-2", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-2"}, + Params: v1beta1.Params{{ + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-2"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile2"}}}, + Name: "DOCKERFILE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile2"}}}, }, { Name: "build-3", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-3"}, + Params: v1beta1.Params{{ + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-3"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile3"}}}, + Name: "DOCKERFILE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile3"}}}, }}, }, - want: []Params{{ + want: []v1beta1.Params{{ { Name: "DOCKERFILE", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile1"}, }, { Name: "IMAGE", - Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-1"}, }, }, { { Name: "DOCKERFILE", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile2"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile2"}, }, { Name: "IMAGE", - Value: ParamValue{Type: ParamTypeString, StringVal: "image-2"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-2"}, }, }, { { Name: "DOCKERFILE", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile3"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile3"}, }, { Name: "IMAGE", - Value: ParamValue{Type: ParamTypeString, StringVal: "image-3"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-3"}, }, }}, }, { name: "matrix include unknown param name, append to all combinations", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1beta1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1beta1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1beta1.Params{{ + Name: "package", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, - want: []Params{{ + want: []v1beta1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }}, }, { name: "matrix include param value does not exist, generate a new combination", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1beta1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1beta1.IncludeParamsList{{ Name: "non-existent-arch", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "I-do-not-exist"}}}, + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "I-do-not-exist"}}}, }}, }, - want: []Params{{ + want: []v1beta1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "I-do-not-exist"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "I-do-not-exist"}, }, }}, }, { name: "Matrix include filters single parameter and appends missing values", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1beta1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1beta1.IncludeParamsList{{ Name: "s390x-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}}, + Name: "flags", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}}}, }}, }, - want: []Params{{ + want: []v1beta1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }}, }, { name: "Matrix include filters multiple parameters and append new parameters", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1beta1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{ + Include: v1beta1.IncludeParamsList{ { Name: "390x-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}}, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}, { - Name: "version", Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}}}, + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}}, { + Name: "flags", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}}, { + Name: "version", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}}}, }, { Name: "amd64-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}}, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}, { - Name: "version", Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}}}, + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}}, { + Name: "flags", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}}, { + Name: "version", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}}}, }, }, }, - want: []Params{{ + want: []v1beta1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }}, }, { name: "Matrix params and include params handles filter, appending, and generating new combinations at once", - matrix: Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1beta1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1beta1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1beta1.Params{{ + Name: "package", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }, { Name: "s390x-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}}, + Name: "flags", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}}}, }, { Name: "go117-context", - Params: Params{{ - Name: "version", Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Params: v1beta1.Params{{ + Name: "version", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, { - Name: "context", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}}}, + Name: "context", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/go117/context"}}}, }, { Name: "non-existent-arch", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "I-do-not-exist"}}, + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "I-do-not-exist"}}, }, }}, }, - want: []Params{{ + want: []v1beta1.Params{{ { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "context", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/go117/context"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "context", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/go117/context"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "context", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/go117/context"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/amd64"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}, { + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}}, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/ppc64le"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { Name: "flags", - Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}, }, { Name: "package", - Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }, { Name: "version", - Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.18.1"}, }, }, { { Name: "GOARCH", - Value: ParamValue{Type: ParamTypeString, StringVal: "I-do-not-exist"}, + Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "I-do-not-exist"}, }, }}, }} @@ -594,7 +595,7 @@ func TestMatrix_FanOut(t *testing.T) { func TestMatrix_HasParams(t *testing.T) { testCases := []struct { name string - matrix *Matrix + matrix *v1beta1.Matrix want bool }{ { @@ -604,37 +605,37 @@ func TestMatrix_HasParams(t *testing.T) { }, { name: "empty matrix", - matrix: &Matrix{}, + matrix: &v1beta1.Matrix{}, want: false, }, { name: "matrixed with params", - matrix: &Matrix{ - Params: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{Name: "platform", Value: v1beta1.ParamValue{ArrayVal: []string{"linux", "windows"}}}}, }, want: true, }, { name: "matrixed with include", - matrix: &Matrix{ - Include: IncludeParamsList{{ + matrix: &v1beta1.Matrix{ + Include: v1beta1.IncludeParamsList{{ Name: "build-1", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Params: v1beta1.Params{{ + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + Name: "DOCKERFILE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, }}, }, want: false, }, { name: "matrixed with params and include", - matrix: &Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: IncludeParamsList{{ + Include: v1beta1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1beta1.Params{{ + Name: "package", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, want: true, @@ -652,7 +653,7 @@ func TestMatrix_HasParams(t *testing.T) { func TestMatrix_HasInclude(t *testing.T) { testCases := []struct { name string - matrix *Matrix + matrix *v1beta1.Matrix want bool }{ { @@ -662,37 +663,37 @@ func TestMatrix_HasInclude(t *testing.T) { }, { name: "empty matrix", - matrix: &Matrix{}, + matrix: &v1beta1.Matrix{}, want: false, }, { name: "matrixed with params", - matrix: &Matrix{ - Params: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{Name: "platform", Value: v1beta1.ParamValue{ArrayVal: []string{"linux", "windows"}}}}, }, want: false, }, { name: "matrixed with include", - matrix: &Matrix{ - Include: IncludeParamsList{{ + matrix: &v1beta1.Matrix{ + Include: v1beta1.IncludeParamsList{{ Name: "build-1", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Params: v1beta1.Params{{ + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + Name: "DOCKERFILE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, }}, }, want: true, }, { name: "matrixed with params and include", - matrix: &Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: IncludeParamsList{{ + Include: v1beta1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1beta1.Params{{ + Name: "package", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, want: true, @@ -710,8 +711,8 @@ func TestMatrix_HasInclude(t *testing.T) { func TestMatrix_GetAllParams(t *testing.T) { testCases := []struct { name string - matrix *Matrix - want Params + matrix *v1beta1.Matrix + want v1beta1.Params }{ { name: "nil matrix", @@ -720,47 +721,47 @@ func TestMatrix_GetAllParams(t *testing.T) { }, { name: "empty matrix", - matrix: &Matrix{}, + matrix: &v1beta1.Matrix{}, want: nil, }, { name: "matrixed with params", - matrix: &Matrix{ - Params: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{Name: "platform", Value: v1beta1.ParamValue{ArrayVal: []string{"linux", "windows"}}}}, }, - want: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + want: v1beta1.Params{{Name: "platform", Value: v1beta1.ParamValue{ArrayVal: []string{"linux", "windows"}}}}, }, { name: "matrixed with include", - matrix: &Matrix{ - Include: IncludeParamsList{{ + matrix: &v1beta1.Matrix{ + Include: v1beta1.IncludeParamsList{{ Name: "build-1", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Params: v1beta1.Params{{ + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + Name: "DOCKERFILE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, }}, }, - want: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + want: v1beta1.Params{{ + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + Name: "DOCKERFILE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, }, { name: "matrixed with params and include", - matrix: &Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: IncludeParamsList{{ + Include: v1beta1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1beta1.Params{{ + Name: "package", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, - want: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + want: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + Name: "package", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}, }}, }, } @@ -776,141 +777,141 @@ func TestMatrix_GetAllParams(t *testing.T) { func TestPipelineTask_CountCombinations(t *testing.T) { tests := []struct { name string - matrix *Matrix + matrix *v1beta1.Matrix want int }{{ name: "combinations count is zero", - matrix: &Matrix{ - Params: Params{{}}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{}}}, want: 0, }, { name: "combinations count is one from one parameter", - matrix: &Matrix{ - Params: Params{{ - Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo"}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "foo", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"foo"}}, }}}, want: 1, }, { name: "combinations count is one from two parameters", - matrix: &Matrix{ - Params: Params{{ - Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo"}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "foo", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"foo"}}, }, { - Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar"}}, + Name: "bar", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"bar"}}, }}}, want: 1, }, { name: "combinations count is two from one parameter", - matrix: &Matrix{ - Params: Params{{ - Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "foo", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, want: 2, }, { name: "combinations count is nine", - matrix: &Matrix{ - Params: Params{{ - Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "foo", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, }, { - Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, + Name: "bar", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, }}}, want: 9, }, { name: "combinations count is large", - matrix: &Matrix{ - Params: Params{{ - Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "foo", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, }, { - Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, + Name: "bar", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, }, { - Name: "quz", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"q", "u", "x"}}, + Name: "quz", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"q", "u", "x"}}, }, { - Name: "xyzzy", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"x", "y", "z", "z", "y"}}, + Name: "xyzzy", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"x", "y", "z", "z", "y"}}, }}}, want: 135, }, { name: "explicit combinations in the matrix", - matrix: &Matrix{ - Include: IncludeParamsList{{ + matrix: &v1beta1.Matrix{ + Include: v1beta1.IncludeParamsList{{ Name: "build-1", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + Params: v1beta1.Params{{ + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-1"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}, + Name: "DOCKERFILE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile1"}, }}, }, { Name: "build-2", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-2"}, + Params: v1beta1.Params{{ + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-2"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile2"}, + Name: "DOCKERFILE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile2"}, }}, }, { Name: "build-3", - Params: Params{{ - Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-3"}, + Params: v1beta1.Params{{ + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-3"}, }, { - Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile3"}, + Name: "DOCKERFILE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile3"}, }}, }}, }, want: 3, }, { name: "params and include in matrix with overriding combinations params", - matrix: &Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1beta1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1beta1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1beta1.Params{{ + Name: "package", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }, { Name: "s390x-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}}, + Name: "flags", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}}}, }, { Name: "go117-context", - Params: Params{{ - Name: "version", Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Params: v1beta1.Params{{ + Name: "version", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, { - Name: "context", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}}}, + Name: "context", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/go117/context"}}}, }}, }, want: 6, }, { name: "params and include in matrix with overriding combinations params and one new combination", - matrix: &Matrix{ - Params: Params{{ - Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, + Name: "version", Value: v1beta1.ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: IncludeParamsList{{ + Include: v1beta1.IncludeParamsList{{ Name: "common-package", - Params: Params{{ - Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + Params: v1beta1.Params{{ + Name: "package", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/common/package/"}}}, }, { Name: "s390x-no-race", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "flags", Value: ParamValue{Type: ParamTypeString, StringVal: "-cover -v"}}}, + Name: "flags", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "-cover -v"}}}, }, { Name: "go117-context", - Params: Params{{ - Name: "version", Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, + Params: v1beta1.Params{{ + Name: "version", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "go1.17"}, }, { - Name: "context", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/go117/context"}}}, + Name: "context", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/go117/context"}}}, }, { Name: "non-existent-arch", - Params: Params{{ - Name: "GOARCH", Value: ParamValue{Type: ParamTypeString, StringVal: "I-do-not-exist"}}, + Params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "I-do-not-exist"}}, }}, }}, want: 7, diff --git a/pkg/apis/pipeline/v1beta1/merge_test.go b/pkg/apis/pipeline/v1beta1/merge_test.go index c2248b0aa1b..08fff766f65 100644 --- a/pkg/apis/pipeline/v1beta1/merge_test.go +++ b/pkg/apis/pipeline/v1beta1/merge_test.go @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1beta1 +package v1beta1_test import ( "testing" "github.com/google/go-cmp/cmp" + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -32,49 +33,49 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { for _, tc := range []struct { name string - template *StepTemplate - steps []Step - expected []Step + template *v1beta1.StepTemplate + steps []v1beta1.Step + expected []v1beta1.Step }{{ name: "nil-template", template: nil, - steps: []Step{{ + steps: []v1beta1.Step{{ Image: "some-image", OnError: "foo", }}, - expected: []Step{{ + expected: []v1beta1.Step{{ Image: "some-image", OnError: "foo", }}, }, { name: "not-overlapping", - template: &StepTemplate{ + template: &v1beta1.StepTemplate{ Command: []string{"/somecmd"}, }, - steps: []Step{{ + steps: []v1beta1.Step{{ Image: "some-image", OnError: "foo", }}, - expected: []Step{{ + expected: []v1beta1.Step{{ Command: []string{"/somecmd"}, Image: "some-image", OnError: "foo", }}, }, { name: "overwriting-one-field", - template: &StepTemplate{ + template: &v1beta1.StepTemplate{ Image: "some-image", Command: []string{"/somecmd"}, }, - steps: []Step{{ + steps: []v1beta1.Step{{ Image: "some-other-image", }}, - expected: []Step{{ + expected: []v1beta1.Step{{ Command: []string{"/somecmd"}, Image: "some-other-image", }}, }, { name: "merge-and-overwrite-slice", - template: &StepTemplate{ + template: &v1beta1.StepTemplate{ Env: []corev1.EnvVar{{ Name: "KEEP_THIS", Value: "A_VALUE", @@ -83,7 +84,7 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { Value: "ORIGINAL_VALUE", }}, }, - steps: []Step{{ + steps: []v1beta1.Step{{ Env: []corev1.EnvVar{{ Name: "NEW_KEY", Value: "A_VALUE", @@ -92,7 +93,7 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { Value: "NEW_VALUE", }}, }}, - expected: []Step{{ + expected: []v1beta1.Step{{ Env: []corev1.EnvVar{{ Name: "NEW_KEY", Value: "A_VALUE", @@ -106,21 +107,21 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { }}, }, { name: "workspace-and-output-config", - template: &StepTemplate{ + template: &v1beta1.StepTemplate{ VolumeMounts: []corev1.VolumeMount{{ Name: "data", MountPath: "/workspace/data", }}, }, - steps: []Step{{ + steps: []v1beta1.Step{{ Image: "some-image", - StdoutConfig: &StepOutputConfig{Path: "stdout.txt"}, - StderrConfig: &StepOutputConfig{Path: "stderr.txt"}, + StdoutConfig: &v1beta1.StepOutputConfig{Path: "stdout.txt"}, + StderrConfig: &v1beta1.StepOutputConfig{Path: "stderr.txt"}, }}, - expected: []Step{{ + expected: []v1beta1.Step{{ Image: "some-image", - StdoutConfig: &StepOutputConfig{Path: "stdout.txt"}, - StderrConfig: &StepOutputConfig{Path: "stderr.txt"}, + StdoutConfig: &v1beta1.StepOutputConfig{Path: "stdout.txt"}, + StderrConfig: &v1beta1.StepOutputConfig{Path: "stderr.txt"}, VolumeMounts: []corev1.VolumeMount{{ Name: "data", MountPath: "/workspace/data", @@ -128,7 +129,7 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { }}, }, { name: "merge-env-by-step", - template: &StepTemplate{ + template: &v1beta1.StepTemplate{ Env: []corev1.EnvVar{{ Name: "KEEP_THIS", Value: "A_VALUE", @@ -145,7 +146,7 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { Value: "VALUE_2", }}, }, - steps: []Step{{ + steps: []v1beta1.Step{{ Env: []corev1.EnvVar{{ Name: "NEW_KEY", Value: "A_VALUE", @@ -162,7 +163,7 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { }, }}, }}, - expected: []Step{{ + expected: []v1beta1.Step{{ Env: []corev1.EnvVar{{ Name: "NEW_KEY", Value: "A_VALUE", @@ -184,7 +185,7 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { }}, }} { t.Run(tc.name, func(t *testing.T) { - result, err := MergeStepsWithStepTemplate(tc.template, tc.steps) + result, err := v1beta1.MergeStepsWithStepTemplate(tc.template, tc.steps) if err != nil { t.Errorf("expected no error. Got error %v", err) } @@ -199,18 +200,18 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { func TestMergeStepOverrides(t *testing.T) { tcs := []struct { name string - steps []Step - stepOverrides []TaskRunStepOverride - want []Step + steps []v1beta1.Step + stepOverrides []v1beta1.TaskRunStepOverride + want []v1beta1.Step }{{ name: "no overrides", - steps: []Step{{ + steps: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, }, }}, - want: []Step{{ + want: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, @@ -218,7 +219,7 @@ func TestMergeStepOverrides(t *testing.T) { }}, }, { name: "not all steps overridden", - steps: []Step{{ + steps: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, @@ -229,13 +230,13 @@ func TestMergeStepOverrides(t *testing.T) { Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, }, }}, - stepOverrides: []TaskRunStepOverride{{ + stepOverrides: []v1beta1.TaskRunStepOverride{{ Name: "bar", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("2Gi")}, }, }}, - want: []Step{{ + want: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, @@ -248,7 +249,7 @@ func TestMergeStepOverrides(t *testing.T) { }}, }, { name: "override memory but not CPU", - steps: []Step{{ + steps: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ @@ -257,13 +258,13 @@ func TestMergeStepOverrides(t *testing.T) { }, }, }}, - stepOverrides: []TaskRunStepOverride{{ + stepOverrides: []v1beta1.TaskRunStepOverride{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("2Gi")}, }, }}, - want: []Step{{ + want: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ @@ -274,20 +275,20 @@ func TestMergeStepOverrides(t *testing.T) { }}, }, { name: "override request but not limit", - steps: []Step{{ + steps: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("2Gi")}, }, }}, - stepOverrides: []TaskRunStepOverride{{ + stepOverrides: []v1beta1.TaskRunStepOverride{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1.5Gi")}, }, }}, - want: []Step{{ + want: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1.5Gi")}, @@ -296,21 +297,21 @@ func TestMergeStepOverrides(t *testing.T) { }}, }, { name: "override request and limit", - steps: []Step{{ + steps: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("2Gi")}, }, }}, - stepOverrides: []TaskRunStepOverride{{ + stepOverrides: []v1beta1.TaskRunStepOverride{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1.5Gi")}, Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("3Gi")}, }, }}, - want: []Step{{ + want: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1.5Gi")}, @@ -321,20 +322,20 @@ func TestMergeStepOverrides(t *testing.T) { // We don't make any effort to reject overrides that would result in invalid pods; // instead, we let k8s reject the resulting pod. name: "new request > old limit", - steps: []Step{{ + steps: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("2Gi")}, }, }}, - stepOverrides: []TaskRunStepOverride{{ + stepOverrides: []v1beta1.TaskRunStepOverride{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("3Gi")}, }, }}, - want: []Step{{ + want: []v1beta1.Step{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("3Gi")}, @@ -344,7 +345,7 @@ func TestMergeStepOverrides(t *testing.T) { }} for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - steps, err := MergeStepsWithOverrides(tc.steps, tc.stepOverrides) + steps, err := v1beta1.MergeStepsWithOverrides(tc.steps, tc.stepOverrides) if err != nil { t.Errorf("unexpected error merging steps with overrides: %s", err) } @@ -358,18 +359,18 @@ func TestMergeStepOverrides(t *testing.T) { func TestMergeSidecarOverrides(t *testing.T) { tcs := []struct { name string - sidecars []Sidecar - sidecarOverrides []TaskRunSidecarOverride - want []Sidecar + sidecars []v1beta1.Sidecar + sidecarOverrides []v1beta1.TaskRunSidecarOverride + want []v1beta1.Sidecar }{{ name: "no overrides", - sidecars: []Sidecar{{ + sidecars: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, }, }}, - want: []Sidecar{{ + want: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, @@ -377,7 +378,7 @@ func TestMergeSidecarOverrides(t *testing.T) { }}, }, { name: "not all sidecars overridden", - sidecars: []Sidecar{{ + sidecars: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, @@ -388,13 +389,13 @@ func TestMergeSidecarOverrides(t *testing.T) { Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, }, }}, - sidecarOverrides: []TaskRunSidecarOverride{{ + sidecarOverrides: []v1beta1.TaskRunSidecarOverride{{ Name: "bar", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("2Gi")}, }, }}, - want: []Sidecar{{ + want: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, @@ -407,7 +408,7 @@ func TestMergeSidecarOverrides(t *testing.T) { }}, }, { name: "override memory but not CPU", - sidecars: []Sidecar{{ + sidecars: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ @@ -416,13 +417,13 @@ func TestMergeSidecarOverrides(t *testing.T) { }, }, }}, - sidecarOverrides: []TaskRunSidecarOverride{{ + sidecarOverrides: []v1beta1.TaskRunSidecarOverride{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("2Gi")}, }, }}, - want: []Sidecar{{ + want: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ @@ -433,20 +434,20 @@ func TestMergeSidecarOverrides(t *testing.T) { }}, }, { name: "override request but not limit", - sidecars: []Sidecar{{ + sidecars: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("2Gi")}, }, }}, - sidecarOverrides: []TaskRunSidecarOverride{{ + sidecarOverrides: []v1beta1.TaskRunSidecarOverride{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1.5Gi")}, }, }}, - want: []Sidecar{{ + want: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1.5Gi")}, @@ -455,21 +456,21 @@ func TestMergeSidecarOverrides(t *testing.T) { }}, }, { name: "override request and limit", - sidecars: []Sidecar{{ + sidecars: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("2Gi")}, }, }}, - sidecarOverrides: []TaskRunSidecarOverride{{ + sidecarOverrides: []v1beta1.TaskRunSidecarOverride{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1.5Gi")}, Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("3Gi")}, }, }}, - want: []Sidecar{{ + want: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1.5Gi")}, @@ -480,20 +481,20 @@ func TestMergeSidecarOverrides(t *testing.T) { // We don't make any effort to reject overrides that would result in invalid pods; // instead, we let k8s reject the resulting pod. name: "new request > old limit", - sidecars: []Sidecar{{ + sidecars: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}, Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("2Gi")}, }, }}, - sidecarOverrides: []TaskRunSidecarOverride{{ + sidecarOverrides: []v1beta1.TaskRunSidecarOverride{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("3Gi")}, }, }}, - want: []Sidecar{{ + want: []v1beta1.Sidecar{{ Name: "foo", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("3Gi")}, @@ -503,7 +504,7 @@ func TestMergeSidecarOverrides(t *testing.T) { }} for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - sidecars, err := MergeSidecarsWithOverrides(tc.sidecars, tc.sidecarOverrides) + sidecars, err := v1beta1.MergeSidecarsWithOverrides(tc.sidecars, tc.sidecarOverrides) if err != nil { t.Errorf("unexpected error merging sidecars with overrides: %s", err) } diff --git a/pkg/apis/pipeline/v1beta1/taskref_types_test.go b/pkg/apis/pipeline/v1beta1/taskref_types_test.go index 40dd01fc985..6666556003d 100644 --- a/pkg/apis/pipeline/v1beta1/taskref_types_test.go +++ b/pkg/apis/pipeline/v1beta1/taskref_types_test.go @@ -5,7 +5,7 @@ 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 + 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, @@ -14,39 +14,43 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1beta1 +package v1beta1_test -import "testing" +import ( + "testing" + + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" +) func TestTaskRef_IsCustomTask(t *testing.T) { tests := []struct { name string - tr *TaskRef + tr *v1beta1.TaskRef want bool }{{ name: "not a custom task - apiVersion and Kind are not set", - tr: &TaskRef{ + tr: &v1beta1.TaskRef{ Name: "foo", }, want: false, }, { // related issue: https://github.com/tektoncd/pipeline/issues/6459 name: "not a custom task - apiVersion is not set", - tr: &TaskRef{ + tr: &v1beta1.TaskRef{ Name: "foo", Kind: "Example", }, want: false, }, { name: "not a custom task - kind is not set", - tr: &TaskRef{ + tr: &v1beta1.TaskRef{ Name: "foo", APIVersion: "example/v0", }, want: false, }, { name: "custom task with name", - tr: &TaskRef{ + tr: &v1beta1.TaskRef{ Name: "foo", Kind: "Example", APIVersion: "example/v0", @@ -54,7 +58,7 @@ func TestTaskRef_IsCustomTask(t *testing.T) { want: true, }, { name: "custom task without name", - tr: &TaskRef{ + tr: &v1beta1.TaskRef{ Kind: "Example", APIVersion: "example/v0", }, diff --git a/pkg/apis/resolution/v1alpha1/resolution_request_conversion_test.go b/pkg/apis/resolution/v1alpha1/resolution_request_conversion_test.go index 7c2bfc8d365..7ebc5868d38 100644 --- a/pkg/apis/resolution/v1alpha1/resolution_request_conversion_test.go +++ b/pkg/apis/resolution/v1alpha1/resolution_request_conversion_test.go @@ -15,14 +15,16 @@ */ -package v1alpha1 +package v1alpha1_test import ( "context" + "errors" "testing" "github.com/google/go-cmp/cmp" pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" "github.com/tektoncd/pipeline/test/diff" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -30,7 +32,7 @@ import ( ) func TestResolutionRequestConversionBadType(t *testing.T) { - good, bad := &ResolutionRequest{}, &pipelinev1beta1.Task{} + good, bad := &v1alpha1.ResolutionRequest{}, &pipelinev1beta1.Task{} if err := good.ConvertTo(context.Background(), bad); err == nil { t.Errorf("ConvertTo() = %#v, wanted error", bad) @@ -41,154 +43,182 @@ func TestResolutionRequestConversionBadType(t *testing.T) { } } -func TestResolutionRequestConvertRoundTrip(t *testing.T) { +func TestResolutionRequestConvertTo(t *testing.T) { + versions := []apis.Convertible{&v1beta1.ResolutionRequest{}} + testCases := []struct { name string - in *ResolutionRequest + in *v1alpha1.ResolutionRequest out apis.Convertible - }{{ - name: "no params", - in: &ResolutionRequest{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: ResolutionRequestSpec{ - Parameters: nil, - }, - }, - }, { - name: "with params", - in: &ResolutionRequest{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: ResolutionRequestSpec{ - Parameters: map[string]string{ - "some-param": "some-value", + }{ + { + name: "no params", + in: &v1alpha1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1alpha1.ResolutionRequestSpec{ + Parameters: nil, }, }, - }, - }, { - name: "with status refsource", - in: &ResolutionRequest{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: ResolutionRequestSpec{ - Parameters: map[string]string{ - "some-param": "some-value", + out: &v1beta1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1beta1.ResolutionRequestSpec{ + Params: nil, }, }, - Status: ResolutionRequestStatus{ - ResolutionRequestStatusFields: ResolutionRequestStatusFields{ - Data: "foobar", - RefSource: &pipelinev1beta1.RefSource{ - URI: "abcd", - Digest: map[string]string{"123": "456"}, - EntryPoint: "baz", + }, { + name: "with params", + in: &v1alpha1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1alpha1.ResolutionRequestSpec{ + Parameters: map[string]string{ + "some-param": "some-value", }, }, }, - }, - }, { - name: "with status, no refsource", - in: &ResolutionRequest{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: ResolutionRequestSpec{ - Parameters: map[string]string{ - "some-param": "some-value", + out: &v1beta1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", }, - }, - Status: ResolutionRequestStatus{ - ResolutionRequestStatusFields: ResolutionRequestStatusFields{ - Data: "foobar", + Spec: v1beta1.ResolutionRequestSpec{ + Params: []pipelinev1beta1.Param{{ + Name: "some-param", + Value: *pipelinev1beta1.NewStructuredValues("some-value"), + }}, }, }, }, - }} + } for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - got := &v1beta1.ResolutionRequest{} - if err := tc.in.ConvertTo(context.Background(), got); err != nil { - t.Fatalf("ConvertTo() = %v", err) - } - - t.Logf("ConvertTo() = %#v", got) - - roundTrip := &ResolutionRequest{} - if err := roundTrip.ConvertFrom(context.Background(), got); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - if d := cmp.Diff(tc.in, roundTrip); d != "" { - t.Errorf("converted ResolutionRequest did not match expected: %s", diff.PrintWantGot(d)) - } - }) + for _, version := range versions { + t.Run(tc.name, func(t *testing.T) { + got := version + if err := tc.in.ConvertTo(context.Background(), got); err != nil { + t.Fatalf("ConvertTo() = %v", err) + } + t.Logf("ConvertTo() = %#v", got) + if d := cmp.Diff(tc.out, got); d != "" { + t.Errorf("converted ResolutionRequest did not match expected: %s", diff.PrintWantGot(d)) + } + }) + } } } -func TestResolutionRequestConvertFromDeprecated(t *testing.T) { +func TestResolutionRequestConvertFrom(t *testing.T) { + versions := []apis.Convertible{&v1alpha1.ResolutionRequest{}} + testCases := []struct { - name string - in *v1beta1.ResolutionRequest - want apis.Convertible - }{{ - name: "with status.source", - in: &v1beta1.ResolutionRequest{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: v1beta1.ResolutionRequestSpec{ - Params: nil, + name string + in apis.Convertible + out *v1alpha1.ResolutionRequest + expectedErr error + }{ + { + name: "no params", + in: &v1beta1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1beta1.ResolutionRequestSpec{ + Params: nil, + }, }, - Status: v1beta1.ResolutionRequestStatus{ - ResolutionRequestStatusFields: v1beta1.ResolutionRequestStatusFields{ - Source: &pipelinev1beta1.ConfigSource{ - URI: "abcd", - Digest: map[string]string{"123": "456"}, - EntryPoint: "baz", - }, + out: &v1alpha1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1alpha1.ResolutionRequestSpec{ + Parameters: nil, }, }, - }, - want: &ResolutionRequest{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", + }, { + name: "with only string params", + in: &v1beta1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1beta1.ResolutionRequestSpec{ + Params: []pipelinev1beta1.Param{{ + Name: "some-param", + Value: *pipelinev1beta1.NewStructuredValues("some-value"), + }}, + }, }, - Spec: ResolutionRequestSpec{ - Parameters: nil, + out: &v1alpha1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1alpha1.ResolutionRequestSpec{ + Parameters: map[string]string{ + "some-param": "some-value", + }, + }, }, - Status: ResolutionRequestStatus{ - ResolutionRequestStatusFields: ResolutionRequestStatusFields{ - RefSource: &pipelinev1beta1.RefSource{ - URI: "abcd", - Digest: map[string]string{"123": "456"}, - EntryPoint: "baz", + }, { + name: "with non-string params", + in: &v1beta1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1beta1.ResolutionRequestSpec{ + Params: []pipelinev1beta1.Param{ + { + Name: "array-val", + Value: *pipelinev1beta1.NewStructuredValues("one", "two"), + }, { + Name: "string-val", + Value: *pipelinev1beta1.NewStructuredValues("a-string"), + }, { + Name: "object-val", + Value: *pipelinev1beta1.NewObject(map[string]string{ + "key-one": "value-one", + "key-two": "value-two", + }), + }, }, }, }, + out: nil, + expectedErr: errors.New("cannot convert v1beta1 to v1alpha, non-string type parameter(s) found: array-val, object-val"), }, - }} + } for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - got := &ResolutionRequest{} - if err := got.ConvertFrom(context.Background(), tc.in); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - if d := cmp.Diff(tc.want, got); d != "" { - t.Errorf("converted ResolutionRequest did not match expected: %s", diff.PrintWantGot(d)) - } - }) + for _, version := range versions { + t.Run(tc.name, func(t *testing.T) { + got := version + err := got.ConvertFrom(context.Background(), tc.in) + if tc.expectedErr != nil { + if err == nil { + t.Fatalf("expected error '%s', but did not get an error", tc.expectedErr.Error()) + } else if d := cmp.Diff(tc.expectedErr.Error(), err.Error()); d != "" { + t.Fatalf("error did not meet expected: %s", diff.PrintWantGot(d)) + } + return + } else if err != nil { + t.Fatalf("ConvertFrom() = %v", err) + } + t.Logf("ConvertFrom() = %#v", got) + if d := cmp.Diff(tc.out, got); d != "" { + t.Errorf("converted ResolutionRequest did not match expected: %s", diff.PrintWantGot(d)) + } + }) + } } } diff --git a/pkg/apis/resolution/v1beta1/resolution_request_conversion_test.go b/pkg/apis/resolution/v1beta1/resolution_request_conversion_test.go index 44b77f51c21..b67e38c566f 100644 --- a/pkg/apis/resolution/v1beta1/resolution_request_conversion_test.go +++ b/pkg/apis/resolution/v1beta1/resolution_request_conversion_test.go @@ -15,17 +15,18 @@ */ -package v1beta1 +package v1beta1_test import ( "context" "testing" pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" ) func TestResolutionRequestConversionBadType(t *testing.T) { - good, bad := &ResolutionRequest{}, &pipelinev1beta1.Task{} + good, bad := &v1beta1.ResolutionRequest{}, &pipelinev1beta1.Task{} if err := good.ConvertTo(context.Background(), bad); err == nil { t.Errorf("ConvertTo() = %#v, wanted error", bad) diff --git a/pkg/apis/run/v1beta1/customrunstatus_types_test.go b/pkg/apis/run/v1beta1/customrunstatus_types_test.go index d2b0fcd1da2..24f47322cfe 100644 --- a/pkg/apis/run/v1beta1/customrunstatus_types_test.go +++ b/pkg/apis/run/v1beta1/customrunstatus_types_test.go @@ -15,7 +15,7 @@ */ -package v1beta1 +package v1beta1_test import ( "testing" @@ -23,6 +23,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/run/v1alpha1" + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/run/v1beta1" "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -74,31 +75,31 @@ func TestFromRunStatus(t *testing.T) { }, } - expectedCustomRunResult := CustomRunStatus{ + expectedCustomRunResult := v1beta1.CustomRunStatus{ Status: duckv1.Status{ Conditions: []apis.Condition{{ Type: apis.ConditionSucceeded, Status: corev1.ConditionTrue, }}, }, - CustomRunStatusFields: CustomRunStatusFields{ + CustomRunStatusFields: v1beta1.CustomRunStatusFields{ StartTime: &metav1.Time{Time: startTime}, CompletionTime: &metav1.Time{Time: endTime}, - Results: []CustomRunResult{{ + Results: []v1beta1.CustomRunResult{{ Name: "foo", Value: "bar", }}, - RetriesStatus: []CustomRunStatus{{ + RetriesStatus: []v1beta1.CustomRunStatus{{ Status: duckv1.Status{ Conditions: []apis.Condition{{ Type: apis.ConditionSucceeded, Status: corev1.ConditionFalse, }}, }, - CustomRunStatusFields: CustomRunStatusFields{ + CustomRunStatusFields: v1beta1.CustomRunStatusFields{ StartTime: &metav1.Time{Time: startTime.Add(-30 * time.Minute)}, CompletionTime: &metav1.Time{Time: startTime.Add(-15 * time.Minute)}, - Results: []CustomRunResult{{ + Results: []v1beta1.CustomRunResult{{ Name: "foo", Value: "bad", }}, @@ -113,7 +114,7 @@ func TestFromRunStatus(t *testing.T) { }, } - if d := cmp.Diff(expectedCustomRunResult, FromRunStatus(runStatus)); d != "" { + if d := cmp.Diff(expectedCustomRunResult, v1beta1.FromRunStatus(runStatus)); d != "" { t.Errorf("expected converted RunStatus to equal expected CustomRunStatus. Diff %s", diff.PrintWantGot(d)) } } diff --git a/pkg/credentials/initialize_test.go b/pkg/credentials/initialize_test.go index 6797512e356..1e89b184ab8 100644 --- a/pkg/credentials/initialize_test.go +++ b/pkg/credentials/initialize_test.go @@ -5,7 +5,7 @@ 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 + 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, diff --git a/pkg/internal/computeresources/transformer_test.go b/pkg/internal/computeresources/transformer_test.go index 63154e2b85f..e805392838d 100644 --- a/pkg/internal/computeresources/transformer_test.go +++ b/pkg/internal/computeresources/transformer_test.go @@ -13,6 +13,7 @@ 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 computeresources import ( diff --git a/pkg/list/diff_test.go b/pkg/list/diff_test.go index cdd1eb37f22..92687f94df7 100644 --- a/pkg/list/diff_test.go +++ b/pkg/list/diff_test.go @@ -14,17 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -package list +package list_test import ( "reflect" "testing" + + list "github.com/tektoncd/pipeline/pkg/list" ) func TestIsSame_same(t *testing.T) { required := []string{"elsa", "anna", "olaf", "kristoff"} provided := []string{"elsa", "anna", "olaf", "kristoff"} - err := IsSame(required, provided) + err := list.IsSame(required, provided) if err != nil { t.Errorf("Didn't expect error when everything required has been provided") } @@ -33,7 +35,7 @@ func TestIsSame_same(t *testing.T) { func TestIsSame_missing(t *testing.T) { required := []string{"elsa", "anna", "olaf", "kristoff"} provided := []string{"elsa", "anna", "olaf"} - err := IsSame(required, provided) + err := list.IsSame(required, provided) if err == nil { t.Errorf("Expected error since `kristoff` should be missing") } @@ -42,7 +44,7 @@ func TestIsSame_missing(t *testing.T) { func TestIsSame_extra(t *testing.T) { required := []string{"elsa", "anna", "olaf"} provided := []string{"elsa", "anna", "olaf", "kristoff"} - err := IsSame(required, provided) + err := list.IsSame(required, provided) if err == nil { t.Errorf("Expected error since `kristoff` should be extra") } @@ -51,7 +53,7 @@ func TestIsSame_extra(t *testing.T) { func TestDiffLeft_same(t *testing.T) { left := []string{"elsa", "anna", "olaf", "kristoff"} right := []string{"elsa", "anna", "olaf", "kristoff"} - extraLeft := DiffLeft(left, right) + extraLeft := list.DiffLeft(left, right) if !reflect.DeepEqual(extraLeft, []string{}) { t.Errorf("Didn't expect extra strings in left list but got %v", extraLeft) @@ -61,7 +63,7 @@ func TestDiffLeft_same(t *testing.T) { func TestDiffLeft_extraLeft(t *testing.T) { left := []string{"elsa", "anna", "olaf", "kristoff", "hans"} right := []string{"elsa", "anna", "olaf", "kristoff"} - extraLeft := DiffLeft(left, right) + extraLeft := list.DiffLeft(left, right) if !reflect.DeepEqual(extraLeft, []string{"hans"}) { t.Errorf("Should have identified extra string in left list but got %v", extraLeft) @@ -71,7 +73,7 @@ func TestDiffLeft_extraLeft(t *testing.T) { func TestDiffLeft_extraRight(t *testing.T) { left := []string{"elsa", "anna", "olaf", "kristoff"} right := []string{"elsa", "anna", "olaf", "kristoff", "hans"} - extraLeft := DiffLeft(left, right) + extraLeft := list.DiffLeft(left, right) if !reflect.DeepEqual(extraLeft, []string{}) { t.Errorf("Shouldn't have noticed extra item in right list but got %v", extraLeft) diff --git a/pkg/names/generate_test.go b/pkg/names/generate_test.go index c0e597a5b04..bf14eb82dd8 100644 --- a/pkg/names/generate_test.go +++ b/pkg/names/generate_test.go @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package names +package names_test import ( "strings" "testing" + pkgnames "github.com/tektoncd/pipeline/pkg/names" "github.com/tektoncd/pipeline/test/names" ) @@ -35,7 +36,7 @@ func TestRestrictLengthWithRandomSuffix(t *testing.T) { }} { t.Run(c.in, func(t *testing.T) { names.TestingSeed() - got := SimpleNameGenerator.RestrictLengthWithRandomSuffix(c.in) + got := pkgnames.SimpleNameGenerator.RestrictLengthWithRandomSuffix(c.in) if got != c.want { t.Errorf("RestrictLengthWithRandomSuffix:\n got %q\nwant %q", got, c.want) } @@ -51,7 +52,7 @@ func TestRestrictLength(t *testing.T) { want: "hello", }, { in: strings.Repeat("a", 100), - want: strings.Repeat("a", maxNameLength), + want: strings.Repeat("a", 63), }, { // Values that don't end with an alphanumeric value are // trimmed until they do. @@ -59,7 +60,7 @@ func TestRestrictLength(t *testing.T) { want: "abcdefg", }} { t.Run(c.in, func(t *testing.T) { - got := SimpleNameGenerator.RestrictLength(c.in) + got := pkgnames.SimpleNameGenerator.RestrictLength(c.in) if got != c.want { t.Errorf("RestrictLength:\n got %q\nwant %q", got, c.want) } diff --git a/pkg/reconciler/customrun/customrun_test.go b/pkg/reconciler/customrun/customrun_test.go index c739e19055a..eb99b7968cc 100644 --- a/pkg/reconciler/customrun/customrun_test.go +++ b/pkg/reconciler/customrun/customrun_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package customrun +package customrun_test import ( "context" @@ -25,6 +25,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + customrun "github.com/tektoncd/pipeline/pkg/reconciler/customrun" "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" "github.com/tektoncd/pipeline/test" @@ -51,7 +52,7 @@ func initializeCustomRunControllerAssets(t *testing.T, d test.Data) (test.Assets test.EnsureConfigurationConfigMapsExist(&d) c, informers := test.SeedTestData(t, ctx, d) configMapWatcher := cminformer.NewInformedWatcher(c.Kube, system.Namespace()) - ctl := NewController()(ctx, configMapWatcher) + ctl := customrun.NewController()(ctx, configMapWatcher) if err := configMapWatcher.Start(ctx.Done()); err != nil { t.Fatalf("error starting configmap watcher: %v", err) } diff --git a/pkg/reconciler/events/cache/cache_test.go b/pkg/reconciler/events/cache/cache_test.go index 3efaf84139c..476b1149edd 100644 --- a/pkg/reconciler/events/cache/cache_test.go +++ b/pkg/reconciler/events/cache/cache_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cache +package cache_test import ( "net/url" @@ -27,6 +27,7 @@ import ( "github.com/google/go-cmp/cmp" lru "github.com/hashicorp/golang-lru" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + cache "github.com/tektoncd/pipeline/pkg/reconciler/events/cache" "github.com/tektoncd/pipeline/test/diff" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -97,7 +98,7 @@ func TestEventsKey(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { gotEvent := getEventToTest(tc.eventtype, tc.run) - gotKey, err := EventKey(gotEvent) + gotKey, err := cache.EventKey(gotEvent) if err != nil { if !tc.wantErr { t.Fatalf("Expecting an error, got none") @@ -145,8 +146,8 @@ func TestAddCheckEvent(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { testCache, _ := lru.New(10) - _, _ = ContainsOrAddCloudEvent(testCache, tc.firstEvent) - found, _ := ContainsOrAddCloudEvent(testCache, tc.secondEvent) + _, _ = cache.ContainsOrAddCloudEvent(testCache, tc.firstEvent) + found, _ := cache.ContainsOrAddCloudEvent(testCache, tc.secondEvent) if d := cmp.Diff(tc.wantFound, found); d != "" { t.Errorf("Cache check failure %s", diff.PrintWantGot(d)) } diff --git a/pkg/reconciler/events/event_test.go b/pkg/reconciler/events/event_test.go index ba350a20259..6557db364d0 100644 --- a/pkg/reconciler/events/event_test.go +++ b/pkg/reconciler/events/event_test.go @@ -14,13 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -package events +package events_test import ( "testing" "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + events "github.com/tektoncd/pipeline/pkg/reconciler/events" "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" "github.com/tektoncd/pipeline/pkg/reconciler/events/k8sevent" corev1 "k8s.io/api/core/v1" @@ -89,7 +90,7 @@ func TestEmit(t *testing.T) { ctx = config.ToContext(ctx, cfg) recorder := controller.GetEventRecorder(ctx).(*record.FakeRecorder) - Emit(ctx, nil, after, object) + events.Emit(ctx, nil, after, object) if err := k8sevent.CheckEventsOrdered(t, recorder.Events, tc.name, tc.wantEvents); err != nil { t.Fatalf(err.Error()) } diff --git a/pkg/reconciler/events/k8sevent/event_test.go b/pkg/reconciler/events/k8sevent/event_test.go index f5c446696b5..6c8603e78f2 100644 --- a/pkg/reconciler/events/k8sevent/event_test.go +++ b/pkg/reconciler/events/k8sevent/event_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package k8sevent +package k8sevent_test import ( "errors" @@ -23,6 +23,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + k8sevents "github.com/tektoncd/pipeline/pkg/reconciler/events/k8sevent" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/record" @@ -176,8 +177,8 @@ func TestEmitK8sEventsOnConditions(t *testing.T) { tr := &corev1.Pod{} ctx, _ := rtesting.SetupFakeContext(t) recorder := controller.GetEventRecorder(ctx).(*record.FakeRecorder) - EmitK8sEvents(ctx, ts.before, ts.after, tr) - err := CheckEventsOrdered(t, recorder.Events, ts.name, ts.wantEvents) + k8sevents.EmitK8sEvents(ctx, ts.before, ts.after, tr) + err := k8sevents.CheckEventsOrdered(t, recorder.Events, ts.name, ts.wantEvents) if err != nil { t.Errorf(err.Error()) } @@ -235,8 +236,8 @@ func TestEmitK8sEvents(t *testing.T) { ctx = config.ToContext(ctx, cfg) recorder := controller.GetEventRecorder(ctx).(*record.FakeRecorder) - EmitK8sEvents(ctx, nil, after, object) - if err := CheckEventsOrdered(t, recorder.Events, tc.name, tc.wantEvents); err != nil { + k8sevents.EmitK8sEvents(ctx, nil, after, object) + if err := k8sevents.CheckEventsOrdered(t, recorder.Events, tc.name, tc.wantEvents); err != nil { t.Fatalf(err.Error()) } } @@ -260,8 +261,8 @@ func TestEmitError(t *testing.T) { for _, ts := range testcases { fr := record.NewFakeRecorder(1) tr := &corev1.Pod{} - EmitError(fr, ts.err, tr) - err := CheckEventsOrdered(t, fr.Events, ts.name, ts.wantEvents) + k8sevents.EmitError(fr, ts.err, tr) + err := k8sevents.CheckEventsOrdered(t, fr.Events, ts.name, ts.wantEvents) if err != nil { t.Errorf(err.Error()) } diff --git a/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec_test.go b/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec_test.go index b14401de03d..d086371b028 100644 --- a/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec_test.go +++ b/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package pipelinespec +package pipelinespec_test import ( "context" @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp" cfgtesting "github.com/tektoncd/pipeline/pkg/apis/config/testing" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelinespec "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/pipelinespec" "github.com/tektoncd/pipeline/test/diff" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -55,7 +56,7 @@ func TestGetPipelineSpec_Ref(t *testing.T) { gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.RefSource, error) { return pipeline, nil, nil } - resolvedObjectMeta, pipelineSpec, err := GetPipelineData(context.Background(), pr, gt) + resolvedObjectMeta, pipelineSpec, err := pipelinespec.GetPipelineData(context.Background(), pr, gt) if err != nil { t.Fatalf("Did not expect error getting pipeline spec but got: %s", err) @@ -93,7 +94,7 @@ func TestGetPipelineSpec_Embedded(t *testing.T) { gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.RefSource, error) { return nil, nil, errors.New("shouldn't be called") } - resolvedObjectMeta, pipelineSpec, err := GetPipelineData(context.Background(), pr, gt) + resolvedObjectMeta, pipelineSpec, err := pipelinespec.GetPipelineData(context.Background(), pr, gt) if err != nil { t.Fatalf("Did not expect error getting pipeline spec but got: %s", err) @@ -121,7 +122,7 @@ func TestGetPipelineSpec_Invalid(t *testing.T) { gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.RefSource, error) { return nil, nil, errors.New("shouldn't be called") } - _, _, err := GetPipelineData(context.Background(), tr, gt) + _, _, err := pipelinespec.GetPipelineData(context.Background(), tr, gt) if err == nil { t.Fatalf("Expected error resolving spec with no embedded or referenced pipeline spec but didn't get error") } @@ -223,7 +224,7 @@ func TestGetPipelineData_ResolutionSuccess(t *testing.T) { }, tc.refSource.DeepCopy(), nil } - resolvedObjectMeta, resolvedPipelineSpec, err := GetPipelineData(ctx, tc.pr, getPipeline) + resolvedObjectMeta, resolvedPipelineSpec, err := pipelinespec.GetPipelineData(ctx, tc.pr, getPipeline) if err != nil { t.Fatalf("did not expect error getting pipeline spec but got: %s", err) } @@ -255,7 +256,7 @@ func TestGetPipelineSpec_Error(t *testing.T) { gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.RefSource, error) { return nil, nil, errors.New("something went wrong") } - _, _, err := GetPipelineData(context.Background(), tr, gt) + _, _, err := pipelinespec.GetPipelineData(context.Background(), tr, gt) if err == nil { t.Fatalf("Expected error when unable to find referenced Pipeline but got none") } @@ -278,7 +279,7 @@ func TestGetPipelineData_ResolutionError(t *testing.T) { return nil, nil, errors.New("something went wrong") } ctx := context.Background() - _, _, err := GetPipelineData(ctx, pr, getPipeline) + _, _, err := pipelinespec.GetPipelineData(ctx, pr, getPipeline) if err == nil { t.Fatalf("Expected error when unable to find referenced Pipeline but got none") } @@ -301,7 +302,7 @@ func TestGetPipelineData_ResolvedNilPipeline(t *testing.T) { return nil, nil, nil } ctx := context.Background() - _, _, err := GetPipelineData(ctx, pr, getPipeline) + _, _, err := pipelinespec.GetPipelineData(ctx, pr, getPipeline) if err == nil { t.Fatalf("Expected error when unable to find referenced Pipeline but got none") } diff --git a/pkg/reconciler/pipelinerun/resources/apply_test.go b/pkg/reconciler/pipelinerun/resources/apply_test.go index 82e64f7e0ab..45521ec70fd 100644 --- a/pkg/reconciler/pipelinerun/resources/apply_test.go +++ b/pkg/reconciler/pipelinerun/resources/apply_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package resources +package resources_test import ( "context" @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + resources "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources" "github.com/tektoncd/pipeline/test/diff" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/selection" @@ -1717,7 +1718,7 @@ func TestApplyParameters(t *testing.T) { Params: tt.params, }, } - got := ApplyParameters(ctx, &tt.original, run) + got := resources.ApplyParameters(ctx, &tt.original, run) if d := cmp.Diff(&tt.expected, got); d != "" { t.Errorf("ApplyParameters() got diff %s", diff.PrintWantGot(d)) } @@ -2026,7 +2027,7 @@ func TestApplyParameters_ArrayIndexing(t *testing.T) { Params: tt.params, }, } - got := ApplyParameters(ctx, &tt.original, run) + got := resources.ApplyParameters(ctx, &tt.original, run) if d := cmp.Diff(&tt.expected, got); d != "" { t.Errorf("ApplyParameters() got diff %s", diff.PrintWantGot(d)) } @@ -2282,7 +2283,7 @@ func TestApplyReplacementsMatrix(t *testing.T) { Params: tt.params, }, } - got := ApplyParameters(ctx, &tt.original, run) + got := resources.ApplyParameters(ctx, &tt.original, run) if d := cmp.Diff(&tt.expected, got); d != "" { t.Errorf("ApplyParameters() got diff %s", diff.PrintWantGot(d)) } @@ -2293,12 +2294,12 @@ func TestApplyReplacementsMatrix(t *testing.T) { func TestApplyTaskResults_MinimalExpression(t *testing.T) { for _, tt := range []struct { name string - targets PipelineRunState - resolvedResultRefs ResolvedResultRefs - want PipelineRunState + targets resources.PipelineRunState + resolvedResultRefs resources.ResolvedResultRefs + want resources.PipelineRunState }{{ name: "Test result substitution on minimal variable substitution expression - params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("aResultValue"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2306,7 +2307,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2316,7 +2317,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2328,7 +2329,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test array indexing result substitution on minimal variable substitution expression - params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2336,7 +2337,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2346,7 +2347,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2358,7 +2359,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test array indexing result substitution out of bound - params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2366,7 +2367,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2376,7 +2377,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2389,7 +2390,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test array result substitution on minimal variable substitution expression - params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2397,7 +2398,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2409,7 +2410,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2421,7 +2422,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test object result as a whole substitution - params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewObject(map[string]string{ "key1": "val1", "key2": "val2", @@ -2432,7 +2433,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2442,7 +2443,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2458,7 +2459,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test object result element substitution - params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewObject(map[string]string{ "key1": "val1", "key2": "val2", @@ -2469,7 +2470,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2479,7 +2480,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2492,7 +2493,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test result substitution on minimal variable substitution expression - matrix", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("aResultValue"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2500,7 +2501,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2511,7 +2512,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2524,7 +2525,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test array indexing result substitution on minimal variable substitution expression - matrix", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2532,7 +2533,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2543,7 +2544,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2556,7 +2557,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test array indexing result substitution out of bound - matrix", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2564,7 +2565,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2575,7 +2576,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2588,7 +2589,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test array result substitution on minimal variable substitution expression - when expressions", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2596,7 +2597,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2608,7 +2609,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2621,7 +2622,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test result substitution on minimal variable substitution expression - when expressions", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("aResultValue"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2629,7 +2630,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2640,7 +2641,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2653,7 +2654,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test array indexing result substitution on minimal variable substitution expression - when expressions", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2661,7 +2662,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2672,7 +2673,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2685,7 +2686,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test array result substitution on minimal variable substitution expression - resolver params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewArrayOrString("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2693,7 +2694,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ TaskRef: &v1beta1.TaskRef{ ResolverRef: v1beta1.ResolverRef{ @@ -2707,7 +2708,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ TaskRef: &v1beta1.TaskRef{ ResolverRef: v1beta1.ResolverRef{ @@ -2723,7 +2724,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test result substitution on minimal variable substitution expression - resolver params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewArrayOrString("aResultValue"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2731,7 +2732,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ TaskRef: &v1beta1.TaskRef{ ResolverRef: v1beta1.ResolverRef{ @@ -2743,7 +2744,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ TaskRef: &v1beta1.TaskRef{ ResolverRef: v1beta1.ResolverRef{ @@ -2757,7 +2758,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }, { name: "Test array indexing result substitution on minimal variable substitution expression - resolver params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewArrayOrString("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2765,7 +2766,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ TaskRef: &v1beta1.TaskRef{ ResolverRef: v1beta1.ResolverRef{ @@ -2780,7 +2781,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ TaskRef: &v1beta1.TaskRef{ ResolverRef: v1beta1.ResolverRef{ @@ -2797,7 +2798,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { }}, }} { t.Run(tt.name, func(t *testing.T) { - ApplyTaskResults(tt.targets, tt.resolvedResultRefs) + resources.ApplyTaskResults(tt.targets, tt.resolvedResultRefs) if d := cmp.Diff(tt.want, tt.targets); d != "" { t.Fatalf("ApplyTaskResults() %s", diff.PrintWantGot(d)) } @@ -2808,12 +2809,12 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { for _, tt := range []struct { name string - targets PipelineRunState - resolvedResultRefs ResolvedResultRefs - want PipelineRunState + targets resources.PipelineRunState + resolvedResultRefs resources.ResolvedResultRefs + want resources.PipelineRunState }{{ name: "Test result substitution on embedded variable substitution expression - params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("aResultValue"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2821,7 +2822,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2831,7 +2832,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2843,7 +2844,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}, }, { name: "Test array indexing result substitution on embedded variable substitution expression - params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2851,7 +2852,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2861,7 +2862,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2873,7 +2874,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}, }, { name: "Test result substitution on embedded variable substitution expression - matrix", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("aResultValue"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2881,7 +2882,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2892,7 +2893,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}}, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2905,7 +2906,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}, }, { name: "test result substitution for strings and arrays in matrix params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("foo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2931,7 +2932,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2943,7 +2944,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2957,7 +2958,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}, }, { name: "test result substitution for strings from string, arr, obj results in matrix include params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("foo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -2983,7 +2984,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -2998,7 +2999,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -3015,7 +3016,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}, }, { name: "Test result substitution on embedded variable substitution expression - when expressions", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("aResultValue"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -3023,7 +3024,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -3036,7 +3037,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -3049,7 +3050,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}, }, { name: "Test array indexing result substitution on embedded variable substitution expression - when expressions", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewStructuredValues("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -3057,7 +3058,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -3070,7 +3071,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, @@ -3083,7 +3084,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}, }, { name: "Test result substitution on embedded variable substitution expression - resolver params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewArrayOrString("aResultValue"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -3091,7 +3092,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ TaskRef: &v1beta1.TaskRef{ ResolverRef: v1beta1.ResolverRef{ @@ -3103,7 +3104,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ TaskRef: &v1beta1.TaskRef{ ResolverRef: v1beta1.ResolverRef{ @@ -3117,7 +3118,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}, }, { name: "Test array indexing result substitution on embedded variable substitution expression - resolver params", - resolvedResultRefs: ResolvedResultRefs{{ + resolvedResultRefs: resources.ResolvedResultRefs{{ Value: *v1beta1.NewArrayOrString("arrayResultValueOne", "arrayResultValueTwo"), ResultReference: v1beta1.ResultRef{ PipelineTask: "aTask", @@ -3125,7 +3126,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, FromTaskRun: "aTaskRun", }}, - targets: PipelineRunState{{ + targets: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ TaskRef: &v1beta1.TaskRef{ ResolverRef: v1beta1.ResolverRef{ @@ -3140,7 +3141,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }, }, }}, - want: PipelineRunState{{ + want: resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ TaskRef: &v1beta1.TaskRef{ ResolverRef: v1beta1.ResolverRef{ @@ -3157,7 +3158,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { }}, }} { t.Run(tt.name, func(t *testing.T) { - ApplyTaskResults(tt.targets, tt.resolvedResultRefs) + resources.ApplyTaskResults(tt.targets, tt.resolvedResultRefs) if d := cmp.Diff(tt.want, tt.targets); d != "" { t.Fatalf("ApplyTaskResults() %s", diff.PrintWantGot(d)) } @@ -3232,7 +3233,7 @@ func TestContext(t *testing.T) { }}}, }, } - got := ApplyContexts(&orig.Spec, orig.Name, tc.pr) + got := resources.ApplyContexts(&orig.Spec, orig.Name, tc.pr) if d := cmp.Diff(tc.expected, got.Tasks[0].Params[0]); d != "" { t.Errorf(diff.PrintWantGot(d)) } @@ -3332,7 +3333,7 @@ func TestApplyPipelineTaskContexts(t *testing.T) { }, }} { t.Run(tc.description, func(t *testing.T) { - got := ApplyPipelineTaskContexts(&tc.pt) + got := resources.ApplyPipelineTaskContexts(&tc.pt) if d := cmp.Diff(&tc.want, got); d != "" { t.Errorf(diff.PrintWantGot(d)) } @@ -3382,7 +3383,7 @@ func TestApplyWorkspaces(t *testing.T) { Workspaces: tc.bindings, }, } - p2 := ApplyWorkspaces(&p1, pr) + p2 := resources.ApplyWorkspaces(&p1, pr) str := p2.Tasks[0].Params[0].Value.StringVal if str != tc.expectedReplacement { t.Errorf("expected %q, received %q", tc.expectedReplacement, str) @@ -3497,7 +3498,7 @@ func TestApplyFinallyResultsToPipelineResults(t *testing.T) { }, } { t.Run(tc.description, func(t *testing.T) { - received, _ := ApplyTaskResultsToPipelineResults(context.Background(), tc.results, tc.taskResults, tc.runResults, nil /* skippedTasks */) + received, _ := resources.ApplyTaskResultsToPipelineResults(context.Background(), tc.results, tc.taskResults, tc.runResults, nil /* skippedTasks */) if d := cmp.Diff(tc.expected, received); d != "" { t.Errorf(diff.PrintWantGot(d)) } @@ -3794,7 +3795,7 @@ func TestApplyTaskResultsToPipelineResults_Success(t *testing.T) { expectedResults: nil, }} { t.Run(tc.description, func(t *testing.T) { - received, err := ApplyTaskResultsToPipelineResults(context.Background(), tc.results, tc.taskResults, tc.runResults, tc.skippedTasks) + received, err := resources.ApplyTaskResultsToPipelineResults(context.Background(), tc.results, tc.taskResults, tc.runResults, tc.skippedTasks) if err != nil { t.Errorf("Got unecpected error:%v", err) } @@ -4010,7 +4011,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) { expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"), }} { t.Run(tc.description, func(t *testing.T) { - received, err := ApplyTaskResultsToPipelineResults(context.Background(), tc.results, tc.taskResults, tc.runResults, nil /*skipped tasks*/) + received, err := resources.ApplyTaskResultsToPipelineResults(context.Background(), tc.results, tc.taskResults, tc.runResults, nil /*skipped tasks*/) if err == nil { t.Errorf("Expect error but got nil") } @@ -4031,7 +4032,7 @@ func TestApplyTaskRunContext(t *testing.T) { "tasks.task1.status": "succeeded", "tasks.task3.status": "none", } - state := PipelineRunState{{ + state := resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "task4", TaskRef: &v1beta1.TaskRef{Name: "task"}, @@ -4049,7 +4050,7 @@ func TestApplyTaskRunContext(t *testing.T) { }}, }, }} - expectedState := PipelineRunState{{ + expectedState := resources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "task4", TaskRef: &v1beta1.TaskRef{Name: "task"}, @@ -4067,7 +4068,7 @@ func TestApplyTaskRunContext(t *testing.T) { }}, }, }} - ApplyPipelineTaskStateContext(state, r) + resources.ApplyPipelineTaskStateContext(state, r) if d := cmp.Diff(expectedState, state); d != "" { t.Fatalf("ApplyTaskRunContext() %s", diff.PrintWantGot(d)) } diff --git a/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go b/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go index b6eed6658ed..dcbc87066d2 100644 --- a/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go @@ -5,7 +5,7 @@ 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 + 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, diff --git a/pkg/reconciler/pipelinerun/resources/validate_dependencies_test.go b/pkg/reconciler/pipelinerun/resources/validate_dependencies_test.go index 34604dabc18..037b0185a38 100644 --- a/pkg/reconciler/pipelinerun/resources/validate_dependencies_test.go +++ b/pkg/reconciler/pipelinerun/resources/validate_dependencies_test.go @@ -14,13 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -package resources +package resources_test import ( "strings" "testing" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + prresources "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" "k8s.io/apimachinery/pkg/selection" ) @@ -30,10 +31,10 @@ import ( func TestValidatePipelineTaskResults_ValidStates(t *testing.T) { for _, tc := range []struct { desc string - state PipelineRunState + state prresources.PipelineRunState }{{ desc: "no variables used", - state: PipelineRunState{{ + state: prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", Params: v1beta1.Params{{ @@ -44,7 +45,7 @@ func TestValidatePipelineTaskResults_ValidStates(t *testing.T) { }}, }, { desc: "correct use of task and result names", - state: PipelineRunState{{ + state: prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", }, @@ -67,7 +68,7 @@ func TestValidatePipelineTaskResults_ValidStates(t *testing.T) { }}, }, { desc: "correct use of task and result names in matrix", - state: PipelineRunState{{ + state: prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", }, @@ -91,7 +92,7 @@ func TestValidatePipelineTaskResults_ValidStates(t *testing.T) { }}, }, { desc: "custom task results are not validated", - state: PipelineRunState{{ + state: prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", }, @@ -108,7 +109,7 @@ func TestValidatePipelineTaskResults_ValidStates(t *testing.T) { }}, }} { t.Run(tc.desc, func(t *testing.T) { - if err := ValidatePipelineTaskResults(tc.state); err != nil { + if err := prresources.ValidatePipelineTaskResults(tc.state); err != nil { t.Errorf("unexpected error: %v", err) } }) @@ -121,10 +122,10 @@ func TestValidatePipelineTaskResults_IncorrectTaskName(t *testing.T) { missingPipelineTaskVariable := "$(tasks.pt2.results.result1)" for _, tc := range []struct { desc string - state PipelineRunState + state prresources.PipelineRunState }{{ desc: "invalid result reference in param", - state: PipelineRunState{{ + state: prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", Params: v1beta1.Params{{ @@ -135,7 +136,7 @@ func TestValidatePipelineTaskResults_IncorrectTaskName(t *testing.T) { }}, }, { desc: "invalid result reference in matrix", - state: PipelineRunState{{ + state: prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", Params: v1beta1.Params{{ @@ -146,7 +147,7 @@ func TestValidatePipelineTaskResults_IncorrectTaskName(t *testing.T) { }}, }, { desc: "invalid result reference in when expression", - state: PipelineRunState{{ + state: prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", WhenExpressions: []v1beta1.WhenExpression{{ @@ -160,7 +161,7 @@ func TestValidatePipelineTaskResults_IncorrectTaskName(t *testing.T) { }}, }} { t.Run(tc.desc, func(t *testing.T) { - err := ValidatePipelineTaskResults(tc.state) + err := prresources.ValidatePipelineTaskResults(tc.state) if err == nil || !strings.Contains(err.Error(), `referenced pipeline task "pt2" does not exist`) { t.Errorf("unexpected error: %v", err) } @@ -171,7 +172,7 @@ func TestValidatePipelineTaskResults_IncorrectTaskName(t *testing.T) { // TestValidatePipelineTaskResults_IncorrectResultName tests that a result variable with // a misnamed Result is correctly caught by the validatePipelineTaskResults func. func TestValidatePipelineTaskResults_IncorrectResultName(t *testing.T) { - pt1 := &ResolvedPipelineTask{ + pt1 := &prresources.ResolvedPipelineTask{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", }, @@ -186,10 +187,10 @@ func TestValidatePipelineTaskResults_IncorrectResultName(t *testing.T) { } for _, tc := range []struct { desc string - state PipelineRunState + state prresources.PipelineRunState }{{ desc: "invalid result reference in param", - state: PipelineRunState{pt1, { + state: prresources.PipelineRunState{pt1, { PipelineTask: &v1beta1.PipelineTask{ Name: "pt2", Params: v1beta1.Params{{ @@ -200,7 +201,7 @@ func TestValidatePipelineTaskResults_IncorrectResultName(t *testing.T) { }}, }, { desc: "invalid result reference in matrix", - state: PipelineRunState{pt1, { + state: prresources.PipelineRunState{pt1, { PipelineTask: &v1beta1.PipelineTask{ Name: "pt2", Matrix: &v1beta1.Matrix{ @@ -212,7 +213,7 @@ func TestValidatePipelineTaskResults_IncorrectResultName(t *testing.T) { }}, }, { desc: "invalid result reference in when expression", - state: PipelineRunState{pt1, { + state: prresources.PipelineRunState{pt1, { PipelineTask: &v1beta1.PipelineTask{ Name: "pt2", WhenExpressions: []v1beta1.WhenExpression{{ @@ -226,7 +227,7 @@ func TestValidatePipelineTaskResults_IncorrectResultName(t *testing.T) { }}, }} { t.Run(tc.desc, func(t *testing.T) { - err := ValidatePipelineTaskResults(tc.state) + err := prresources.ValidatePipelineTaskResults(tc.state) if err == nil || !strings.Contains(err.Error(), `"result1" is not a named result returned by pipeline task "pt1"`) { t.Errorf("unexpected error: %v", err) } @@ -237,7 +238,7 @@ func TestValidatePipelineTaskResults_IncorrectResultName(t *testing.T) { // TestValidatePipelineTaskResults_MissingTaskSpec tests that a malformed PipelineTask // with a name but no spec results in a validation error being returned. func TestValidatePipelineTaskResults_MissingTaskSpec(t *testing.T) { - pt1 := &ResolvedPipelineTask{ + pt1 := &prresources.ResolvedPipelineTask{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", }, @@ -246,7 +247,7 @@ func TestValidatePipelineTaskResults_MissingTaskSpec(t *testing.T) { TaskSpec: nil, }, } - state := PipelineRunState{pt1, { + state := prresources.PipelineRunState{pt1, { PipelineTask: &v1beta1.PipelineTask{ Name: "pt2", Params: v1beta1.Params{{ @@ -264,7 +265,7 @@ func TestValidatePipelineTaskResults_MissingTaskSpec(t *testing.T) { }}}, }, }} - err := ValidatePipelineTaskResults(state) + err := prresources.ValidatePipelineTaskResults(state) if err == nil || !strings.Contains(err.Error(), `task spec not found`) { t.Errorf("unexpected error: %v", err) } @@ -276,7 +277,7 @@ func TestValidatePipelineResults_ValidStates(t *testing.T) { for _, tc := range []struct { desc string spec *v1beta1.PipelineSpec - state PipelineRunState + state prresources.PipelineRunState }{{ desc: "no result variables", spec: &v1beta1.PipelineSpec{ @@ -294,7 +295,7 @@ func TestValidatePipelineResults_ValidStates(t *testing.T) { Value: *v1beta1.NewStructuredValues("test $(tasks.pt1.results.result1) 123"), }}, }, - state: PipelineRunState{{ + state: prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", }, @@ -309,7 +310,7 @@ func TestValidatePipelineResults_ValidStates(t *testing.T) { }}, }} { t.Run(tc.desc, func(t *testing.T) { - if err := ValidatePipelineResults(tc.spec, tc.state); err != nil { + if err := prresources.ValidatePipelineResults(tc.spec, tc.state); err != nil { t.Errorf("unexpected error: %v", err) } }) @@ -325,8 +326,8 @@ func TestValidatePipelineResults_IncorrectTaskName(t *testing.T) { Value: *v1beta1.NewStructuredValues("$(tasks.pt1.results.result1)"), }}, } - state := PipelineRunState{} - err := ValidatePipelineResults(spec, state) + state := prresources.PipelineRunState{} + err := prresources.ValidatePipelineResults(spec, state) if err == nil || !strings.Contains(err.Error(), `referenced pipeline task "pt1" does not exist`) { t.Errorf("unexpected error: %v", err) } @@ -341,7 +342,7 @@ func TestValidatePipelineResults_IncorrectResultName(t *testing.T) { Value: *v1beta1.NewStructuredValues("$(tasks.pt1.results.result1)"), }}, } - state := PipelineRunState{{ + state := prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", }, @@ -354,7 +355,7 @@ func TestValidatePipelineResults_IncorrectResultName(t *testing.T) { }, }, }} - err := ValidatePipelineResults(spec, state) + err := prresources.ValidatePipelineResults(spec, state) if err == nil || !strings.Contains(err.Error(), `"result1" is not a named result returned by pipeline task "pt1"`) { t.Errorf("unexpected error: %v", err) } @@ -366,11 +367,11 @@ func TestValidateOptionalWorkspaces_ValidStates(t *testing.T) { for _, tc := range []struct { desc string workspaces []v1beta1.PipelineWorkspaceDeclaration - state PipelineRunState + state prresources.PipelineRunState }{{ desc: "no workspaces declared", workspaces: nil, - state: PipelineRunState{{ + state: prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", Workspaces: nil, @@ -384,7 +385,7 @@ func TestValidateOptionalWorkspaces_ValidStates(t *testing.T) { }, { desc: "pipeline can omit workspace if task workspace is optional", workspaces: nil, - state: PipelineRunState{{ + state: prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", Workspaces: []v1beta1.WorkspacePipelineTaskBinding{}, @@ -404,7 +405,7 @@ func TestValidateOptionalWorkspaces_ValidStates(t *testing.T) { Name: "ws1", Optional: true, }}, - state: PipelineRunState{{ + state: prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", Workspaces: []v1beta1.WorkspacePipelineTaskBinding{{ @@ -423,7 +424,7 @@ func TestValidateOptionalWorkspaces_ValidStates(t *testing.T) { }}, }} { t.Run(tc.desc, func(t *testing.T) { - if err := ValidateOptionalWorkspaces(tc.workspaces, tc.state); err != nil { + if err := prresources.ValidateOptionalWorkspaces(tc.workspaces, tc.state); err != nil { t.Errorf("unexpected error: %v", err) } }) @@ -437,7 +438,7 @@ func TestValidateOptionalWorkspaces_NonOptionalTaskWorkspace(t *testing.T) { Name: "ws1", Optional: true, }} - state := PipelineRunState{{ + state := prresources.PipelineRunState{{ PipelineTask: &v1beta1.PipelineTask{ Name: "pt1", Workspaces: []v1beta1.WorkspacePipelineTaskBinding{{ @@ -454,7 +455,7 @@ func TestValidateOptionalWorkspaces_NonOptionalTaskWorkspace(t *testing.T) { }, }, }} - err := ValidateOptionalWorkspaces(workspaces, state) + err := prresources.ValidateOptionalWorkspaces(workspaces, state) if err == nil || !strings.Contains(err.Error(), `pipeline workspace "ws1" is marked optional but pipeline task "pt1" requires it be provided`) { t.Errorf("unexpected error: %v", err) } diff --git a/pkg/reconciler/pipelinerun/resources/validate_params_test.go b/pkg/reconciler/pipelinerun/resources/validate_params_test.go index e1fcef4df33..1057785a7b1 100644 --- a/pkg/reconciler/pipelinerun/resources/validate_params_test.go +++ b/pkg/reconciler/pipelinerun/resources/validate_params_test.go @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package resources +package resources_test import ( "testing" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + resources "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -54,7 +55,7 @@ func TestValidateParamTypesMatching_Valid(t *testing.T) { Spec: v1beta1.PipelineRunSpec{Params: tc.prp}, } - if err := ValidateParamTypesMatching(ps, pr); err != nil { + if err := resources.ValidateParamTypesMatching(ps, pr); err != nil { t.Errorf("Pipeline.Validate() returned error: %v", err) } }) @@ -102,7 +103,7 @@ func TestValidateParamTypesMatching_Invalid(t *testing.T) { Spec: v1beta1.PipelineRunSpec{Params: tc.prp}, } - if err := ValidateParamTypesMatching(ps, pr); err == nil { + if err := resources.ValidateParamTypesMatching(ps, pr); err == nil { t.Errorf("Expected to see error when validating PipelineRun/Pipeline param types but saw none") } }) @@ -144,7 +145,7 @@ func TestValidateRequiredParametersProvided_Valid(t *testing.T) { }, }} { t.Run(tc.name, func(t *testing.T) { - if err := ValidateRequiredParametersProvided(&tc.pp, &tc.prp); err != nil { + if err := resources.ValidateRequiredParametersProvided(&tc.pp, &tc.prp); err != nil { t.Errorf("Didn't expect to see error when validating valid PipelineRun parameters but got: %v", err) } }) @@ -178,7 +179,7 @@ func TestValidateRequiredParametersProvided_Invalid(t *testing.T) { }, }} { t.Run(tc.name, func(t *testing.T) { - if err := ValidateRequiredParametersProvided(&tc.pp, &tc.prp); err == nil { + if err := resources.ValidateRequiredParametersProvided(&tc.pp, &tc.prp); err == nil { t.Errorf("Expected to see error when validating invalid PipelineRun parameters but saw none") } }) @@ -230,7 +231,7 @@ func TestValidateObjectParamRequiredKeys_Invalid(t *testing.T) { }, }} { t.Run(tc.name, func(t *testing.T) { - if err := ValidateObjectParamRequiredKeys(tc.pp, tc.prp); err == nil { + if err := resources.ValidateObjectParamRequiredKeys(tc.pp, tc.prp); err == nil { t.Errorf("Expected to see error when validating invalid object parameter keys but saw none") } }) @@ -310,7 +311,7 @@ func TestValidateObjectParamRequiredKeys_Valid(t *testing.T) { }, }} { t.Run(tc.name, func(t *testing.T) { - if err := ValidateObjectParamRequiredKeys(tc.pp, tc.prp); err != nil { + if err := resources.ValidateObjectParamRequiredKeys(tc.pp, tc.prp); err != nil { t.Errorf("Didn't expect to see error when validating invalid object parameter keys but got: %v", err) } }) diff --git a/pkg/reconciler/resources_test.go b/pkg/reconciler/resources_test.go index 4e391d07536..8d17d0bf493 100644 --- a/pkg/reconciler/resources_test.go +++ b/pkg/reconciler/resources_test.go @@ -14,17 +14,23 @@ See the License for the specific language governing permissions and limitations under the License. */ -package reconciler +package reconciler_test import ( "testing" "time" + reconciler "github.com/tektoncd/pipeline/pkg/reconciler" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/kmeta" ) +const ( + // minimumResourceAge is the age at which resources stop being IsYoungResource. + minimumResourceAge = 5 * time.Second +) + func TestIsYoungResource(t *testing.T) { tests := []struct { name string @@ -56,7 +62,7 @@ func TestIsYoungResource(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - got := IsYoungResource(test.resource) + got := reconciler.IsYoungResource(test.resource) if got != test.want { t.Errorf("IsYoungResource() = %v, wanted %v", got, test.want) } diff --git a/pkg/resolution/common/context_test.go b/pkg/resolution/common/context_test.go index 92c09daf280..39453061848 100644 --- a/pkg/resolution/common/context_test.go +++ b/pkg/resolution/common/context_test.go @@ -5,7 +5,7 @@ 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 + 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, @@ -14,11 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package common +package common_test import ( "context" "testing" + + common "github.com/tektoncd/pipeline/pkg/resolution/common" ) func TestRequestNamespace(t *testing.T) { @@ -26,18 +28,18 @@ func TestRequestNamespace(t *testing.T) { namespaceB := "bar" ctx := context.Background() - ctx = InjectRequestNamespace(ctx, namespaceA) - if RequestNamespace(ctx) != namespaceA { + ctx = common.InjectRequestNamespace(ctx, namespaceA) + if common.RequestNamespace(ctx) != namespaceA { t.Fatalf("expected namespace to be stored as part of context") } - ctx = InjectRequestNamespace(ctx, namespaceB) - if RequestNamespace(ctx) != namespaceA { + ctx = common.InjectRequestNamespace(ctx, namespaceB) + if common.RequestNamespace(ctx) != namespaceA { t.Fatalf("expected stored namespace to be immutable once set") } ctx = context.Background() - if RequestNamespace(ctx) != "" { + if common.RequestNamespace(ctx) != "" { t.Fatalf("expected empty namespace returned if no value was previously injected") } } @@ -47,18 +49,18 @@ func TestRequestName(t *testing.T) { nameB := "bar" ctx := context.Background() - ctx = InjectRequestName(ctx, nameA) - if RequestName(ctx) != nameA { + ctx = common.InjectRequestName(ctx, nameA) + if common.RequestName(ctx) != nameA { t.Fatalf("expected namespace to be stored as part of context") } - ctx = InjectRequestNamespace(ctx, nameB) - if RequestName(ctx) != nameA { + ctx = common.InjectRequestNamespace(ctx, nameB) + if common.RequestName(ctx) != nameA { t.Fatalf("expected stored namespace to be immutable once set") } ctx = context.Background() - if RequestName(ctx) != "" { + if common.RequestName(ctx) != "" { t.Fatalf("expected empty namespace returned if no value was previously injected") } } diff --git a/pkg/resolution/common/errors_test.go b/pkg/resolution/common/errors_test.go index f73a5490fc2..32e221b9aa8 100644 --- a/pkg/resolution/common/errors_test.go +++ b/pkg/resolution/common/errors_test.go @@ -14,11 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package common +package common_test import ( "errors" "testing" + + common "github.com/tektoncd/pipeline/pkg/resolution/common" ) type TestError struct{} @@ -31,7 +33,7 @@ func (*TestError) Error() string { func TestResolutionErrorUnwrap(t *testing.T) { originalError := &TestError{} - resolutionError := NewError("", originalError) + resolutionError := common.NewError("", originalError) if !errors.Is(resolutionError, &TestError{}) { t.Errorf("resolution error expected to unwrap successfully") } @@ -39,7 +41,7 @@ func TestResolutionErrorUnwrap(t *testing.T) { func TestResolutionErrorMessage(t *testing.T) { originalError := errors.New("this is just a test message") - resolutionError := NewError("", originalError) + resolutionError := common.NewError("", originalError) if resolutionError.Error() != originalError.Error() { t.Errorf("resolution error message expected to equal that of original error") } diff --git a/pkg/resolution/resolver/bundle/resolver_test.go b/pkg/resolution/resolver/bundle/resolver_test.go index 4410f5f6b51..998b55e1258 100644 --- a/pkg/resolution/resolver/bundle/resolver_test.go +++ b/pkg/resolution/resolver/bundle/resolver_test.go @@ -14,7 +14,7 @@ limitations under the License. */ -package bundle +package bundle_test import ( "context" @@ -32,6 +32,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" resolutioncommon "github.com/tektoncd/pipeline/pkg/resolution/common" + bundle "github.com/tektoncd/pipeline/pkg/resolution/resolver/bundle" frtesting "github.com/tektoncd/pipeline/pkg/resolution/resolver/framework/testing" "github.com/tektoncd/pipeline/pkg/resolution/resolver/internal" "github.com/tektoncd/pipeline/test" @@ -44,30 +45,34 @@ import ( "sigs.k8s.io/yaml" ) +const ( + disabledError = "cannot handle resolution request, enable-bundles-resolver feature flag not true" +) + func TestGetSelector(t *testing.T) { - resolver := Resolver{} + resolver := bundle.Resolver{} sel := resolver.GetSelector(context.Background()) if typ, has := sel[resolutioncommon.LabelKeyResolverType]; !has { t.Fatalf("unexpected selector: %v", sel) - } else if typ != LabelValueBundleResolverType { + } else if typ != bundle.LabelValueBundleResolverType { t.Fatalf("unexpected type: %q", typ) } } func TestValidateParams(t *testing.T) { - resolver := Resolver{} + resolver := bundle.Resolver{} paramsWithTask := []pipelinev1beta1.Param{{ - Name: ParamKind, + Name: bundle.ParamKind, Value: *pipelinev1beta1.NewStructuredValues("task"), }, { - Name: ParamName, + Name: bundle.ParamName, Value: *pipelinev1beta1.NewStructuredValues("foo"), }, { - Name: ParamBundle, + Name: bundle.ParamBundle, Value: *pipelinev1beta1.NewStructuredValues("bar"), }, { - Name: ParamServiceAccount, + Name: bundle.ParamServiceAccount, Value: *pipelinev1beta1.NewStructuredValues("baz"), }} @@ -76,16 +81,16 @@ func TestValidateParams(t *testing.T) { } paramsWithPipeline := []pipelinev1beta1.Param{{ - Name: ParamKind, + Name: bundle.ParamKind, Value: *pipelinev1beta1.NewStructuredValues("pipeline"), }, { - Name: ParamName, + Name: bundle.ParamName, Value: *pipelinev1beta1.NewStructuredValues("foo"), }, { - Name: ParamBundle, + Name: bundle.ParamBundle, Value: *pipelinev1beta1.NewStructuredValues("bar"), }, { - Name: ParamServiceAccount, + Name: bundle.ParamServiceAccount, Value: *pipelinev1beta1.NewStructuredValues("baz"), }} if err := resolver.ValidateParams(context.Background(), paramsWithPipeline); err != nil { @@ -94,21 +99,21 @@ func TestValidateParams(t *testing.T) { } func TestValidateParamsDisabled(t *testing.T) { - resolver := Resolver{} + resolver := bundle.Resolver{} var err error params := []pipelinev1beta1.Param{{ - Name: ParamKind, + Name: bundle.ParamKind, Value: *pipelinev1beta1.NewStructuredValues("task"), }, { - Name: ParamName, + Name: bundle.ParamName, Value: *pipelinev1beta1.NewStructuredValues("foo"), }, { - Name: ParamBundle, + Name: bundle.ParamBundle, Value: *pipelinev1beta1.NewStructuredValues("bar"), }, { - Name: ParamServiceAccount, + Name: bundle.ParamServiceAccount, Value: *pipelinev1beta1.NewStructuredValues("baz"), }} err = resolver.ValidateParams(resolverDisabledContext(), params) @@ -122,18 +127,18 @@ func TestValidateParamsDisabled(t *testing.T) { } func TestValidateParamsMissing(t *testing.T) { - resolver := Resolver{} + resolver := bundle.Resolver{} var err error paramsMissingBundle := []pipelinev1beta1.Param{{ - Name: ParamKind, + Name: bundle.ParamKind, Value: *pipelinev1beta1.NewStructuredValues("task"), }, { - Name: ParamName, + Name: bundle.ParamName, Value: *pipelinev1beta1.NewStructuredValues("foo"), }, { - Name: ParamServiceAccount, + Name: bundle.ParamServiceAccount, Value: *pipelinev1beta1.NewStructuredValues("baz"), }} err = resolver.ValidateParams(context.Background(), paramsMissingBundle) @@ -142,13 +147,13 @@ func TestValidateParamsMissing(t *testing.T) { } paramsMissingName := []pipelinev1beta1.Param{{ - Name: ParamKind, + Name: bundle.ParamKind, Value: *pipelinev1beta1.NewStructuredValues("task"), }, { - Name: ParamBundle, + Name: bundle.ParamBundle, Value: *pipelinev1beta1.NewStructuredValues("bar"), }, { - Name: ParamServiceAccount, + Name: bundle.ParamServiceAccount, Value: *pipelinev1beta1.NewStructuredValues("baz"), }} err = resolver.ValidateParams(context.Background(), paramsMissingName) @@ -158,21 +163,21 @@ func TestValidateParamsMissing(t *testing.T) { } func TestResolveDisabled(t *testing.T) { - resolver := Resolver{} + resolver := bundle.Resolver{} var err error params := []pipelinev1beta1.Param{{ - Name: ParamKind, + Name: bundle.ParamKind, Value: *pipelinev1beta1.NewStructuredValues("task"), }, { - Name: ParamName, + Name: bundle.ParamName, Value: *pipelinev1beta1.NewStructuredValues("foo"), }, { - Name: ParamBundle, + Name: bundle.ParamBundle, Value: *pipelinev1beta1.NewStructuredValues("bar"), }, { - Name: ParamServiceAccount, + Name: bundle.ParamServiceAccount, Value: *pipelinev1beta1.NewStructuredValues("baz"), }} _, err = resolver.Resolve(resolverDisabledContext(), params) @@ -245,7 +250,7 @@ func TestResolve(t *testing.T) { // too many objects in bundle resolver test var tooManyObjs []runtime.Object - for i := 0; i <= MaximumBundleObjects; i++ { + for i := 0; i <= bundle.MaximumBundleObjects; i++ { name := fmt.Sprintf("%d-task", i) obj := pipelinev1beta1.Task{ ObjectMeta: metav1.ObjectMeta{ @@ -348,7 +353,7 @@ func TestResolve(t *testing.T) { kind: "task", }, expectedStatus: internal.CreateResolutionRequestFailureStatus(), - expectedErrMessage: fmt.Sprintf("contained more than the maximum %d allow objects", MaximumBundleObjects), + expectedErrMessage: fmt.Sprintf("contained more than the maximum %d allow objects", bundle.MaximumBundleObjects), }, { name: "single task no version", args: ¶ms{ @@ -357,7 +362,7 @@ func TestResolve(t *testing.T) { kind: "task", }, expectedStatus: internal.CreateResolutionRequestFailureStatus(), - expectedErrMessage: fmt.Sprintf("the layer 0 does not contain a %s annotation", BundleAnnotationAPIVersion), + expectedErrMessage: fmt.Sprintf("the layer 0 does not contain a %s annotation", bundle.BundleAnnotationAPIVersion), }, { name: "single task no kind", args: ¶ms{ @@ -366,7 +371,7 @@ func TestResolve(t *testing.T) { kind: "task", }, expectedStatus: internal.CreateResolutionRequestFailureStatus(), - expectedErrMessage: fmt.Sprintf("the layer 0 does not contain a %s annotation", BundleAnnotationKind), + expectedErrMessage: fmt.Sprintf("the layer 0 does not contain a %s annotation", bundle.BundleAnnotationKind), }, { name: "single task no name", args: ¶ms{ @@ -375,7 +380,7 @@ func TestResolve(t *testing.T) { kind: "task", }, expectedStatus: internal.CreateResolutionRequestFailureStatus(), - expectedErrMessage: fmt.Sprintf("the layer 0 does not contain a %s annotation", BundleAnnotationName), + expectedErrMessage: fmt.Sprintf("the layer 0 does not contain a %s annotation", bundle.BundleAnnotationName), }, { name: "single task kind incorrect form", args: ¶ms{ @@ -384,16 +389,16 @@ func TestResolve(t *testing.T) { kind: "task", }, expectedStatus: internal.CreateResolutionRequestFailureStatus(), - expectedErrMessage: fmt.Sprintf("the layer 0 the annotation %s must be lowercased and singular, found %s", BundleAnnotationKind, "Task"), + expectedErrMessage: fmt.Sprintf("the layer 0 the annotation %s must be lowercased and singular, found %s", bundle.BundleAnnotationKind, "Task"), }, } - resolver := &Resolver{} + resolver := &bundle.Resolver{} confMap := map[string]string{ - ConfigKind: "task", + bundle.ConfigKind: "task", // service account is not used in testing, but we have to set this since // param validation will check if the service account is set either from param or from configmap. - ConfigServiceAccount: "placeholder", + bundle.ConfigServiceAccount: "placeholder", } for _, tc := range testcases { @@ -406,7 +411,7 @@ func TestResolve(t *testing.T) { ResolutionRequests: []*v1beta1.ResolutionRequest{request}, ConfigMaps: []*corev1.ConfigMap{{ ObjectMeta: metav1.ObjectMeta{ - Name: ConfigMapName, + Name: bundle.ConfigMapName, Namespace: resolverconfig.ResolversNamespace(system.Namespace()), }, Data: confMap, @@ -431,15 +436,15 @@ func TestResolve(t *testing.T) { switch { case tc.kindInBundle != "": - expectedStatus.Annotations[ResolverAnnotationKind] = tc.kindInBundle + expectedStatus.Annotations[bundle.ResolverAnnotationKind] = tc.kindInBundle case tc.args.kind != "": - expectedStatus.Annotations[ResolverAnnotationKind] = tc.args.kind + expectedStatus.Annotations[bundle.ResolverAnnotationKind] = tc.args.kind default: - expectedStatus.Annotations[ResolverAnnotationKind] = "task" + expectedStatus.Annotations[bundle.ResolverAnnotationKind] = "task" } - expectedStatus.Annotations[ResolverAnnotationName] = tc.args.name - expectedStatus.Annotations[ResolverAnnotationAPIVersion] = "v1beta1" + expectedStatus.Annotations[bundle.ResolverAnnotationName] = tc.args.name + expectedStatus.Annotations[bundle.ResolverAnnotationAPIVersion] = "v1beta1" expectedStatus.RefSource = &pipelinev1beta1.RefSource{ URI: testImages[tc.imageName].uri, @@ -471,21 +476,21 @@ func createRequest(p *params) *v1beta1.ResolutionRequest { Namespace: "foo", CreationTimestamp: metav1.Time{Time: time.Now()}, Labels: map[string]string{ - resolutioncommon.LabelKeyResolverType: LabelValueBundleResolverType, + resolutioncommon.LabelKeyResolverType: bundle.LabelValueBundleResolverType, }, }, Spec: v1beta1.ResolutionRequestSpec{ Params: []pipelinev1beta1.Param{{ - Name: ParamBundle, + Name: bundle.ParamBundle, Value: *pipelinev1beta1.NewStructuredValues(p.bundle), }, { - Name: ParamName, + Name: bundle.ParamName, Value: *pipelinev1beta1.NewStructuredValues(p.name), }, { - Name: ParamKind, + Name: bundle.ParamKind, Value: *pipelinev1beta1.NewStructuredValues(p.kind), }, { - Name: ParamServiceAccount, + Name: bundle.ParamServiceAccount, Value: *pipelinev1beta1.NewStructuredValues(p.serviceAccount), }}, }, @@ -495,7 +500,7 @@ func createRequest(p *params) *v1beta1.ResolutionRequest { func createError(image, msg string) error { return &resolutioncommon.GetResourceError{ - ResolverName: BundleResolverName, + ResolverName: bundle.BundleResolverName, Key: "foo/rr", Original: fmt.Errorf("invalid tekton bundle %s, error: %s", image, msg), } @@ -504,14 +509,14 @@ func createError(image, msg string) error { func asIsMapper(obj runtime.Object) map[string]string { annotations := map[string]string{} if test.GetObjectName(obj) != "" { - annotations[BundleAnnotationName] = test.GetObjectName(obj) + annotations[bundle.BundleAnnotationName] = test.GetObjectName(obj) } if obj.GetObjectKind().GroupVersionKind().Kind != "" { - annotations[BundleAnnotationKind] = obj.GetObjectKind().GroupVersionKind().Kind + annotations[bundle.BundleAnnotationKind] = obj.GetObjectKind().GroupVersionKind().Kind } if obj.GetObjectKind().GroupVersionKind().Version != "" { - annotations[BundleAnnotationAPIVersion] = obj.GetObjectKind().GroupVersionKind().Version + annotations[bundle.BundleAnnotationAPIVersion] = obj.GetObjectKind().GroupVersionKind().Version } return annotations } diff --git a/pkg/resolution/resolver/cluster/resolver_test.go b/pkg/resolution/resolver/cluster/resolver_test.go index aabf1172c65..0a6a5baddb4 100644 --- a/pkg/resolution/resolver/cluster/resolver_test.go +++ b/pkg/resolution/resolver/cluster/resolver_test.go @@ -15,7 +15,7 @@ */ -package cluster +package cluster_test import ( "context" @@ -32,6 +32,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" resolutioncommon "github.com/tektoncd/pipeline/pkg/resolution/common" + cluster "github.com/tektoncd/pipeline/pkg/resolution/resolver/cluster" "github.com/tektoncd/pipeline/pkg/resolution/resolver/framework" frtesting "github.com/tektoncd/pipeline/pkg/resolution/resolver/framework/testing" "github.com/tektoncd/pipeline/pkg/resolution/resolver/internal" @@ -45,33 +46,37 @@ import ( "sigs.k8s.io/yaml" ) +const ( + disabledError = "cannot handle resolution request, enable-cluster-resolver feature flag not true" +) + func TestGetSelector(t *testing.T) { - resolver := Resolver{} + resolver := cluster.Resolver{} sel := resolver.GetSelector(context.Background()) if typ, has := sel[resolutioncommon.LabelKeyResolverType]; !has { t.Fatalf("unexpected selector: %v", sel) - } else if typ != LabelValueClusterResolverType { + } else if typ != cluster.LabelValueClusterResolverType { t.Fatalf("unexpected type: %q", typ) } } func TestValidateParams(t *testing.T) { - resolver := Resolver{} + resolver := cluster.Resolver{} params := []pipelinev1beta1.Param{{ - Name: KindParam, + Name: cluster.KindParam, Value: *pipelinev1beta1.NewStructuredValues("task"), }, { - Name: NamespaceParam, + Name: cluster.NamespaceParam, Value: *pipelinev1beta1.NewStructuredValues("foo"), }, { - Name: NameParam, + Name: cluster.NameParam, Value: *pipelinev1beta1.NewStructuredValues("baz"), }} ctx := framework.InjectResolverConfigToContext(context.Background(), map[string]string{ - AllowedNamespacesKey: "foo,bar", - BlockedNamespacesKey: "abc,def", + cluster.AllowedNamespacesKey: "foo,bar", + cluster.BlockedNamespacesKey: "abc,def", }) if err := resolver.ValidateParams(ctx, params); err != nil { @@ -80,18 +85,18 @@ func TestValidateParams(t *testing.T) { } func TestValidateParamsNotEnabled(t *testing.T) { - resolver := Resolver{} + resolver := cluster.Resolver{} var err error params := []pipelinev1beta1.Param{{ - Name: KindParam, + Name: cluster.KindParam, Value: *pipelinev1beta1.NewStructuredValues("task"), }, { - Name: NamespaceParam, + Name: cluster.NamespaceParam, Value: *pipelinev1beta1.NewStructuredValues("foo"), }, { - Name: NameParam, + Name: cluster.NameParam, Value: *pipelinev1beta1.NewStructuredValues("baz"), }} err = resolver.ValidateParams(resolverDisabledContext(), params) @@ -113,44 +118,44 @@ func TestValidateParamsFailure(t *testing.T) { { name: "missing kind", params: map[string]string{ - NameParam: "foo", - NamespaceParam: "bar", + cluster.NameParam: "foo", + cluster.NamespaceParam: "bar", }, expectedErr: "missing required cluster resolver params: kind", }, { name: "invalid kind", params: map[string]string{ - KindParam: "banana", - NamespaceParam: "foo", - NameParam: "bar", + cluster.KindParam: "banana", + cluster.NamespaceParam: "foo", + cluster.NameParam: "bar", }, expectedErr: "unknown or unsupported resource kind 'banana'", }, { name: "missing multiple", params: map[string]string{ - KindParam: "task", + cluster.KindParam: "task", }, expectedErr: "missing required cluster resolver params: name, namespace", }, { name: "not in allowed namespaces", params: map[string]string{ - KindParam: "task", - NamespaceParam: "foo", - NameParam: "baz", + cluster.KindParam: "task", + cluster.NamespaceParam: "foo", + cluster.NameParam: "baz", }, conf: map[string]string{ - AllowedNamespacesKey: "abc,def", + cluster.AllowedNamespacesKey: "abc,def", }, expectedErr: "access to specified namespace foo is not allowed", }, { name: "in blocked namespaces", params: map[string]string{ - KindParam: "task", - NamespaceParam: "foo", - NameParam: "baz", + cluster.KindParam: "task", + cluster.NamespaceParam: "foo", + cluster.NameParam: "baz", }, conf: map[string]string{ - BlockedNamespacesKey: "foo,bar", + cluster.BlockedNamespacesKey: "foo,bar", }, expectedErr: "access to specified namespace foo is blocked", }, @@ -158,7 +163,7 @@ func TestValidateParamsFailure(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - resolver := &Resolver{} + resolver := &cluster.Resolver{} ctx := context.Background() if len(tc.conf) > 0 { @@ -351,7 +356,7 @@ func TestResolve(t *testing.T) { namespace: "other-ns", expectedStatus: internal.CreateResolutionRequestFailureStatus(), expectedErr: &resolutioncommon.GetResourceError{ - ResolverName: ClusterResolverName, + ResolverName: cluster.ClusterResolverName, Key: "foo/rr", Original: errors.New(`tasks.tekton.dev "example-task" not found`), }, @@ -387,20 +392,20 @@ func TestResolve(t *testing.T) { request := createRequest(tc.kind, tc.resourceName, tc.namespace) confMap := map[string]string{ - DefaultKindKey: "task", - DefaultNamespaceKey: defaultNS, + cluster.DefaultKindKey: "task", + cluster.DefaultNamespaceKey: defaultNS, } if tc.allowedNamespaces != "" { - confMap[AllowedNamespacesKey] = tc.allowedNamespaces + confMap[cluster.AllowedNamespacesKey] = tc.allowedNamespaces } if tc.blockedNamespaces != "" { - confMap[BlockedNamespacesKey] = tc.blockedNamespaces + confMap[cluster.BlockedNamespacesKey] = tc.blockedNamespaces } d := test.Data{ ConfigMaps: []*corev1.ConfigMap{{ ObjectMeta: metav1.ObjectMeta{ - Name: configMapName, + Name: "cluster-resolver-config", Namespace: resolverconfig.ResolversNamespace(system.Namespace()), }, Data: confMap, @@ -418,7 +423,7 @@ func TestResolve(t *testing.T) { Tasks: []*pipelinev1beta1.Task{exampleTask}, } - resolver := &Resolver{} + resolver := &cluster.Resolver{} var expectedStatus *v1beta1.ResolutionRequestStatus if tc.expectedStatus != nil { @@ -432,11 +437,11 @@ func TestResolve(t *testing.T) { if expectedStatus.Annotations == nil { expectedStatus.Annotations = make(map[string]string) } - expectedStatus.Annotations[ResourceNameAnnotation] = reqParams[NameParam].StringVal - if reqParams[NamespaceParam].StringVal != "" { - expectedStatus.Annotations[ResourceNamespaceAnnotation] = reqParams[NamespaceParam].StringVal + expectedStatus.Annotations[cluster.ResourceNameAnnotation] = reqParams[cluster.NameParam].StringVal + if reqParams[cluster.NamespaceParam].StringVal != "" { + expectedStatus.Annotations[cluster.ResourceNamespaceAnnotation] = reqParams[cluster.NamespaceParam].StringVal } else { - expectedStatus.Annotations[ResourceNamespaceAnnotation] = defaultNS + expectedStatus.Annotations[cluster.ResourceNamespaceAnnotation] = defaultNS } } else { expectedStatus.Status.Conditions[0].Message = tc.expectedErr.Error() @@ -459,25 +464,25 @@ func createRequest(kind, name, namespace string) *v1beta1.ResolutionRequest { Namespace: "foo", CreationTimestamp: metav1.Time{Time: time.Now()}, Labels: map[string]string{ - resolutioncommon.LabelKeyResolverType: LabelValueClusterResolverType, + resolutioncommon.LabelKeyResolverType: cluster.LabelValueClusterResolverType, }, }, Spec: v1beta1.ResolutionRequestSpec{ Params: []pipelinev1beta1.Param{{ - Name: NameParam, + Name: cluster.NameParam, Value: *pipelinev1beta1.NewStructuredValues(name), }}, }, } if kind != "" { rr.Spec.Params = append(rr.Spec.Params, pipelinev1beta1.Param{ - Name: KindParam, + Name: cluster.KindParam, Value: *pipelinev1beta1.NewStructuredValues(kind), }) } if namespace != "" { rr.Spec.Params = append(rr.Spec.Params, pipelinev1beta1.Param{ - Name: NamespaceParam, + Name: cluster.NamespaceParam, Value: *pipelinev1beta1.NewStructuredValues(namespace), }) } diff --git a/pkg/resolution/resolver/framework/configstore_test.go b/pkg/resolution/resolver/framework/configstore_test.go index 34bc82e39d3..ad2b58890ae 100644 --- a/pkg/resolution/resolver/framework/configstore_test.go +++ b/pkg/resolution/resolver/framework/configstore_test.go @@ -14,13 +14,13 @@ limitations under the License. */ -package framework +package framework_test import ( "testing" + framework "github.com/tektoncd/pipeline/pkg/resolution/resolver/framework" corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/configmap" logtesting "knative.dev/pkg/logging/testing" ) @@ -53,7 +53,7 @@ func TestDataFromConfigMap(t *testing.T) { "foo": "bar", }, }} { - out, err := DataFromConfigMap(tc.configMap) + out, err := framework.DataFromConfigMap(tc.configMap) if err != nil { t.Fatalf("unexpected error: %v", err) } @@ -64,15 +64,9 @@ func TestDataFromConfigMap(t *testing.T) { } func TestGetResolverConfig(t *testing.T) { - _ = &ConfigStore{ - resolverConfigName: "test", - untyped: configmap.NewUntypedStore( - "test-config", - logtesting.TestLogger(t), - configmap.Constructors{ - "test": DataFromConfigMap, - }, - ), + config := framework.NewConfigStore("test", logtesting.TestLogger(t)) + if len(config.GetResolverConfig()) != 0 { + t.Fatalf("expected empty config") } } diff --git a/pkg/resolution/resolver/framework/reconciler_test.go b/pkg/resolution/resolver/framework/reconciler_test.go index 89948726744..a871c232b0e 100644 --- a/pkg/resolution/resolver/framework/reconciler_test.go +++ b/pkg/resolution/resolver/framework/reconciler_test.go @@ -14,7 +14,7 @@ limitations under the License. */ -package framework +package framework_test import ( "context" @@ -30,6 +30,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" resolutioncommon "github.com/tektoncd/pipeline/pkg/resolution/common" + framework "github.com/tektoncd/pipeline/pkg/resolution/resolver/framework" "github.com/tektoncd/pipeline/test" "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" @@ -57,7 +58,7 @@ func TestReconcile(t *testing.T) { testCases := []struct { name string inputRequest *v1beta1.ResolutionRequest - paramMap map[string]*FakeResolvedResource + paramMap map[string]*framework.FakeResolvedResource reconcilerTimeout time.Duration expectedStatus *v1beta1.ResolutionRequestStatus expectedErr error @@ -74,12 +75,12 @@ func TestReconcile(t *testing.T) { Namespace: "foo", CreationTimestamp: metav1.Time{Time: time.Now()}, Labels: map[string]string{ - resolutioncommon.LabelKeyResolverType: LabelValueFakeResolverType, + resolutioncommon.LabelKeyResolverType: framework.LabelValueFakeResolverType, }, }, Spec: v1beta1.ResolutionRequestSpec{ Params: []pipelinev1beta1.Param{{ - Name: FakeParamName, + Name: framework.FakeParamName, Value: *pipelinev1beta1.NewStructuredValues("bar"), }}, }, @@ -98,18 +99,18 @@ func TestReconcile(t *testing.T) { Namespace: "foo", CreationTimestamp: metav1.Time{Time: time.Now()}, Labels: map[string]string{ - resolutioncommon.LabelKeyResolverType: LabelValueFakeResolverType, + resolutioncommon.LabelKeyResolverType: framework.LabelValueFakeResolverType, }, }, Spec: v1beta1.ResolutionRequestSpec{ Params: []pipelinev1beta1.Param{{ - Name: FakeParamName, + Name: framework.FakeParamName, Value: *pipelinev1beta1.NewStructuredValues("bar"), }}, }, Status: v1beta1.ResolutionRequestStatus{}, }, - paramMap: map[string]*FakeResolvedResource{ + paramMap: map[string]*framework.FakeResolvedResource{ "bar": { Content: "some content", AnnotationMap: map[string]string{"foo": "bar"}, @@ -158,18 +159,18 @@ func TestReconcile(t *testing.T) { Namespace: "foo", CreationTimestamp: metav1.Time{Time: time.Now()}, Labels: map[string]string{ - resolutioncommon.LabelKeyResolverType: LabelValueFakeResolverType, + resolutioncommon.LabelKeyResolverType: framework.LabelValueFakeResolverType, }, }, Spec: v1beta1.ResolutionRequestSpec{ Params: []pipelinev1beta1.Param{{ - Name: FakeParamName, + Name: framework.FakeParamName, Value: *pipelinev1beta1.NewStructuredValues("bar"), }}, }, Status: v1beta1.ResolutionRequestStatus{}, }, - paramMap: map[string]*FakeResolvedResource{ + paramMap: map[string]*framework.FakeResolvedResource{ "bar": { ErrorWith: "fake failure", }, @@ -187,18 +188,18 @@ func TestReconcile(t *testing.T) { Namespace: "foo", CreationTimestamp: metav1.Time{Time: time.Now().Add(-59 * time.Second)}, // 1 second before default timeout Labels: map[string]string{ - resolutioncommon.LabelKeyResolverType: LabelValueFakeResolverType, + resolutioncommon.LabelKeyResolverType: framework.LabelValueFakeResolverType, }, }, Spec: v1beta1.ResolutionRequestSpec{ Params: []pipelinev1beta1.Param{{ - Name: FakeParamName, + Name: framework.FakeParamName, Value: *pipelinev1beta1.NewStructuredValues("bar"), }}, }, Status: v1beta1.ResolutionRequestStatus{}, }, - paramMap: map[string]*FakeResolvedResource{ + paramMap: map[string]*framework.FakeResolvedResource{ "bar": { WaitFor: 1100 * time.Millisecond, }, @@ -214,7 +215,7 @@ func TestReconcile(t *testing.T) { ResolutionRequests: []*v1beta1.ResolutionRequest{tc.inputRequest}, } - fakeResolver := &FakeResolver{ForParam: tc.paramMap} + fakeResolver := &framework.FakeResolver{ForParam: tc.paramMap} if tc.reconcilerTimeout > 0 { fakeResolver.Timeout = tc.reconcilerTimeout } @@ -251,14 +252,14 @@ func TestReconcile(t *testing.T) { } } -func getResolverFrameworkController(ctx context.Context, t *testing.T, d test.Data, resolver Resolver, modifiers ...ReconcilerModifier) (test.Assets, func()) { +func getResolverFrameworkController(ctx context.Context, t *testing.T, d test.Data, resolver framework.Resolver, modifiers ...framework.ReconcilerModifier) (test.Assets, func()) { t.Helper() names.TestingSeed() ctx, cancel := context.WithCancel(ctx) c, informers := test.SeedTestData(t, ctx, d) configMapWatcher := cminformer.NewInformedWatcher(c.Kube, system.Namespace()) - ctl := NewController(ctx, resolver, modifiers...)(ctx, configMapWatcher) + ctl := framework.NewController(ctx, resolver, modifiers...)(ctx, configMapWatcher) if err := configMapWatcher.Start(ctx.Done()); err != nil { t.Fatalf("error starting configmap watcher: %v", err) } @@ -281,7 +282,7 @@ func getRequestName(rr *v1beta1.ResolutionRequest) string { return strings.Join([]string{rr.Namespace, rr.Name}, "/") } -func setClockOnReconciler(r *Reconciler) { +func setClockOnReconciler(r *framework.Reconciler) { if r.Clock == nil { r.Clock = testClock } diff --git a/pkg/status/status_test.go b/pkg/status/status_test.go index 3a93c366c10..67309b6b4a3 100644 --- a/pkg/status/status_test.go +++ b/pkg/status/status_test.go @@ -15,7 +15,7 @@ */ -package status +package status_test import ( "errors" @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" + status "github.com/tektoncd/pipeline/pkg/status" "github.com/tektoncd/pipeline/test" "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/parse" @@ -100,7 +101,7 @@ status: } clients, _ := test.SeedTestData(t, ctx, d) - trStatus, err := GetTaskRunStatusForPipelineTask(ctx, clients.Pipeline, "", tc.childRef) + trStatus, err := status.GetTaskRunStatusForPipelineTask(ctx, clients.Pipeline, "", tc.childRef) if tc.expectedErr != nil { if err == nil { @@ -183,7 +184,7 @@ status: } clients, _ := test.SeedTestData(t, ctx, d) - runStatus, err := GetCustomRunStatusForPipelineTask(ctx, clients.Pipeline, "", tc.childRef) + runStatus, err := status.GetCustomRunStatusForPipelineTask(ctx, clients.Pipeline, "", tc.childRef) if tc.expectedErr != nil { if err == nil { @@ -353,7 +354,7 @@ pr-run-1: d.CustomRuns = append(d.CustomRuns, tc.runs...) clients, _ := test.SeedTestData(t, ctx, d) - trStatuses, runStatuses, err := GetPipelineTaskStatuses(ctx, clients.Pipeline, "", tc.originalPR) + trStatuses, runStatuses, err := status.GetPipelineTaskStatuses(ctx, clients.Pipeline, "", tc.originalPR) if tc.expectedErr != nil { if err == nil { diff --git a/pkg/termination/parse_test.go b/pkg/termination/parse_test.go index 3d701ea00be..42e44d5c2ba 100644 --- a/pkg/termination/parse_test.go +++ b/pkg/termination/parse_test.go @@ -13,7 +13,7 @@ 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 termination +package termination_test import ( "strings" @@ -21,6 +21,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/result" + termination "github.com/tektoncd/pipeline/pkg/termination" "github.com/tektoncd/pipeline/test/diff" "knative.dev/pkg/logging" ) @@ -81,7 +82,7 @@ func TestParseMessage(t *testing.T) { }} { t.Run(c.desc, func(t *testing.T) { logger, _ := logging.NewLogger("", "status") - got, err := ParseMessage(logger, c.msg) + got, err := termination.ParseMessage(logger, c.msg) if err != nil { t.Fatalf("ParseMessage: %v", err) } @@ -102,7 +103,7 @@ func TestParseMessageInvalidMessage(t *testing.T) { }} { t.Run(c.desc, func(t *testing.T) { logger, _ := logging.NewLogger("", "status") - _, err := ParseMessage(logger, c.msg) + _, err := termination.ParseMessage(logger, c.msg) if err == nil { t.Errorf("Expected error parsing incorrect termination message, got nil") } diff --git a/pkg/termination/write_test.go b/pkg/termination/write_test.go index 19deb600ad8..0cd5bf7ab58 100644 --- a/pkg/termination/write_test.go +++ b/pkg/termination/write_test.go @@ -13,7 +13,7 @@ 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 termination +package termination_test import ( "errors" @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/result" + termination "github.com/tektoncd/pipeline/pkg/termination" "github.com/tektoncd/pipeline/test/diff" "knative.dev/pkg/logging" ) @@ -45,7 +46,7 @@ func TestExistingFile(t *testing.T) { Value: "hello", }} - if err := WriteMessage(tmpFile.Name(), output); err != nil { + if err := termination.WriteMessage(tmpFile.Name(), output); err != nil { logger.Fatalf("Errot while writing message: %s", err) } @@ -54,7 +55,7 @@ func TestExistingFile(t *testing.T) { Value: "world", }} - if err := WriteMessage(tmpFile.Name(), output); err != nil { + if err := termination.WriteMessage(tmpFile.Name(), output); err != nil { logger.Fatalf("Errot while writing message: %s", err) } @@ -82,7 +83,9 @@ func TestMaxSizeFile(t *testing.T) { Value: value, }} - if err := WriteMessage(tmpFile.Name(), output); !errors.Is(err, errTooLong) { + err = termination.WriteMessage(tmpFile.Name(), output) + var expectedErr termination.MessageLengthError + if !errors.As(err, &expectedErr) { t.Fatalf("Expected MessageLengthError, received: %v", err) } } diff --git a/pkg/workspace/validate_test.go b/pkg/workspace/validate_test.go index 4adc62f4e68..d7cc172e37c 100644 --- a/pkg/workspace/validate_test.go +++ b/pkg/workspace/validate_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package workspace +package workspace_test import ( "context" @@ -22,6 +22,7 @@ import ( "testing" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + workspace "github.com/tektoncd/pipeline/pkg/workspace" corev1 "k8s.io/api/core/v1" ) @@ -77,7 +78,7 @@ func TestValidateBindingsValid(t *testing.T) { bindings: []v1beta1.WorkspaceBinding{}, }} { t.Run(tc.name, func(t *testing.T) { - if err := ValidateBindings(context.Background(), tc.declarations, tc.bindings); err != nil { + if err := workspace.ValidateBindings(context.Background(), tc.declarations, tc.bindings); err != nil { t.Errorf("didnt expect error for valid bindings but got: %v", err) } }) @@ -153,7 +154,7 @@ func TestValidateBindingsInvalid(t *testing.T) { }}, }} { t.Run(tc.name, func(t *testing.T) { - if err := ValidateBindings(context.Background(), tc.declarations, tc.bindings); err == nil { + if err := workspace.ValidateBindings(context.Background(), tc.declarations, tc.bindings); err == nil { t.Errorf("expected error for invalid bindings but didn't get any!") } }) @@ -200,7 +201,7 @@ func TestValidateOnlyOnePVCIsUsed_Valid(t *testing.T) { }}, }} { t.Run(tc.name, func(t *testing.T) { - if err := ValidateOnlyOnePVCIsUsed(tc.bindings); err != nil { + if err := workspace.ValidateOnlyOnePVCIsUsed(tc.bindings); err != nil { t.Errorf("unexpected error: %v", err) } }) @@ -238,7 +239,7 @@ func TestValidateOnlyOnePVCIsUsed_Invalid(t *testing.T) { wantErr: validationError, }} { t.Run(tc.name, func(t *testing.T) { - err := ValidateOnlyOnePVCIsUsed(tc.bindings) + err := workspace.ValidateOnlyOnePVCIsUsed(tc.bindings) if err == nil || (tc.wantErr.Error() != err.Error()) { t.Errorf("expected %v received %v", tc.wantErr, err) }