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

Function TestRunFunction

fn_test.go:25–1550  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestRunFunction(t *testing.T) {
26 type args struct {
27 ctx context.Context
28 req *fnv1.RunFunctionRequest
29 }
30 type want struct {
31 rsp *fnv1.RunFunctionResponse
32 err error
33 }
34
35 cases := map[string]struct {
36 reason string
37 args args
38 want want
39 }{
40 "NoInput": {
41 reason: "The Function should return a fatal result if no input was specified",
42 args: args{
43 req: &fnv1.RunFunctionRequest{},
44 },
45 want: want{
46 rsp: &fnv1.RunFunctionResponse{
47 Meta: &fnv1.ResponseMeta{Ttl: durationpb.New(response.DefaultTTL)},
48 Results: []*fnv1.Result{
49 {
50 Severity: fnv1.Severity_SEVERITY_FATAL,
51 Message: "invalid Function input: resources: Required value: resources or environment patches are required",
52 Target: fnv1.Target_TARGET_COMPOSITE.Enum(),
53 },
54 },
55 },
56 },
57 },
58 "RenderBaseTemplateWithoutPatches": {
59 reason: "A simple base template with no patches should be rendered and returned as a desired object.",
60 args: args{
61 req: &fnv1.RunFunctionRequest{
62 Input: resource.MustStructObject(&v1beta1.Resources{
63 Resources: []v1beta1.ComposedTemplate{
64 {
65 Name: "cool-resource",
66 Base: &runtime.RawExtension{Raw: []byte(`{"apiVersion":"example.org/v1","kind":"CD"}`)},
67 },
68 },
69 }),
70 Observed: &fnv1.State{
71 Composite: &fnv1.Resource{
72 Resource: resource.MustStructJSON(`{"apiVersion":"example.org/v1","kind":"XR"}`),
73 },
74 },
75 Desired: &fnv1.State{
76 Composite: &fnv1.Resource{
77 Resource: resource.MustStructJSON(`{"apiVersion":"example.org/v1","kind":"XR"}`),
78 },
79 },
80 },
81 },
82 want: want{

Callers

nothing calls this directly

Calls 3

RunFunctionMethod · 0.95
contextWithEnvironmentFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected