@@ -38,6 +38,27 @@ func testBuildValidation(t *testing.T, when spec.G, it spec.S) {
3838 },
3939 },
4040 }
41+ buildUsingRef := & Build {
42+ ObjectMeta : metav1.ObjectMeta {
43+ Name : "buildWithRef-name" ,
44+ },
45+ Spec : BuildSpec {
46+ Tags : []string {"some/image" },
47+ Builder : corev1alpha1.BuildBuilderSpec {
48+ Ref : & corev1.ObjectReference {
49+ Name : "default" ,
50+ Kind : "ClusterBuilder" ,
51+ },
52+ },
53+ ServiceAccountName : "some/service-account" ,
54+ Source : corev1alpha1.SourceConfig {
55+ Git : & corev1alpha1.Git {
56+ URL : "http://github.com/repo" ,
57+ Revision : "master" ,
58+ },
59+ },
60+ },
61+ }
4162 when ("Default" , func () {
4263 it ("does not modify already set fields" , func () {
4364 oldBuild := build .DeepCopy ()
@@ -81,14 +102,32 @@ func testBuildValidation(t *testing.T, when spec.G, it spec.S) {
81102
82103 it ("missing builder name" , func () {
83104 build .Spec .Builder .Image = ""
84- assertValidationError (build , context .TODO (), apis .ErrMissingField ("image" ).ViaField ("spec" , "builder" ))
105+ assertValidationError (build , context .TODO (), apis .ErrMissingField ("image" , "ref" ).ViaField ("spec" , "builder" ))
85106 })
86107
87108 it ("invalid builder name" , func () {
88109 build .Spec .Builder .Image = "foo.ioo/builder-but-not-a-builder@sha256:alksdifhjalsouidfh"
89110 assertValidationError (build , context .TODO (), apis .ErrInvalidValue ("foo.ioo/builder-but-not-a-builder@sha256:alksdifhjalsouidfh" , "image" ).ViaField ("spec" , "builder" ))
90111 })
91112
113+ it ("valid cluster builder by ref" , func () {
114+ assert .Nil (t , buildUsingRef .Validate (context .TODO ()))
115+ })
116+
117+ it ("both image and builder by ref present" , func () {
118+ buildUsingRef .Spec .Builder .Image = "builder/bionic-builder@sha256:e431a4f94fb84854fd081da62762192f36fd093fdfb85ad3bc009b9309524e2d"
119+ assertValidationError (buildUsingRef , context .TODO (), apis .ErrMultipleOneOf ("image" , "ref" ).ViaField ("spec" , "builder" ))
120+ })
121+
122+ it ("validate namespaced builder by ref" , func () {
123+ buildUsingRef .Spec .Builder .Ref = & corev1.ObjectReference {
124+ Kind : "Builder" ,
125+ Name : "namespaced-builder" ,
126+ Namespace : "default" ,
127+ }
128+ assert .Nil (t , buildUsingRef .Validate (context .TODO ()))
129+ })
130+
92131 it ("multiple sources" , func () {
93132 build .Spec .Source .Git = & corev1alpha1.Git {
94133 URL : "http://github.com/repo" ,
@@ -331,7 +370,7 @@ func testBuildValidation(t *testing.T, when spec.G, it spec.S) {
331370 build .Spec .Builder .Image = ""
332371 assertValidationError (build , context .TODO (),
333372 apis .ErrMissingField ("tags" ).ViaField ("spec" ).
334- Also (apis .ErrMissingField ("image" ).ViaField ("spec" , "builder" )))
373+ Also (apis .ErrMissingField ("image" , "ref" ).ViaField ("spec" , "builder" )))
335374 })
336375
337376 it ("validates spec is immutable" , func () {
0 commit comments