MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / TestInvoke

Function TestInvoke

pkg/controller/client/rpc_test.go:63–121  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestInvoke(t *testing.T) {
64 pflag.CommandLine = pflag.NewFlagSet(os.Args[0], pflag.ExitOnError)
65 opt := NewControllerClientOptions()
66 opt.AddFlags(pflag.CommandLine)
67 pflag.Set("controller-host", ServerHost)
68 flag.InitFlags()
69 client, err := NewControllerClient(opt)
70 if err != nil {
71 t.Errorf("new client with err %s", err.Error())
72 return
73 }
74
75 ds := []struct {
76 host string
77 withError bool
78 err error
79 }{
80 {host: ServerHost, withError: false, err: nil},
81 {host: ServerHost, withError: true, err: nil},
82 {host: OtherServerHost, withError: true, err: errors.New(fmt.Sprintf("dial tcp4 127.0.0.1:7777: connect: connection refused"))},
83 }
84 for _, item := range ds {
85 router := newControllerClientRouter(item.withError)
86 ts := httptest.NewUnstartedServer(router)
87 u, _ := url.Parse(item.host)
88 l, err := net.Listen("tcp", u.Host)
89 if err != nil {
90 t.Errorf("test server listen err: %+v", err)
91 return
92 }
93 ts.Listener = l
94 ts.Start()
95 bodyStr := "{\"k1\":\"v1\"}"
96 ir := &api.InvokeRequest{
97 UserID: "df391b08c64c426a81645468c75163a5",
98 FunctionBRN: "brn:cloud:faas:bj:cd64f99c69d7c404b61de0a4f1865834:function:concurrentHello:1",
99 Body: &bodyStr,
100 RequestID: "xxx",
101 }
102 res, err := client.Invoke(ir)
103 t.Logf("res = %v", res)
104 t.Logf("err = %v", err)
105 if err != item.err {
106 ts.Close()
107 if err != nil && item.err == nil {
108 t.Errorf("controller invoke expect err nil, but got %+v", err)
109 } else if item.err != nil && err == nil {
110 t.Errorf("controller invoke expect err %+v, but got nil", item.err)
111 } else if item.err.Error() != err.Error() {
112 t.Errorf("controller invoke expect err %+v, but got %+v", item.err, err)
113 } else {
114 continue
115 }
116 return
117 }
118 ts.Close()
119 }
120 return

Callers

nothing calls this directly

Calls 12

AddFlagsMethod · 0.95
InvokeMethod · 0.95
InitFlagsFunction · 0.92
NewControllerClientFunction · 0.85
ErrorfMethod · 0.80
NewMethod · 0.80
SetMethod · 0.65
StartMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected