@@ -20,8 +20,8 @@ func TestEvaluateCondition(t *testing.T) {
2020 oxr := `{"apiVersion":"nopexample.org/v1alpha1","kind":"XNopResource","metadata":{"name":"test-resource"},"spec":{"env":"dev","render":true},"status":{"id":"123","ready":false} }`
2121
2222 type args struct {
23- cs v1beta1.ConditionSpec
24- req * fnv1beta1.RunFunctionRequest
23+ condition v1beta1.Condition
24+ req * fnv1beta1.RunFunctionRequest
2525 }
2626 type want struct {
2727 ret bool
@@ -35,7 +35,7 @@ func TestEvaluateCondition(t *testing.T) {
3535 }{
3636 "CELParseError" : {
3737 args : args {
38- cs : v1beta1. ConditionSpec { Expression : "field = value" } ,
38+ condition : strPtr ( "field = value" ) ,
3939 req : & fnv1beta1.RunFunctionRequest {
4040 Input : resource .MustStructObject (& v1beta1.Resources {
4141 Resources : []v1beta1.ComposedTemplate {
@@ -64,7 +64,7 @@ func TestEvaluateCondition(t *testing.T) {
6464 },
6565 "CELTypeError" : {
6666 args : args {
67- cs : v1beta1. ConditionSpec { Expression : "size(desired.resources)" } ,
67+ condition : strPtr ( "size(desired.resources)" ) ,
6868 req : & fnv1beta1.RunFunctionRequest {
6969 Input : resource .MustStructObject (& v1beta1.Resources {
7070 Resources : []v1beta1.ComposedTemplate {
@@ -93,7 +93,7 @@ func TestEvaluateCondition(t *testing.T) {
9393 },
9494 "KeyError" : {
9595 args : args {
96- cs : v1beta1. ConditionSpec { Expression : "badkey" } ,
96+ condition : strPtr ( "badkey" ) ,
9797 req : & fnv1beta1.RunFunctionRequest {
9898 Input : resource .MustStructObject (& v1beta1.Resources {
9999 Resources : []v1beta1.ComposedTemplate {
@@ -122,7 +122,7 @@ func TestEvaluateCondition(t *testing.T) {
122122 },
123123 "TrueDesired" : {
124124 args : args {
125- cs : v1beta1. ConditionSpec { Expression : "desired.composite.resource.spec.env == \" dev\" " } ,
125+ condition : strPtr ( "desired.composite.resource.spec.env == \" dev\" " ) ,
126126 req : & fnv1beta1.RunFunctionRequest {
127127 Input : resource .MustStructObject (& v1beta1.Resources {
128128 Resources : []v1beta1.ComposedTemplate {
@@ -151,7 +151,7 @@ func TestEvaluateCondition(t *testing.T) {
151151 },
152152 "TrueDesiredBool" : {
153153 args : args {
154- cs : v1beta1. ConditionSpec { Expression : "desired.composite.resource.spec.render == true" } ,
154+ condition : strPtr ( "desired.composite.resource.spec.render == true" ) ,
155155 req : & fnv1beta1.RunFunctionRequest {
156156 Input : resource .MustStructObject (& v1beta1.Resources {
157157 Resources : []v1beta1.ComposedTemplate {
@@ -180,7 +180,7 @@ func TestEvaluateCondition(t *testing.T) {
180180 },
181181 "FalseDesiredBool" : {
182182 args : args {
183- cs : v1beta1. ConditionSpec { Expression : "desired.composite.resource.spec.render == false" } ,
183+ condition : strPtr ( "desired.composite.resource.spec.render == false" ) ,
184184 req : & fnv1beta1.RunFunctionRequest {
185185 Input : resource .MustStructObject (& v1beta1.Resources {
186186 Resources : []v1beta1.ComposedTemplate {
@@ -209,7 +209,7 @@ func TestEvaluateCondition(t *testing.T) {
209209 },
210210 "FalseObservedBool" : {
211211 args : args {
212- cs : v1beta1. ConditionSpec { Expression : "observed.composite.resource.status.ready == true" } ,
212+ condition : strPtr ( "observed.composite.resource.status.ready == true" ) ,
213213 req : & fnv1beta1.RunFunctionRequest {
214214 Input : resource .MustStructObject (& v1beta1.Resources {
215215 Resources : []v1beta1.ComposedTemplate {
@@ -238,7 +238,7 @@ func TestEvaluateCondition(t *testing.T) {
238238 },
239239 "FalseLengthResources" : {
240240 args : args {
241- cs : v1beta1. ConditionSpec { Expression : "size(desired.resources) == 0" } ,
241+ condition : strPtr ( "size(desired.resources) == 0" ) ,
242242 req : & fnv1beta1.RunFunctionRequest {
243243 Input : resource .MustStructObject (& v1beta1.Resources {
244244 Resources : []v1beta1.ComposedTemplate {
@@ -272,7 +272,7 @@ func TestEvaluateCondition(t *testing.T) {
272272 },
273273 "TrueResourceMapKeyExists" : {
274274 args : args {
275- cs : v1beta1. ConditionSpec { Expression : "\" test-resource\" in desired.resources" } ,
275+ condition : strPtr ( "\" test-resource\" in desired.resources" ) ,
276276 req : & fnv1beta1.RunFunctionRequest {
277277 Input : resource .MustStructObject (& v1beta1.Resources {
278278 Resources : []v1beta1.ComposedTemplate {
@@ -306,7 +306,7 @@ func TestEvaluateCondition(t *testing.T) {
306306 },
307307 "FalseResourceMapKeyExists" : {
308308 args : args {
309- cs : v1beta1. ConditionSpec { Expression : "\" bad-resource\" in desired.resources" } ,
309+ condition : strPtr ( "\" bad-resource\" in desired.resources" ) ,
310310 req : & fnv1beta1.RunFunctionRequest {
311311 Input : resource .MustStructObject (& v1beta1.Resources {
312312 Resources : []v1beta1.ComposedTemplate {
@@ -342,7 +342,7 @@ func TestEvaluateCondition(t *testing.T) {
342342
343343 for name , tc := range cases {
344344 t .Run (name , func (t * testing.T ) {
345- ret , err := EvaluateCondition (tc .args .cs , tc .args .req )
345+ ret , err := EvaluateCondition (tc .args .condition , tc .args .req )
346346
347347 if diff := cmp .Diff (tc .want .ret , ret ); diff != "" {
348348 t .Errorf ("%s\n EvaluateCondition(...): -want ret, +got ret:\n %s" , tc .reason , diff )
@@ -357,3 +357,7 @@ func TestEvaluateCondition(t *testing.T) {
357357 })
358358 }
359359}
360+
361+ func strPtr (str string ) * string {
362+ return & str
363+ }
0 commit comments