diff --git a/vat/listener_test.go b/vat/listener_test.go index c697611..455a253 100644 --- a/vat/listener_test.go +++ b/vat/listener_test.go @@ -13,7 +13,7 @@ import ( "github.com/wetware/go/vat" ) -func TestListener(t *testing.T) { +func TestStreamHandler(t *testing.T) { t.Parallel() ctrl := gomock.NewController(t) @@ -23,12 +23,14 @@ func TestListener(t *testing.T) { defer cancel() c := test_libp2p.NewMockConn(ctrl) - c.EXPECT().RemotePeer(). + c.EXPECT(). + RemotePeer(). Return(peer.ID("test")). Times(1) s := test_libp2p.NewMockStream(ctrl) - s.EXPECT().Conn(). + s.EXPECT(). + Conn(). Return(c). Times(1) s.EXPECT().ID(). @@ -46,6 +48,29 @@ func TestListener(t *testing.T) { require.NoError(t, err) } +func TestListener(t *testing.T) { + t.Parallel() + + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + proto := vat.ProtoFromRoot("test") + + h := test_libp2p.NewMockHost(ctrl) + h.EXPECT(). + SetStreamHandler(proto, gomock.Any()). + Times(1) + h.EXPECT(). + RemoveStreamHandler(proto). + Times(1) + + l := vat.ListenConfig{Host: h}.Listen(ctx, proto) + defer l.Release() // calls h.RemoveStreamHandler +} + // func TestXXX(t *testing.T) { // t.Parallel() diff --git a/vat/util.go b/vat/util.go index 88b2223..60daad4 100644 --- a/vat/util.go +++ b/vat/util.go @@ -7,7 +7,11 @@ import ( "github.com/tetratelabs/wazero/api" ) -func ProtoFromModule(mod api.Module) protocol.ID { - path := filepath.Join(Proto, mod.Name()) +func ProtoFromRoot(path string) protocol.ID { + path = filepath.Join(Proto, path) return protocol.ID(path) } + +func ProtoFromModule(mod api.Module) protocol.ID { + return ProtoFromRoot(mod.Name()) +}