MCPcopy Index your code
hub / github.com/FunctionStream/function-stream / TestHttpTube

Function TestHttpTube

server/server_test.go:136–198  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

134}
135
136func TestHttpTube(t *testing.T) {
137 ctx, cancel := context.WithCancel(context.Background())
138 defer cancel()
139 s, httpAddr := startStandaloneSvr(t, ctx, nil, nil)
140
141 endpoint := "test-endpoint"
142 funcConf := &model.Function{
143 Runtime: model.RuntimeConfig{
144 Type: common.WASMRuntime,
145 Config: map[string]interface{}{
146 common.RuntimeArchiveConfigKey: "../bin/example_basic.wasm",
147 },
148 },
149 Sources: []model.TubeConfig{{
150 Type: common.HttpTubeType,
151 Config: map[string]interface{}{
152 contube.EndpointKey: endpoint,
153 },
154 }},
155 Sink: model.TubeConfig{
156 Type: common.MemoryTubeType,
157 Config: (&contube.SinkQueueConfig{
158 Topic: "output",
159 }).ToConfigMap(),
160 },
161 Name: "test-func",
162 Replicas: 1,
163 }
164
165 err := s.Manager.StartFunction(funcConf)
166 assert.Nil(t, err)
167
168 p := &tests.Person{
169 Name: "rbt",
170 Money: 0,
171 }
172 jsonBytes, err := json.Marshal(p)
173 if err != nil {
174 t.Fatal(err)
175 }
176
177 cfg := adminclient.NewConfiguration()
178 cfg.Host = httpAddr
179 cli := adminclient.NewAPIClient(cfg)
180 _, err = cli.HttpTubeAPI.TriggerHttpTubeEndpoint(ctx, endpoint).Body(string(jsonBytes)).Execute()
181 assert.Nil(t, err)
182
183 event, err := s.Manager.ConsumeEvent("output")
184 if err != nil {
185 t.Error(err)
186 return
187 }
188 var out tests.Person
189 err = json.Unmarshal(event.GetPayload(), &out)
190 if err != nil {
191 t.Error(err)
192 return
193 }

Callers

nothing calls this directly

Calls 9

startStandaloneSvrFunction · 0.85
ErrorMethod · 0.80
StartFunctionMethod · 0.65
ConsumeEventMethod · 0.65
GetPayloadMethod · 0.65
ToConfigMapMethod · 0.45
ExecuteMethod · 0.45
BodyMethod · 0.45

Tested by

no test coverage detected