@@ -19,7 +19,6 @@ package v1alpha1
1919
2020import (
2121 "context"
22- "errors"
2322 "testing"
2423
2524 "github.com/google/go-cmp/cmp"
@@ -42,182 +41,156 @@ func TestResolutionRequestConversionBadType(t *testing.T) {
4241 }
4342}
4443
45- func TestResolutionRequestConvertTo (t * testing.T ) {
46- versions := []apis.Convertible {& v1beta1.ResolutionRequest {}}
47-
44+ func TestResolutionRequestConvertRoundTrip (t * testing.T ) {
4845 testCases := []struct {
4946 name string
5047 in * ResolutionRequest
5148 out apis.Convertible
52- }{
53- {
54- name : "no params" ,
55- in : & ResolutionRequest {
56- ObjectMeta : metav1.ObjectMeta {
57- Name : "foo" ,
58- Namespace : "bar" ,
59- },
60- Spec : ResolutionRequestSpec {
61- Parameters : nil ,
62- },
49+ }{{
50+ name : "no params" ,
51+ in : & ResolutionRequest {
52+ ObjectMeta : metav1.ObjectMeta {
53+ Name : "foo" ,
54+ Namespace : "bar" ,
6355 },
64- out : & v1beta1.ResolutionRequest {
65- ObjectMeta : metav1.ObjectMeta {
66- Name : "foo" ,
67- Namespace : "bar" ,
68- },
69- Spec : v1beta1.ResolutionRequestSpec {
70- Params : nil ,
56+ Spec : ResolutionRequestSpec {
57+ Parameters : nil ,
58+ },
59+ },
60+ }, {
61+ name : "with params" ,
62+ in : & ResolutionRequest {
63+ ObjectMeta : metav1.ObjectMeta {
64+ Name : "foo" ,
65+ Namespace : "bar" ,
66+ },
67+ Spec : ResolutionRequestSpec {
68+ Parameters : map [string ]string {
69+ "some-param" : "some-value" ,
7170 },
7271 },
73- }, {
74- name : "with params" ,
75- in : & ResolutionRequest {
76- ObjectMeta : metav1.ObjectMeta {
77- Name : "foo" ,
78- Namespace : "bar" ,
72+ },
73+ }, {
74+ name : "with status refsource" ,
75+ in : & ResolutionRequest {
76+ ObjectMeta : metav1.ObjectMeta {
77+ Name : "foo" ,
78+ Namespace : "bar" ,
79+ },
80+ Spec : ResolutionRequestSpec {
81+ Parameters : map [string ]string {
82+ "some-param" : "some-value" ,
7983 },
80- Spec : ResolutionRequestSpec {
81- Parameters : map [string ]string {
82- "some-param" : "some-value" ,
84+ },
85+ Status : ResolutionRequestStatus {
86+ ResolutionRequestStatusFields : ResolutionRequestStatusFields {
87+ Data : "foobar" ,
88+ RefSource : & pipelinev1beta1.RefSource {
89+ URI : "abcd" ,
90+ Digest : map [string ]string {"123" : "456" },
91+ EntryPoint : "baz" ,
8392 },
8493 },
8594 },
86- out : & v1beta1.ResolutionRequest {
87- ObjectMeta : metav1.ObjectMeta {
88- Name : "foo" ,
89- Namespace : "bar" ,
95+ },
96+ }, {
97+ name : "with status, no refsource" ,
98+ in : & ResolutionRequest {
99+ ObjectMeta : metav1.ObjectMeta {
100+ Name : "foo" ,
101+ Namespace : "bar" ,
102+ },
103+ Spec : ResolutionRequestSpec {
104+ Parameters : map [string ]string {
105+ "some-param" : "some-value" ,
90106 },
91- Spec : v1beta1.ResolutionRequestSpec {
92- Params : []pipelinev1beta1.Param {{
93- Name : "some-param" ,
94- Value : * pipelinev1beta1 .NewStructuredValues ("some-value" ),
95- }},
107+ },
108+ Status : ResolutionRequestStatus {
109+ ResolutionRequestStatusFields : ResolutionRequestStatusFields {
110+ Data : "foobar" ,
96111 },
97112 },
98113 },
99- }
114+ }}
100115
101116 for _ , tc := range testCases {
102- for _ , version := range versions {
103- t .Run (tc .name , func (t * testing.T ) {
104- got := version
105- if err := tc .in .ConvertTo (context .Background (), got ); err != nil {
106- t .Fatalf ("ConvertTo() = %v" , err )
107- }
108- t .Logf ("ConvertTo() = %#v" , got )
109- if d := cmp .Diff (tc .out , got ); d != "" {
110- t .Errorf ("converted ResolutionRequest did not match expected: %s" , diff .PrintWantGot (d ))
111- }
112- })
113- }
117+
118+ t .Run (tc .name , func (t * testing.T ) {
119+ got := & v1beta1.ResolutionRequest {}
120+ if err := tc .in .ConvertTo (context .Background (), got ); err != nil {
121+ t .Fatalf ("ConvertTo() = %v" , err )
122+ }
123+
124+ t .Logf ("ConvertTo() = %#v" , got )
125+
126+ roundTrip := & ResolutionRequest {}
127+ if err := roundTrip .ConvertFrom (context .Background (), got ); err != nil {
128+ t .Errorf ("ConvertFrom() = %v" , err )
129+ }
130+
131+ if d := cmp .Diff (tc .in , roundTrip ); d != "" {
132+ t .Errorf ("converted ResolutionRequest did not match expected: %s" , diff .PrintWantGot (d ))
133+ }
134+ })
114135 }
115136}
116137
117- func TestResolutionRequestConvertFrom (t * testing.T ) {
118- versions := []apis.Convertible {& ResolutionRequest {}}
119-
138+ func TestResolutionRequestConvertFromDeprecated (t * testing.T ) {
120139 testCases := []struct {
121- name string
122- in apis.Convertible
123- out * ResolutionRequest
124- expectedErr error
125- }{
126- {
127- name : "no params" ,
128- in : & v1beta1.ResolutionRequest {
129- ObjectMeta : metav1.ObjectMeta {
130- Name : "foo" ,
131- Namespace : "bar" ,
132- },
133- Spec : v1beta1.ResolutionRequestSpec {
134- Params : nil ,
135- },
136- },
137- out : & ResolutionRequest {
138- ObjectMeta : metav1.ObjectMeta {
139- Name : "foo" ,
140- Namespace : "bar" ,
141- },
142- Spec : ResolutionRequestSpec {
143- Parameters : nil ,
144- },
140+ name string
141+ in * v1beta1.ResolutionRequest
142+ want apis.Convertible
143+ }{{
144+ name : "with status.source" ,
145+ in : & v1beta1.ResolutionRequest {
146+ ObjectMeta : metav1.ObjectMeta {
147+ Name : "foo" ,
148+ Namespace : "bar" ,
145149 },
146- }, {
147- name : "with only string params" ,
148- in : & v1beta1.ResolutionRequest {
149- ObjectMeta : metav1.ObjectMeta {
150- Name : "foo" ,
151- Namespace : "bar" ,
152- },
153- Spec : v1beta1.ResolutionRequestSpec {
154- Params : []pipelinev1beta1.Param {{
155- Name : "some-param" ,
156- Value : * pipelinev1beta1 .NewStructuredValues ("some-value" ),
157- }},
158- },
150+ Spec : v1beta1.ResolutionRequestSpec {
151+ Params : nil ,
159152 },
160- out : & ResolutionRequest {
161- ObjectMeta : metav1.ObjectMeta {
162- Name : "foo" ,
163- Namespace : "bar" ,
164- },
165- Spec : ResolutionRequestSpec {
166- Parameters : map [string ]string {
167- "some-param" : "some-value" ,
153+ Status : v1beta1.ResolutionRequestStatus {
154+ ResolutionRequestStatusFields : v1beta1.ResolutionRequestStatusFields {
155+ Source : & pipelinev1beta1.ConfigSource {
156+ URI : "abcd" ,
157+ Digest : map [string ]string {"123" : "456" },
158+ EntryPoint : "baz" ,
168159 },
169160 },
170161 },
171- }, {
172- name : "with non-string params" ,
173- in : & v1beta1.ResolutionRequest {
174- ObjectMeta : metav1.ObjectMeta {
175- Name : "foo" ,
176- Namespace : "bar" ,
177- },
178- Spec : v1beta1.ResolutionRequestSpec {
179- Params : []pipelinev1beta1.Param {
180- {
181- Name : "array-val" ,
182- Value : * pipelinev1beta1 .NewStructuredValues ("one" , "two" ),
183- }, {
184- Name : "string-val" ,
185- Value : * pipelinev1beta1 .NewStructuredValues ("a-string" ),
186- }, {
187- Name : "object-val" ,
188- Value : * pipelinev1beta1 .NewObject (map [string ]string {
189- "key-one" : "value-one" ,
190- "key-two" : "value-two" ,
191- }),
192- },
162+ },
163+ want : & ResolutionRequest {
164+ ObjectMeta : metav1.ObjectMeta {
165+ Name : "foo" ,
166+ Namespace : "bar" ,
167+ },
168+ Spec : ResolutionRequestSpec {
169+ Parameters : nil ,
170+ },
171+ Status : ResolutionRequestStatus {
172+ ResolutionRequestStatusFields : ResolutionRequestStatusFields {
173+ RefSource : & pipelinev1beta1.RefSource {
174+ URI : "abcd" ,
175+ Digest : map [string ]string {"123" : "456" },
176+ EntryPoint : "baz" ,
193177 },
194178 },
195179 },
196- out : nil ,
197- expectedErr : errors .New ("cannot convert v1beta1 to v1alpha, non-string type parameter(s) found: array-val, object-val" ),
198180 },
199- }
181+ }}
200182
201183 for _ , tc := range testCases {
202- for _ , version := range versions {
203- t .Run (tc .name , func (t * testing.T ) {
204- got := version
205- err := got .ConvertFrom (context .Background (), tc .in )
206- if tc .expectedErr != nil {
207- if err == nil {
208- t .Fatalf ("expected error '%s', but did not get an error" , tc .expectedErr .Error ())
209- } else if d := cmp .Diff (tc .expectedErr .Error (), err .Error ()); d != "" {
210- t .Fatalf ("error did not meet expected: %s" , diff .PrintWantGot (d ))
211- }
212- return
213- } else if err != nil {
214- t .Fatalf ("ConvertFrom() = %v" , err )
215- }
216- t .Logf ("ConvertFrom() = %#v" , got )
217- if d := cmp .Diff (tc .out , got ); d != "" {
218- t .Errorf ("converted ResolutionRequest did not match expected: %s" , diff .PrintWantGot (d ))
219- }
220- })
221- }
184+ t .Run (tc .name , func (t * testing.T ) {
185+ got := & ResolutionRequest {}
186+ if err := got .ConvertFrom (context .Background (), tc .in ); err != nil {
187+ t .Errorf ("ConvertFrom() = %v" , err )
188+ }
189+
190+ if d := cmp .Diff (tc .want , got ); d != "" {
191+ t .Errorf ("converted ResolutionRequest did not match expected: %s" , diff .PrintWantGot (d ))
192+ }
193+ })
194+
222195 }
223196}
0 commit comments