@@ -51,7 +51,7 @@ func TestRunFunction(t *testing.T) {
51
51
Results : []* fnv1beta1.Result {
52
52
{
53
53
Severity : fnv1beta1 .Severity_SEVERITY_FATAL ,
54
- Message : "invalid Function input: resources: Required value: resources is required" ,
54
+ Message : "invalid Function input: resources: Required value: resources or environment patches are required" ,
55
55
},
56
56
},
57
57
},
@@ -1197,6 +1197,44 @@ func TestRunFunction(t *testing.T) {
1197
1197
Context : contextWithEnvironment (map [string ]interface {}{
1198
1198
"widgets" : "10" ,
1199
1199
})}}},
1200
+ "OnlyEnvironmentPatchesIsAllowed" : {
1201
+ reason : "Having only environment patches should be allowed and work as expected." ,
1202
+ args : args {
1203
+ req : & fnv1beta1.RunFunctionRequest {
1204
+ Input : resource .MustStructObject (& v1beta1.Resources {
1205
+ Environment : & v1beta1.Environment {
1206
+ Patches : []v1beta1.EnvironmentPatch {
1207
+ {
1208
+ Type : v1beta1 .PatchTypeFromCompositeFieldPath ,
1209
+ Patch : v1beta1.Patch {
1210
+ FromFieldPath : ptr.To [string ]("spec.widgets" ),
1211
+ ToFieldPath : ptr.To [string ]("envKey" ),
1212
+ },
1213
+ },
1214
+ },
1215
+ },
1216
+ }),
1217
+ Observed : & fnv1beta1.State {
1218
+ Composite : & fnv1beta1.Resource {
1219
+ Resource : resource .MustStructJSON (`{"apiVersion":"example.org/v1","kind":"XR","spec":{"widgets":"10"}}` ),
1220
+ },
1221
+ },
1222
+ },
1223
+ },
1224
+ want : want {
1225
+ rsp : & fnv1beta1.RunFunctionResponse {
1226
+ Meta : & fnv1beta1.ResponseMeta {Ttl : durationpb .New (response .DefaultTTL )},
1227
+ Desired : & fnv1beta1.State {
1228
+ Composite : & fnv1beta1.Resource {
1229
+ Resource : resource .MustStructJSON (`{"apiVersion":"example.org/v1","kind":"XR"}` ),
1230
+ },
1231
+ },
1232
+ Context : contextWithEnvironment (map [string ]interface {}{
1233
+ "envKey" : "10" ,
1234
+ }),
1235
+ },
1236
+ },
1237
+ },
1200
1238
}
1201
1239
1202
1240
for name , tc := range cases {
0 commit comments