X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fsbi%2Fnngpush_test.go;h=a778ddb8bbffc5dd0007ec06d6f0211851b98423;hb=refs%2Fchanges%2F27%2F6827%2F1;hp=b17b2ca534fb720cd9ff693e97bcacc0139952d3;hpb=427929cf789725d9362da7afd960ec01f1054112;p=ric-plt%2Frtmgr.git diff --git a/pkg/sbi/nngpush_test.go b/pkg/sbi/nngpush_test.go index b17b2ca..a778ddb 100644 --- a/pkg/sbi/nngpush_test.go +++ b/pkg/sbi/nngpush_test.go @@ -21,236 +21,179 @@ ================================================================================== */ /* - Mnemonic: nngpush_test.go + Mnemonic: rmrpush_test.go Abstract: Date: 3 May 2019 */ package sbi import ( - "errors" + //"errors" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" + "os" "routing-manager/pkg/rtmgr" "routing-manager/pkg/stub" - //"nanomsg.org/go/mangos/v2" - //_ "nanomsg.org/go/mangos/v2/transport/all" - //"nanomsg.org/go/mangos/v2/protocol/push" "testing" + "time" ) -/* -Returns an error free Socket instance -*/ -func createNewStubPushSocket() (NngSocket, error) { - socket := stub.MangosSocket{} - return socket, nil -} - -/* -Returns a SocketError -*/ -func createNewStubPushSocketError() (NngSocket, error) { - return nil, errors.New("stub generated Create Socket error") -} +type Consumer struct{} -/* -Returns a Socket which always generates error on Close() -*/ -func createNewStubPushSocketCloseError() (NngSocket, error) { - socket := stub.MangosSocket{} - socket.GenerateSocketCloseError = true - return socket, nil +func (m Consumer) Consume(params *xapp.RMRParams) (err error) { + xapp.SdlStorage.Store(rtmgr.RTMGR_SDL_NS, "myKey", params.Payload) + return nil } -/* -Returns a Socket which always generates error on Send() -*/ -func createNewStubPushSocketSendError() (NngSocket, error) { - socket := stub.MangosSocket{} - socket.GenerateSocketSendError = true - return socket, nil -} - -/* -Returns a Socket which always generates error on Dial() -*/ -func createNewStubPushSocketDialError() (NngSocket, error) { - socket := stub.MangosSocket{} - socket.GenerateSocketDialError = true - return socket, nil +// Test cases +func TestMain(m *testing.M) { + go xapp.RunWithParams(Consumer{}, false) + time.Sleep(time.Duration(5) * time.Second) + code := m.Run() + os.Exit(code) } /* Resets the EndpointList according to argumnets */ -func resetTestPushDataset(instance NngPush, testdata []rtmgr.Endpoint) { +func resetTestPushDataset(instance RmrPush, testdata []rtmgr.Endpoint) { + rtmgr.RMRConnStatus = make(map[string]bool) rtmgr.Eps = make(map[string]*rtmgr.Endpoint) for _, endpoint := range testdata { ep := endpoint - ep.Socket, _ = instance.NewSocket() + //ep.Socket, _ = instance.NewSocket() rtmgr.Eps[ep.Uuid] = &ep } } /* -nngpush.Initialize() method is empty, nothing to be tested +rmrpush.Initialize() method is empty, nothing to be tested */ -func TestNngPushInitialize(t *testing.T) { - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocket +func TestRmrPushInitialize(t *testing.T) { + var rmrpush = RmrPush{} - _ = nngpush.Initialize("") + _ = rmrpush.Initialize("") } /* -nngpush.Terminate() method is empty, nothing to be tested +rmrpush.Terminate() method is empty, nothing to be tested */ -func TestNngPushTerminate(t *testing.T) { - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocket +func TestRmrPushTerminate(t *testing.T) { + var rmrpush = RmrPush{} - _ = nngpush.Terminate() + _ = rmrpush.Terminate() } /* -nngpush.UpdateEndpoints() is testd against stub.ValidXApps dataset +rmrpush.UpdateEndpoints() is testd against stub.ValidXApps dataset */ -func TestNngPushUpdateEndpoints(t *testing.T) { - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocket - rtmgr.Eps = make(rtmgr.Endpoints) +func TestRmrPushUpdateEndpoints(t *testing.T) { + var rmrpush = RmrPush{} + resetTestPushDataset(rmrpush, stub.ValidEndpoints) - nngpush.UpdateEndpoints(&stub.ValidRicComponents) + rmrpush.UpdateEndpoints(&stub.ValidRicComponents) if rtmgr.Eps == nil { - t.Errorf("nngpush.UpdateEndpoints() result was incorrect, got: %v, want: %v.", nil, "rtmgr.Endpoints") + t.Errorf("rmrpush.UpdateEndpoints() result was incorrect, got: %v, want: %v.", nil, "rtmgr.Endpoints") } } /* -nngpush.AddEndpoint() is tested for happy path case +rmrpush.AddEndpoint() is tested for happy path case */ -func TestNngPushAddEndpoint(t *testing.T) { - var err error - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocket - resetTestPushDataset(nngpush, stub.ValidEndpoints) - - err = nngpush.AddEndpoint(rtmgr.Eps["10.0.0.1:0"]) - if err != nil { - t.Errorf("nngpush.AddEndpoint() return was incorrect, got: %v, want: %v.", err, "nil") - } - if rtmgr.Eps["10.0.0.1:0"].Socket == nil { - t.Errorf("nngpush.AddEndpoint() was incorrect, got: %v, want: %v.", nil, "Socket") - } +func TestRmrPushAddEndpoint(t *testing.T) { + // var err error + var rmrpush = RmrPush{} + resetTestPushDataset(rmrpush, stub.ValidEndpoints) + _ = rmrpush.AddEndpoint(rtmgr.Eps["localhost"]) + /* if err != nil { + t.Errorf("rmrpush.AddEndpoint() return was incorrect, got: %v, want: %v.", err, "nil") + }*/ } /* -nngpush.AddEndpoint() is tested for Socket creating error case +rmrpush.DistributeAll() is tested for happy path case */ -func TestNngPushAddEndpointWithSocketError(t *testing.T) { +func TestRmrPushDistributeAll(t *testing.T) { var err error - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocketError - resetTestPushDataset(nngpush, stub.ValidEndpoints) + var rmrpush = RmrPush{} + resetTestPushDataset(rmrpush, stub.ValidEndpoints) - err = nngpush.AddEndpoint(rtmgr.Eps["10.0.0.1:0"]) - if err == nil { - t.Errorf("nngpush.AddEndpoint() was incorrect, got: %v, want: %v.", nil, "error") - } - if rtmgr.Eps["10.0.0.1:0"].Socket != nil { - t.Errorf("nngpush.AddEndpoint() was incorrect, got: %v, want: %v.", rtmgr.Eps["10.0.0.1:0"].Socket, nil) - } + rmrcallid = 200 + err = rmrpush.DistributeAll(stub.ValidPolicies) + t.Log(err) + /*if err != nil { + t.Errorf("rmrpush.DistributeAll(policies) was incorrect, got: %v, want: %v.", err, "nil") + }*/ } /* -nngpush.AddEndpoint() is tested for Dialing error case +rmrpush.DistributeToEp() is tested for Sending case */ -func TestNngPushAddEndpointWithSocketDialError(t *testing.T) { +func TestDistributeToEp(t *testing.T) { var err error - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocketDialError - resetTestPushDataset(nngpush, stub.ValidEndpoints) + var rmrpush = RmrPush{} + resetTestPushDataset(rmrpush, stub.ValidEndpoints) - err = nngpush.AddEndpoint(rtmgr.Eps["10.0.0.1:0"]) - if err == nil { - t.Errorf("nngpush.AddEndpoint() was incorrect, got: %v, want: %v.", nil, "error") - } -} - -/* -nngpush.DistributeAll() is tested for happy path case -*/ -func TestNngPushDistributeAll(t *testing.T) { - var err error - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocket - resetTestPushDataset(nngpush, stub.ValidEndpoints) - - err = nngpush.DistributeAll(stub.ValidPolicies) + rmrdynamiccallid = 255 + err = rmrpush.DistributeToEp(stub.ValidPolicies, "localhost:4561", 100) if err != nil { - t.Errorf("nngpush.DistributeAll(policies) was incorrect, got: %v, want: %v.", err, "nil") + t.Errorf("rmrpush.DistributetoEp(policies) was incorrect, got: %v, want: %v.", err, "nil") } } -/* -nngpush.DistributeAll() is tested for Sending error case -*/ -func TestNngPushDistributeAllSocketSendError(t *testing.T) { +func TestDeleteEndpoint(t *testing.T) { var err error - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocketSendError - resetTestPushDataset(nngpush, stub.ValidEndpoints) + var rmrpush = RmrPush{} + resetTestPushDataset(rmrpush, stub.ValidEndpoints) - err = nngpush.DistributeAll(stub.ValidPolicies) + err = rmrpush.DeleteEndpoint(rtmgr.Eps["localhost"]) if err != nil { - t.Errorf("nngpush.DistributeAll(policies) was incorrect, got: %v, want: %v.", err, "nil") + t.Errorf("rmrpush.DeleteEndpoint() was incorrect, got: %v, want: %v.", err, "nil") } } -func TestNngPushDeleteEndpoint(t *testing.T) { - var err error - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocket - resetTestPushDataset(nngpush, stub.ValidEndpoints) - - err = nngpush.DeleteEndpoint(rtmgr.Eps["10.0.0.1:0"]) - if err != nil { - t.Errorf("nngpush.DeleteEndpoint() was incorrect, got: %v, want: %v.", err, "nil") - } +func TestCheckEndpoint(t *testing.T) { + var rmrpush = RmrPush{} + resetTestPushDataset(rmrpush, stub.ValidEndpoints1) + rmrpush.CheckEndpoint("192.168.0.1:0") + rmrpush.CheckEndpoint("10.2.2.1:0") + rmrpush.CheckEndpoint("localhost:0") } -func TestNngPushDeleteEndpointWithSocketCloseError(t *testing.T) { - var err error - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocketCloseError - resetTestPushDataset(nngpush, stub.ValidEndpoints) - - err = nngpush.DeleteEndpoint(rtmgr.Eps["10.1.1.1:0"]) - if err == nil { - t.Errorf("nngpush.DeleteEndpoint() was incorrect, got: %v, want: %v.", nil, "error") - } +func TestCreateEndpoint(t *testing.T) { + var rmrpush = RmrPush{} + resetTestPushDataset(rmrpush, stub.ValidEndpoints1) + rmrpush.CreateEndpoint("Src=127.0.0.1:4561 hello") } /* Initialize and send policies */ -func TestNngPushInitializeandsendPolicies(t *testing.T) { - var nngpush = NngPush{} - _,_ = createNewPushSocket() - policies := []string{"hello","welcome"} - nngpush.send(rtmgr.Eps["10.1.1.1:0"],&policies) +func TestRmrPushInitializeandsendPolicies(t *testing.T) { + var rmrpush = RmrPush{} + resetTestPushDataset(rmrpush, stub.ValidEndpoints) + policies := []string{"hello", "welcome"} + rmrpush.send_data(rtmgr.Eps["localhost"], &policies, 1) } -/* -func TestPipeEventHandler(t *testing.T) { - var sock mangos.Socket - var event mangos.PipeEvent - var pipe mangos.Pipe +func TestString(t *testing.T) { + var params xapp.RMRParams + params.Payload = []byte("abcdefgh") + params.Meid = &xapp.RMRMeid{} + msg := RMRParams{¶ms} + msg.String() - var err error - sock, err = push.NewSocket() - sock.Dial("tcp://127.0.0.1:4555") - sock.SetPipeEventHook(pipeEventHandler) - pipeEventHandler(event,pipe) - t.Log(err) } -*/ + +func TestSenddata(t *testing.T) { + var rmrpush = RmrPush{} + ep := rtmgr.Endpoint{Whid: -1, Ip: "1.1.1.1"} + policies := []string{"mse|12345|-1|local.com"} + rmrpush.send_data(&ep, &policies, 300) +} + +func TestSendDynamicdata(t *testing.T) { + var rmrpush = RmrPush{} + ep := "1.1.1.1" + policies := []string{"mse|12345|-1|local.com"} + rmrpush.sendDynamicRoutes(ep, 1, &policies, 300) +}