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

Function TestBasicFunction

tests/integration_test.go:49–137  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

47}
48
49func TestBasicFunction(t *testing.T) {
50
51 cfg := adminclient.NewConfiguration()
52 cli := adminclient.NewAPIClient(cfg)
53
54 client, err := pulsar.NewClient(pulsar.ClientOptions{
55 URL: "pulsar://localhost:6650",
56 })
57 if err != nil {
58 t.Fatalf(err.Error())
59 }
60
61 name := "func-" + strconv.Itoa(rand.Int())
62 inputTopic := "test-input-" + strconv.Itoa(rand.Int())
63 outputTopic := "test-output-" + strconv.Itoa(rand.Int())
64 f := adminclient.ModelFunction{
65 Name: name,
66 Runtime: adminclient.ModelRuntimeConfig{
67 Type: common.WASMRuntime,
68 Config: map[string]interface{}{
69 common.RuntimeArchiveConfigKey: "../bin/example_basic.wasm",
70 },
71 },
72 Source: utils.MakePulsarSourceTubeConfig(inputTopic),
73 Sink: *utils.MakePulsarSinkTubeConfig(outputTopic),
74 Replicas: 1,
75 }
76
77 producer, err := client.CreateProducer(pulsar.ProducerOptions{
78 Topic: inputTopic,
79 })
80 if err != nil {
81 t.Fatalf(err.Error())
82 }
83
84 consumer, err := client.Subscribe(pulsar.ConsumerOptions{
85 Topic: outputTopic,
86 SubscriptionName: "test-sub",
87 })
88 if err != nil {
89 t.Fatalf(err.Error())
90 }
91
92 res, err := cli.FunctionAPI.CreateFunction(context.Background()).Body(f).Execute()
93 if err != nil && res == nil {
94 t.Errorf("failed to create function: %v", err)
95 }
96 if res.StatusCode != 200 {
97 body, _ := io.ReadAll(res.Body)
98 t.Fatalf("expected 200, got %d: %s", res.StatusCode, body)
99 return
100 }
101
102 for i := 0; i < 10; i++ {
103 p := Person{Name: "rbt", Money: 0}
104 jsonBytes, err := json.Marshal(p)
105 if err != nil {
106 t.Fatalf(err.Error())

Callers

nothing calls this directly

Calls 8

MakePulsarSinkTubeConfigFunction · 0.92
ErrorMethod · 0.80
CreateFunctionMethod · 0.80
SendMethod · 0.65
DeleteFunctionMethod · 0.65
ExecuteMethod · 0.45
BodyMethod · 0.45

Tested by

no test coverage detected