@@ -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,154 @@ 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+ t .Run (tc .name , func (t * testing.T ) {
118+ got := & v1beta1.ResolutionRequest {}
119+ if err := tc .in .ConvertTo (context .Background (), got ); err != nil {
120+ t .Fatalf ("ConvertTo() = %v" , err )
121+ }
122+
123+ t .Logf ("ConvertTo() = %#v" , got )
124+
125+ roundTrip := & ResolutionRequest {}
126+ if err := roundTrip .ConvertFrom (context .Background (), got ); err != nil {
127+ t .Errorf ("ConvertFrom() = %v" , err )
128+ }
129+
130+ if d := cmp .Diff (tc .in , roundTrip ); d != "" {
131+ t .Errorf ("converted ResolutionRequest did not match expected: %s" , diff .PrintWantGot (d ))
132+ }
133+ })
114134 }
115135}
116136
117- func TestResolutionRequestConvertFrom (t * testing.T ) {
118- versions := []apis.Convertible {& ResolutionRequest {}}
119-
137+ func TestResolutionRequestConvertFromDeprecated (t * testing.T ) {
120138 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- },
139+ name string
140+ in * v1beta1.ResolutionRequest
141+ want apis.Convertible
142+ }{{
143+ name : "with status.source" ,
144+ in : & v1beta1.ResolutionRequest {
145+ ObjectMeta : metav1.ObjectMeta {
146+ Name : "foo" ,
147+ Namespace : "bar" ,
145148 },
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- },
149+ Spec : v1beta1.ResolutionRequestSpec {
150+ Params : nil ,
159151 },
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" ,
152+ Status : v1beta1.ResolutionRequestStatus {
153+ ResolutionRequestStatusFields : v1beta1.ResolutionRequestStatusFields {
154+ Source : & pipelinev1beta1.ConfigSource {
155+ URI : "abcd" ,
156+ Digest : map [string ]string {"123" : "456" },
157+ EntryPoint : "baz" ,
168158 },
169159 },
170160 },
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- },
161+ },
162+ want : & ResolutionRequest {
163+ ObjectMeta : metav1.ObjectMeta {
164+ Name : "foo" ,
165+ Namespace : "bar" ,
166+ },
167+ Spec : ResolutionRequestSpec {
168+ Parameters : nil ,
169+ },
170+ Status : ResolutionRequestStatus {
171+ ResolutionRequestStatusFields : ResolutionRequestStatusFields {
172+ RefSource : & pipelinev1beta1.RefSource {
173+ URI : "abcd" ,
174+ Digest : map [string ]string {"123" : "456" },
175+ EntryPoint : "baz" ,
193176 },
194177 },
195178 },
196- out : nil ,
197- expectedErr : errors .New ("cannot convert v1beta1 to v1alpha, non-string type parameter(s) found: array-val, object-val" ),
198179 },
199- }
180+ }}
200181
201182 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- }
183+ t .Run (tc .name , func (t * testing.T ) {
184+ got := & ResolutionRequest {}
185+ if err := got .ConvertFrom (context .Background (), tc .in ); err != nil {
186+ t .Errorf ("ConvertFrom() = %v" , err )
187+ }
188+
189+ if d := cmp .Diff (tc .want , got ); d != "" {
190+ t .Errorf ("converted ResolutionRequest did not match expected: %s" , diff .PrintWantGot (d ))
191+ }
192+ })
222193 }
223194}
0 commit comments