Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 04c9acd

Browse files
committed
change hostemulator's entrypoint signature
Signed-off-by: mathetake <[email protected]>
1 parent efb11f8 commit 04c9acd

File tree

12 files changed

+117
-48
lines changed

12 files changed

+117
-48
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,12 @@ TinyGo's official release of WASI target will come soon, and after that you coul
5252
just follow https://tinygo.org/getting-started/ to install the requirement on any platform. Stay tuned!
5353

5454

55-
### compatible Envoy builds
56-
57-
| proxy-wasm-go-sdk| proxy-wasm ABI version | envoyproxy/envoy-wasm| istio/proxyv2|
58-
|:-------------:|:-------------:|:-------------:|:-------------:|
59-
| main | 0.2.0| N/A | v1.17.x |
60-
| v0.0.4 | 0.2.0| N/A | v1.17.x |
61-
| v0.0.3 | 0.2.0| N/A | v1.17.x |
62-
| v0.0.2 | 0.1.0|release/v1.15 | N/A |
55+
### compatible ABI / Envoy builds
56+
57+
| proxy-wasm-go-sdk| proxy-wasm ABI version |istio/proxyv2|
58+
|:-------------:|:-------------:|:-------------:|
59+
| main | 0.2.0| v1.17.x |
60+
| v0.0.4 | 0.2.0| v1.17.x |
6361

6462

6563
## run examples

