@@ -13,6 +13,7 @@ import (
1313 "testing"
1414 "time"
1515
16+ "github.com/Microsoft/hcsshim/internal/gcs/prot"
1617 "github.com/sirupsen/logrus"
1718)
1819
@@ -33,7 +34,7 @@ func pipeConn() (*stitched, *stitched) {
3334 return & stitched {r1 , w2 }, & stitched {r2 , w1 }
3435}
3536
36- func sendMessage (t * testing.T , w io.Writer , typ msgType , id int64 , msg []byte ) {
37+ func sendMessage (t * testing.T , w io.Writer , typ prot. MsgType , id int64 , msg []byte ) {
3738 t .Helper ()
3839 var h [16 ]byte
3940 binary .LittleEndian .PutUint32 (h [:], uint32 (typ ))
@@ -63,18 +64,18 @@ func reflector(t *testing.T, rw io.ReadWriteCloser, delay time.Duration) {
6364 return
6465 }
6566 time .Sleep (delay ) // delay is used to test timeouts (when non-zero)
66- typ ^= msgTypeResponse ^ msgTypeRequest
67+ typ ^= prot . MsgTypeResponse ^ prot . MsgTypeRequest
6768 sendMessage (t , rw , typ , id , msg )
6869 }
6970}
7071
7172type testReq struct {
72- requestBase
73+ prot. RequestBase
7374 X , Y int
7475}
7576
7677type testResp struct {
77- responseBase
78+ prot. ResponseBase
7879 X , Y int
7980}
8081
@@ -92,7 +93,7 @@ func TestBridgeRPC(t *testing.T) {
9293 defer b .Close ()
9394 req := testReq {X : 5 }
9495 var resp testResp
95- err := b .RPC (context .Background (), rpcCreate , & req , & resp , false )
96+ err := b .RPC (context .Background (), prot . RpcCreate , & req , & resp , false )
9697 if err != nil {
9798 t .Fatal (err )
9899 }
@@ -107,7 +108,7 @@ func TestBridgeRPCResponseTimeout(t *testing.T) {
107108 b .Timeout = time .Millisecond * 100
108109 req := testReq {X : 5 }
109110 var resp testResp
110- err := b .RPC (context .Background (), rpcCreate , & req , & resp , false )
111+ err := b .RPC (context .Background (), prot . RpcCreate , & req , & resp , false )
111112 if err == nil || ! strings .Contains (err .Error (), "bridge closed" ) {
112113 t .Fatalf ("expected bridge disconnection, got %s" , err )
113114 }
@@ -121,7 +122,7 @@ func TestBridgeRPCContextDone(t *testing.T) {
121122 defer cancel ()
122123 req := testReq {X : 5 }
123124 var resp testResp
124- err := b .RPC (ctx , rpcCreate , & req , & resp , true )
125+ err := b .RPC (ctx , prot . RpcCreate , & req , & resp , true )
125126 if err != context .DeadlineExceeded { //nolint:errorlint
126127 t .Fatalf ("expected deadline exceeded, got %s" , err )
127128 }
@@ -135,7 +136,7 @@ func TestBridgeRPCContextDoneNoCancel(t *testing.T) {
135136 defer cancel ()
136137 req := testReq {X : 5 }
137138 var resp testResp
138- err := b .RPC (ctx , rpcCreate , & req , & resp , false )
139+ err := b .RPC (ctx , prot . RpcCreate , & req , & resp , false )
139140 if err == nil || ! strings .Contains (err .Error (), "bridge closed" ) {
140141 t .Fatalf ("expected bridge disconnection, got %s" , err )
141142 }
@@ -145,13 +146,13 @@ func TestBridgeRPCBridgeClosed(t *testing.T) {
145146 b := startReflectedBridge (t , 0 )
146147 eerr := errors .New ("forcibly terminated" )
147148 b .kill (eerr )
148- err := b .RPC (context .Background (), rpcCreate , nil , nil , false )
149+ err := b .RPC (context .Background (), prot . RpcCreate , nil , nil , false )
149150 if err != eerr { //nolint:errorlint
150151 t .Fatal ("unexpected: " , err )
151152 }
152153}
153154
154- func sendJSON (t * testing.T , w io.Writer , typ msgType , id int64 , msg interface {}) error {
155+ func sendJSON (t * testing.T , w io.Writer , typ prot. MsgType , id int64 , msg interface {}) error {
155156 t .Helper ()
156157 msgb , err := json .Marshal (msg )
157158 if err != nil {
@@ -161,7 +162,7 @@ func sendJSON(t *testing.T, w io.Writer, typ msgType, id int64, msg interface{})
161162 return nil
162163}
163164
164- func notifyThroughBridge (t * testing.T , typ msgType , msg interface {}, fn notifyFunc ) error {
165+ func notifyThroughBridge (t * testing.T , typ prot. MsgType , msg interface {}, fn notifyFunc ) error {
165166 t .Helper ()
166167 s , c := pipeConn ()
167168 b := newBridge (s , fn , logrus .NewEntry (logrus .StandardLogger ()))
@@ -176,9 +177,9 @@ func notifyThroughBridge(t *testing.T, typ msgType, msg interface{}, fn notifyFu
176177}
177178
178179func TestBridgeNotify (t * testing.T ) {
179- ntf := & containerNotification {Operation : "testing" }
180+ ntf := & prot. ContainerNotification {Operation : "testing" }
180181 recvd := false
181- err := notifyThroughBridge (t , msgTypeNotify | notifyContainer , ntf , func (nntf * containerNotification ) error {
182+ err := notifyThroughBridge (t , prot . MsgTypeNotify | prot . NotifyContainer , ntf , func (nntf * prot. ContainerNotification ) error {
182183 if ! reflect .DeepEqual (ntf , nntf ) {
183184 t .Errorf ("%+v != %+v" , ntf , nntf )
184185 }
@@ -194,9 +195,9 @@ func TestBridgeNotify(t *testing.T) {
194195}
195196
196197func TestBridgeNotifyFailure (t * testing.T ) {
197- ntf := & containerNotification {Operation : "testing" }
198+ ntf := & prot. ContainerNotification {Operation : "testing" }
198199 errMsg := "notify should have failed"
199- err := notifyThroughBridge (t , msgTypeNotify | notifyContainer , ntf , func (nntf * containerNotification ) error {
200+ err := notifyThroughBridge (t , prot . MsgTypeNotify | prot . NotifyContainer , ntf , func (nntf * prot. ContainerNotification ) error {
200201 return errors .New (errMsg )
201202 })
202203 if err == nil || ! strings .Contains (err .Error (), errMsg ) {
0 commit comments