@@ -21,72 +21,74 @@ import (
2121 "github.com/stretchr/testify/require"
2222
2323 "github.com/tetratelabs/proxy-wasm-go-sdk/proxytest"
24- "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
2524 "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
2625)
2726
28- func newStreamContext (uint32 ) proxywasm.StreamContext {
29- return & context {}
30- }
31-
3227func TestNetwork_OnNewConnection (t * testing.T ) {
33- host , done := proxytest .NewNetworkFilterHost (newStreamContext )
34- defer done () // release the host emulation lock so that other test cases can insert their own host emulation
28+ host := proxytest .NewHostEmulator (nil , nil ,
29+ newRootContext , newNetworkContext , nil )
30+ defer host .Done () // release the host emulation lock so that other test cases can insert their own host emulation
31+
32+ host .StartVM () // call OnVMStart: init metric
3533
36- _ = host .InitConnection () // OnNewConnection is called
34+ _ = host .NetworkFilterInitConnection () // OnNewConnection is called
3735
3836 logs := host .GetLogs (types .LogLevelInfo ) // retrieve logs emitted to Envoy
3937 assert .Equal (t , logs [0 ], "new connection!" )
4038}
4139
4240func TestNetwork_OnDownstreamClose (t * testing.T ) {
43- host , done := proxytest .NewNetworkFilterHost (newStreamContext )
44- defer done () // release the host emulation lock so that other test cases can insert their own host emulation
41+ host := proxytest .NewHostEmulator (nil , nil ,
42+ newRootContext , newNetworkContext , nil )
43+ defer host .Done () // release the host emulation lock so that other test cases can insert their own host emulation
4544
46- contextID := host .InitConnection () // OnNewConnection is called
47- host .CloseDownstreamConnection (contextID ) // OnDownstreamClose is called
45+ contextID := host .NetworkFilterInitConnection () // OnNewConnection is called
46+ host .NetworkFilterCloseDownstreamConnection (contextID ) // OnDownstreamClose is called
4847
4948 logs := host .GetLogs (types .LogLevelInfo ) // retrieve logs emitted to Envoy
5049 require .Len (t , logs , 2 )
5150 assert .Equal (t , logs [1 ], "downstream connection close!" )
5251}
5352
5453func TestNetwork_OnDownstreamData (t * testing.T ) {
55- host , done := proxytest .NewNetworkFilterHost (newStreamContext )
56- defer done () // release the host emulation lock so that other test cases can insert their own host emulation
54+ host := proxytest .NewHostEmulator (nil , nil ,
55+ newRootContext , newNetworkContext , nil )
56+ defer host .Done () // release the host emulation lock so that other test cases can insert their own host emulation
5757
58- contextID := host .InitConnection () // OnNewConnection is called
58+ contextID := host .NetworkFilterInitConnection () // OnNewConnection is called
5959
6060 msg := "this is downstream data"
6161 data := []byte (msg )
62- host .PutDownstreamData (contextID , data ) // OnDownstreamData is called
62+ host .NetworkFilterPutDownstreamData (contextID , data ) // OnDownstreamData is called
6363
6464 logs := host .GetLogs (types .LogLevelInfo ) // retrieve logs emitted to Envoy
6565 assert .Equal (t , ">>>>>> downstream data received >>>>>>\n " + msg , logs [len (logs )- 1 ])
6666}
6767
6868func TestNetwork_OnUpstreamData (t * testing.T ) {
69- host , done := proxytest .NewNetworkFilterHost (newStreamContext )
70- defer done () // release the host emulation lock so that other test cases can insert their own host emulation
69+ host := proxytest .NewHostEmulator (nil , nil ,
70+ newRootContext , newNetworkContext , nil )
71+ defer host .Done () // release the host emulation lock so that other test cases can insert their own host emulation
7172
72- contextID := host .InitConnection () // OnNewConnection is called
73+ contextID := host .NetworkFilterInitConnection () // OnNewConnection is called
7374
7475 msg := "this is upstream data"
7576 data := []byte (msg )
76- host .PutUpstreamData (contextID , data ) // OnUpstreamData is called
77+ host .NetworkFilterPutUpstreamData (contextID , data ) // OnUpstreamData is called
7778
7879 logs := host .GetLogs (types .LogLevelInfo ) // retrieve logs emitted to Envoy
7980 assert .Equal (t , "<<<<<< upstream data received <<<<<<\n " + msg , logs [len (logs )- 1 ])
8081}
8182
8283func TestNetwork_counter (t * testing.T ) {
83- host , done := proxytest .NewNetworkFilterHost (newStreamContext )
84- defer done () // release the host emulation lock so that other test cases can insert their own host emulation
84+ host := proxytest .NewHostEmulator (nil , nil ,
85+ newRootContext , newNetworkContext , nil )
86+ defer host .Done () // release the host emulation lock so that other test cases can insert their own host emulation
8587
86- context {}. OnVMStart ( 0 ) // init metric
88+ host . StartVM ( ) // call OnVMStart: init metric
8789
88- contextID := host .InitConnection ()
89- host .CompleteConnection (contextID ) // call OnDone on contextID -> increment the connection counter
90+ contextID := host .NetworkFilterInitConnection ()
91+ host .NetworkFilterCompleteConnection (contextID ) // call OnStreamDone on contextID -> increment the connection counter
9092
9193 logs := host .GetLogs (types .LogLevelInfo )
9294 require .Greater (t , len (logs ), 0 )
0 commit comments