examples/helloworld/main_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package main
33
import (
44
"strings"
55
"testing"
6+
"time"
7+
8+
"github.com/stretchr/testify/require"
69

710
"github.com/stretchr/testify/assert"
811

@@ -11,22 +14,29 @@ import (
1114
)
1215

1316
func TestHelloWorld_OnTick(t *testing.T) {
14-
ctx := newHelloWorld(100)
15-
host := proxytest.NewHostEmulator(nil, nil, newHelloWorld, nil, nil)
17+
opt := proxytest.NewEmulatorOption().
18+
WithNewRootContext(newHelloWorld)
19+
host := proxytest.NewHostEmulator(opt)
1620
defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation
17-
ctx.OnTick()
21+
22+
host.StartVM() // call OnVMStart
23+
24+
time.Sleep(time.Duration(tickMilliseconds) * 4 * time.Millisecond)
1825

1926
logs := host.GetLogs(types.LogLevelInfo)
27+
require.Greater(t, len(logs), 0)
2028
msg := logs[len(logs)-1]
2129

2230
assert.True(t, strings.Contains(msg, "OnTick on"))
2331
}
2432

2533
func TestHelloWorld_OnVMStart(t *testing.T) {
26-
host := proxytest.NewHostEmulator(nil, nil, newHelloWorld, nil, nil)
34+
opt := proxytest.NewEmulatorOption().
35+
WithNewRootContext(newHelloWorld)
36+
host := proxytest.NewHostEmulator(opt)
2737
defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation
2838

29-
host.StartVM()
39+
host.StartVM() // call OnVMStart
3040
logs := host.GetLogs(types.LogLevelInfo)
3141
msg := logs[len(logs)-1]
3242

examples/http_auth_random/main_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import (
1111
)
1212

1313
func TestHttpAuthRandom_OnHttpRequestHeaders(t *testing.T) {
14-
host := proxytest.NewHostEmulator(nil, nil, nil, nil, newContext)
14+
opt := proxytest.NewEmulatorOption().
15+
WithNewHttpContext(newContext)
16+
host := proxytest.NewHostEmulator(opt)
1517
defer host.Done()
1618

1719
contextID := host.HttpFilterInitContext()
@@ -32,7 +34,9 @@ func TestHttpAuthRandom_OnHttpRequestHeaders(t *testing.T) {
3234
}
3335

3436
func TestHttpAuthRandom_OnHttpCallResponse(t *testing.T) {
35-
host := proxytest.NewHostEmulator(nil, nil, nil, nil, newContext)
37+
opt := proxytest.NewEmulatorOption().
38+
WithNewHttpContext(newContext)
39+
host := proxytest.NewHostEmulator(opt)
3640
defer host.Done()
3741

3842
// http://httpbin.org/uuid

examples/http_headers/main_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212
)
1313

1414
func TestHttpHeaders_OnHttpRequestHeaders(t *testing.T) {
15-
host := proxytest.NewHostEmulator(nil, nil, nil, nil, newContext)
15+
opt := proxytest.NewEmulatorOption().
16+
WithNewHttpContext(newContext)
17+
host := proxytest.NewHostEmulator(opt)
1618
defer host.Done()
1719
id := host.HttpFilterInitContext()
1820

@@ -30,7 +32,9 @@ func TestHttpHeaders_OnHttpRequestHeaders(t *testing.T) {
3032
}
3133

3234
func TestHttpHeaders_OnHttpResponseHeaders(t *testing.T) {
33-
host := proxytest.NewHostEmulator(nil, nil, nil, nil, newContext)
35+
opt := proxytest.NewEmulatorOption().
36+
WithNewHttpContext(newContext)
37+
host := proxytest.NewHostEmulator(opt)
3438
defer host.Done()
3539
id := host.HttpFilterInitContext()
3640

examples/metrics/main_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
)
1212

1313
func TestMetric(t *testing.T) {
14-
host := proxytest.NewHostEmulator(nil, nil,
15-
newRootContext, nil, newHttpContext,
16-
)
14+
opt := proxytest.NewEmulatorOption().
15+
WithNewHttpContext(newHttpContext).
16+
WithNewRootContext(newRootContext)
17+
host := proxytest.NewHostEmulator(opt)
1718
defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation
1819

1920
host.StartVM() // call OnVMStart: define metric

examples/network/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func (ctx *networkContext) OnNewConnection() types.Action {
5959

6060
func (ctx *networkContext) OnDownstreamData(dataSize int, _ bool) types.Action {
6161
if dataSize == 0 {
62-
panic("aa")
6362
return types.ActionContinue
6463
}
6564

examples/network/main_test.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import (
2525
)
2626

2727
func TestNetwork_OnNewConnection(t *testing.T) {
28-
host := proxytest.NewHostEmulator(nil, nil,
29-
newRootContext, newNetworkContext, nil)
28+
opt := proxytest.NewEmulatorOption().
29+
WithNewStreamContext(newNetworkContext).
30+
WithNewRootContext(newRootContext)
31+
host := proxytest.NewHostEmulator(opt)
3032
defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation
3133

3234
host.StartVM() // call OnVMStart: init metric
@@ -38,8 +40,10 @@ func TestNetwork_OnNewConnection(t *testing.T) {
3840
}
3941

4042
func TestNetwork_OnDownstreamClose(t *testing.T) {
41-
host := proxytest.NewHostEmulator(nil, nil,
42-
newRootContext, newNetworkContext, nil)
43+
opt := proxytest.NewEmulatorOption().
44+
WithNewStreamContext(newNetworkContext).
45+
WithNewRootContext(newRootContext)
46+
host := proxytest.NewHostEmulator(opt)
4347
defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation
4448

4549
contextID := host.NetworkFilterInitConnection() // OnNewConnection is called
@@ -51,8 +55,10 @@ func TestNetwork_OnDownstreamClose(t *testing.T) {
5155
}
5256

5357
func TestNetwork_OnDownstreamData(t *testing.T) {
54-
host := proxytest.NewHostEmulator(nil, nil,
55-
newRootContext, newNetworkContext, nil)
58+
opt := proxytest.NewEmulatorOption().
59+
WithNewStreamContext(newNetworkContext).
60+
WithNewRootContext(newRootContext)
61+
host := proxytest.NewHostEmulator(opt)
5662
defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation
5763

5864
contextID := host.NetworkFilterInitConnection() // OnNewConnection is called
@@ -66,8 +72,10 @@ func TestNetwork_OnDownstreamData(t *testing.T) {
6672
}
6773

6874
func TestNetwork_OnUpstreamData(t *testing.T) {
69-
host := proxytest.NewHostEmulator(nil, nil,
70-
newRootContext, newNetworkContext, nil)
75+
opt := proxytest.NewEmulatorOption().
76+
WithNewStreamContext(newNetworkContext).
77+
WithNewRootContext(newRootContext)
78+
host := proxytest.NewHostEmulator(opt)
7179
defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation
7280

7381
contextID := host.NetworkFilterInitConnection() // OnNewConnection is called
@@ -81,8 +89,10 @@ func TestNetwork_OnUpstreamData(t *testing.T) {
8189
}
8290

8391
func TestNetwork_counter(t *testing.T) {
84-
host := proxytest.NewHostEmulator(nil, nil,
85-
newRootContext, newNetworkContext, nil)
92+
opt := proxytest.NewEmulatorOption().
93+
WithNewStreamContext(newNetworkContext).
94+
WithNewRootContext(newRootContext)
95+
host := proxytest.NewHostEmulator(opt)
8696
defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation
8797

8898
host.StartVM() // call OnVMStart: init metric

examples/shared_data/main_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ import (
2525
)
2626

2727
func TestData(t *testing.T) {
28-
host := proxytest.NewHostEmulator(nil, nil,
29-
newRootContext, nil, newHttpContext,
30-
)
28+
opt := proxytest.NewEmulatorOption().
29+
WithNewHttpContext(newHttpContext).
30+
WithNewRootContext(newRootContext)
31+
host := proxytest.NewHostEmulator(opt)
3132
defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation
3233

3334
host.StartVM() // set initial value

examples/shared_queue/main_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ import (
2727
)
2828

2929
func TestQueue(t *testing.T) {
30-
host := proxytest.NewHostEmulator(nil, nil,
31-
newRootContext, nil, newHttpContext)
30+
opt := proxytest.NewEmulatorOption().
31+
WithNewHttpContext(newHttpContext).
32+
WithNewRootContext(newRootContext)
33+
host := proxytest.NewHostEmulator(opt)
3234
defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation
3335

3436
host.StartVM() // register the queue,set tick period

examples/vm_plugin_configuration/main_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ import (
2929
func TestContext_OnPluginStart(t *testing.T) {
3030
pluginConfigData := `{"name": "tinygo plugin configuration"}`
3131

32-
host := proxytest.NewHostEmulator([]byte(pluginConfigData), nil, newRootContext, nil, nil)
32+
opt := proxytest.NewEmulatorOption().
33+
WithPluginConfiguration([]byte(pluginConfigData)).
34+
WithNewRootContext(newRootContext)
35+
host := proxytest.NewHostEmulator(opt)
3336
defer host.Done() // release the emulation lock so that other test cases can insert their own host emulation
3437

3538
host.StartPlugin() // invoke OnPluginStart
@@ -42,7 +45,10 @@ func TestContext_OnPluginStart(t *testing.T) {
4245

4346
func TestContext_OnVMStart(t *testing.T) {
4447
vmConfigData := `{"name": "tinygo vm configuration"}`
45-
host := proxytest.NewHostEmulator(nil, []byte(vmConfigData), newRootContext, nil, nil)
48+
opt := proxytest.NewEmulatorOption().
49+
WithVMConfiguration([]byte(vmConfigData)).
50+
WithNewRootContext(newRootContext)
51+
host := proxytest.NewHostEmulator(opt)
4652
defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation
4753

4854
host.StartVM() // invoke OnVMStart

0 commit comments

Comments
 (0)