(t *testing.T)
| 47 | } |
| 48 | |
| 49 | func 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()) |
nothing calls this directly
no test coverage detected