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