MCPcopy Index your code
hub / github.com/crossplane/function-template-go / TestRunFunction

Function TestRunFunction

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

Source from the content-addressed store, hash-verified

16)
17
18func TestRunFunction(t *testing.T) {
19 type args struct {
20 ctx context.Context
21 req *fnv1.RunFunctionRequest
22 }
23 type want struct {
24 rsp *fnv1.RunFunctionResponse
25 err error
26 }
27
28 cases := map[string]struct {
29 reason string
30 args args
31 want want
32 }{
33 "ResponseIsReturned": {
34 reason: "The Function should return a fatal result if no input was specified",
35 args: args{
36 req: &fnv1.RunFunctionRequest{
37 Meta: &fnv1.RequestMeta{Tag: "hello"},
38 Input: resource.MustStructJSON(`{
39 "apiVersion": "template.fn.crossplane.io/v1beta1",
40 "kind": "Input",
41 "example": "Hello, world"
42 }`),
43 },
44 },
45 want: want{
46 rsp: &fnv1.RunFunctionResponse{
47 Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)},
48 Results: []*fnv1.Result{
49 {
50 Severity: fnv1.Severity_SEVERITY_NORMAL,
51 Message: "I was run with input \"Hello, world\"!",
52 Target: fnv1.Target_TARGET_COMPOSITE.Enum(),
53 },
54 },
55 Conditions: []*fnv1.Condition{
56 {
57 Type: "FunctionSuccess",
58 Status: fnv1.Status_STATUS_CONDITION_TRUE,
59 Reason: "Success",
60 Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(),
61 },
62 },
63 },
64 },
65 },
66 }
67
68 for name, tc := range cases {
69 t.Run(name, func(t *testing.T) {
70 f := &Function{log: logging.NewNopLogger()}
71 rsp, err := f.RunFunction(tc.args.ctx, tc.args.req)
72
73 if diff := cmp.Diff(tc.want.rsp, rsp, protocmp.Transform()); diff != "" {
74 t.Errorf("%s\nf.RunFunction(...): -want rsp, +got rsp:\n%s", tc.reason, diff)
75 }

Callers

nothing calls this directly

Calls 2

RunFunctionMethod · 0.95
RunMethod · 0.80

Tested by

no test coverage detected