X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=core%2Fchannel_test.go;fp=core%2Fchannel_test.go;h=7e721cd20e42ea06e023ba2bae1ab721fab2e14e;hb=639870b5083a1e66f4584ec7a5f30492fcdb7168;hp=ba761b36aeefb8a5a65e43c6644a58b6cbef83c3;hpb=572c0840e77d2c34077a054548e7559cb3670308;p=govpp.git diff --git a/core/channel_test.go b/core/channel_test.go index ba761b3..7e721cd 100644 --- a/core/channel_test.go +++ b/core/channel_test.go @@ -18,14 +18,13 @@ import ( "testing" "time" + . "github.com/onsi/gomega" + "git.fd.io/govpp.git/adapter/mock" + "git.fd.io/govpp.git/api" "git.fd.io/govpp.git/examples/binapi/interfaces" "git.fd.io/govpp.git/examples/binapi/memif" - "git.fd.io/govpp.git/examples/binapi/tap" "git.fd.io/govpp.git/examples/binapi/vpe" - - "git.fd.io/govpp.git/api" - . "github.com/onsi/gomega" ) type testCtx struct { @@ -56,93 +55,6 @@ func (ctx *testCtx) teardownTest() { ctx.conn.Disconnect() } -func TestRequestReplyTapConnect(t *testing.T) { - ctx := setupTest(t) - defer ctx.teardownTest() - - // mock reply - ctx.mockVpp.MockReply(&tap.TapConnectReply{ - SwIfIndex: 1, - }) - - request := &tap.TapConnect{ - TapName: []byte("test-tap-name"), - UseRandomMac: 1, - } - reply := &tap.TapConnectReply{} - - err := ctx.ch.SendRequest(request).ReceiveReply(reply) - Expect(err).ShouldNot(HaveOccurred()) - Expect(reply.Retval).To(BeEquivalentTo(0), - "Incorrect Retval value for TapConnectReply") - Expect(reply.SwIfIndex).To(BeEquivalentTo(1), - "Incorrect SwIfIndex value for TapConnectReply") -} - -func TestRequestReplyTapModify(t *testing.T) { - ctx := setupTest(t) - defer ctx.teardownTest() - - // mock reply - ctx.mockVpp.MockReply(&tap.TapModifyReply{ - SwIfIndex: 2, - }) - - request := &tap.TapModify{ - TapName: []byte("test-tap-modify"), - UseRandomMac: 1, - CustomDevInstance: 1, - } - reply := &tap.TapModifyReply{} - - err := ctx.ch.SendRequest(request).ReceiveReply(reply) - Expect(err).ShouldNot(HaveOccurred()) - Expect(reply.Retval).To(BeEquivalentTo(0), - "Incorrect Retval value for TapModifyReply") - Expect(reply.SwIfIndex).To(BeEquivalentTo(2), - "Incorrect SwIfIndex value for TapModifyReply") -} - -func TestRequestReplyTapDelete(t *testing.T) { - ctx := setupTest(t) - defer ctx.teardownTest() - - // mock reply - ctx.mockVpp.MockReply(&tap.TapDeleteReply{}) - - request := &tap.TapDelete{ - SwIfIndex: 3, - } - reply := &tap.TapDeleteReply{} - - err := ctx.ch.SendRequest(request).ReceiveReply(reply) - Expect(err).ShouldNot(HaveOccurred()) - Expect(reply.Retval).To(BeEquivalentTo(0), - "Incorrect Retval value for TapDeleteReply") -} - -func TestRequestReplySwInterfaceTapDump(t *testing.T) { - ctx := setupTest(t) - defer ctx.teardownTest() - - // mock reply - byteName := []byte("dev-name-test") - ctx.mockVpp.MockReply(&tap.SwInterfaceTapDetails{ - SwIfIndex: 25, - DevName: byteName, - }) - - request := &tap.SwInterfaceTapDump{} - reply := &tap.SwInterfaceTapDetails{} - - err := ctx.ch.SendRequest(request).ReceiveReply(reply) - Expect(err).ShouldNot(HaveOccurred()) - Expect(reply.SwIfIndex).To(BeEquivalentTo(25), - "Incorrect SwIfIndex value for SwInterfaceTapDetails") - Expect(reply.DevName).ToNot(BeEquivalentTo(byteName), - "Incorrect DevName value for SwInterfaceTapDetails") -} - func TestRequestReplyMemifCreate(t *testing.T) { ctx := setupTest(t) defer ctx.teardownTest() @@ -208,35 +120,6 @@ func TestRequestReplyMemifDetails(t *testing.T) { "Incorrect Role value for MemifDetails") } -func TestMultiRequestReplySwInterfaceTapDump(t *testing.T) { - ctx := setupTest(t) - defer ctx.teardownTest() - - // mock reply - var msgs []api.Message - for i := 1; i <= 10; i++ { - msgs = append(msgs, &tap.SwInterfaceTapDetails{ - SwIfIndex: uint32(i), - DevName: []byte("dev-name-test"), - }) - } - ctx.mockVpp.MockReply(msgs...) - ctx.mockVpp.MockReply(&ControlPingReply{}) - - reqCtx := ctx.ch.SendMultiRequest(&tap.SwInterfaceTapDump{}) - cnt := 0 - for { - msg := &tap.SwInterfaceTapDetails{} - stop, err := reqCtx.ReceiveReply(msg) - if stop { - break - } - Expect(err).ShouldNot(HaveOccurred()) - cnt++ - } - Expect(cnt).To(BeEquivalentTo(10)) -} - func TestMultiRequestReplySwInterfaceMemifDump(t *testing.T) { ctx := setupTest(t) defer ctx.teardownTest() @@ -479,16 +362,16 @@ func TestReceiveReplyAfterTimeout(t *testing.T) { }, // normal reply for next request mock.MsgWithContext{ - Msg: &tap.TapConnectReply{}, + Msg: &interfaces.SwInterfaceSetFlagsReply{}, SeqNum: 3, }, ) - req := &tap.TapConnect{ - TapName: []byte("test-tap-name"), - UseRandomMac: 1, + req := &interfaces.SwInterfaceSetFlags{ + SwIfIndex: 1, + AdminUpDown: 1, } - reply := &tap.TapConnectReply{} + reply := &interfaces.SwInterfaceSetFlagsReply{} // should succeed err = ctx.ch.SendRequest(req).ReceiveReply(reply) @@ -554,13 +437,13 @@ func TestReceiveReplyAfterTimeoutMultiRequest(t *testing.T) { ctx.mockVpp.MockReplyWithContext(msgs...) // normal reply for next request - ctx.mockVpp.MockReplyWithContext(mock.MsgWithContext{Msg: &tap.TapConnectReply{}, SeqNum: 3}) + ctx.mockVpp.MockReplyWithContext(mock.MsgWithContext{Msg: &interfaces.SwInterfaceSetFlagsReply{}, SeqNum: 3}) - req := &tap.TapConnect{ - TapName: []byte("test-tap-name"), - UseRandomMac: 1, + req := &interfaces.SwInterfaceSetFlags{ + SwIfIndex: 1, + AdminUpDown: 1, } - reply := &tap.TapConnectReply{} + reply := &interfaces.SwInterfaceSetFlagsReply{} // should succeed err = ctx.ch.SendRequest(req).ReceiveReply(reply)