MCPcopy Create free account
hub / github.com/crossplane-contrib/function-patch-and-transform / ValidateCombine

Function ValidateCombine

validate.go:225–248  ·  view source on GitHub ↗

ValidateCombine validates a Combine.

(c *v1beta1.Combine)

Source from the content-addressed store, hash-verified

223
224// ValidateCombine validates a Combine.
225func ValidateCombine(c *v1beta1.Combine) *field.Error {
226 switch c.Strategy {
227 case v1beta1.CombineStrategyString:
228 if c.String == nil {
229 return field.Required(field.NewPath("string"), fmt.Sprintf("string must be set for combine strategy %s", c.Strategy))
230 }
231 case "":
232 return field.Required(field.NewPath("strategy"), "a combine strategy must be provided")
233 default:
234 return field.Invalid(field.NewPath("strategy"), c.Strategy, "unknown strategy type")
235 }
236
237 if len(c.Variables) == 0 {
238 return field.Required(field.NewPath("variables"), "at least one variable must be provided")
239 }
240
241 for i := range c.Variables {
242 if c.Variables[i].FromFieldPath == "" {
243 return field.Required(field.NewPath("variables").Index(i).Child("fromFieldPath"), "fromFieldPath must be set for each combine variable")
244 }
245 }
246
247 return nil
248}
249
250// ValidateTransform validates a Transform.
251func ValidateTransform(t v1beta1.Transform) *field.Error { //nolint:gocyclo // This is a long but simple/same-y switch.

Callers 2

ValidatePatchFunction · 0.85
TestValidateCombineFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestValidateCombineFunction · 0.68