X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=pkg%2Fsbi%2Fnngpush_test.go;h=f3bc6e49506a3b42ce5668f6e93b084dfc2df2af;hb=a55ae650c55c106183838f76fc9fd83b4056bfdf;hp=422a03643e5e6e6d19f3073820583d3eb4902c62;hpb=aaf8d396257a455247b24716a32b05fc3fd145c2;p=ric-plt%2Frtmgr.git diff --git a/pkg/sbi/nngpush_test.go b/pkg/sbi/nngpush_test.go index 422a036..f3bc6e4 100644 --- a/pkg/sbi/nngpush_test.go +++ b/pkg/sbi/nngpush_test.go @@ -14,6 +14,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + + This source code is part of the near-RT RIC (RAN Intelligent Controller) + platform project (RICP). + ================================================================================== */ /* @@ -24,52 +28,28 @@ package sbi import ( - "errors" + //"errors" "routing-manager/pkg/rtmgr" "routing-manager/pkg/stub" + "time" + "os" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" "testing" ) -/* -Returns an error free Socket instance -*/ -func createNewStubPushSocket() (NngSocket, error) { - socket := stub.MangosSocket{} - return socket, nil -} +type Consumer struct{} -/* -Returns a SocketError -*/ -func createNewStubPushSocketError() (NngSocket, error) { - return nil, errors.New("stub generated Create Socket error") +func (m Consumer) Consume(params *xapp.RMRParams) (err error) { + xapp.Sdl.Store("myKey", params.Payload) + return nil } -/* -Returns a Socket which always generates error on Close() -*/ -func createNewStubPushSocketCloseError() (NngSocket, error) { - socket := stub.MangosSocket{} - socket.GenerateSocketCloseError = true - return socket, 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) } /* @@ -79,7 +59,7 @@ func resetTestPushDataset(instance NngPush, testdata []rtmgr.Endpoint) { 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 } } @@ -89,7 +69,6 @@ nngpush.Initialize() method is empty, nothing to be tested */ func TestNngPushInitialize(t *testing.T) { var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocket _ = nngpush.Initialize("") } @@ -99,7 +78,6 @@ nngpush.Terminate() method is empty, nothing to be tested */ func TestNngPushTerminate(t *testing.T) { var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocket _ = nngpush.Terminate() } @@ -109,8 +87,7 @@ nngpush.UpdateEndpoints() is testd against stub.ValidXApps dataset */ func TestNngPushUpdateEndpoints(t *testing.T) { var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocket - rtmgr.Eps = make(rtmgr.Endpoints) + resetTestPushDataset(nngpush, stub.ValidEndpoints) nngpush.UpdateEndpoints(&stub.ValidRicComponents) if rtmgr.Eps == nil { @@ -124,50 +101,13 @@ nngpush.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"]) + err = nngpush.AddEndpoint(rtmgr.Eps["localhost"]) 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") - } -} - -/* -nngpush.AddEndpoint() is tested for Socket creating error case -*/ -func TestNngPushAddEndpointWithSocketError(t *testing.T) { - var err error - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocketError - resetTestPushDataset(nngpush, 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) - } } -/* -nngpush.AddEndpoint() is tested for Dialing error case -*/ -func TestNngPushAddEndpointWithSocketDialError(t *testing.T) { - var err error - var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocketDialError - resetTestPushDataset(nngpush, 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 @@ -175,7 +115,6 @@ 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) @@ -185,40 +124,42 @@ func TestNngPushDistributeAll(t *testing.T) { } /* -nngpush.DistributeAll() is tested for Sending error case +nngpush.DistributeToEp() is tested for Sending case */ -func TestNngPushDistributeAllSocketSendError(t *testing.T) { +func TestDistributeToEp(t *testing.T) { var err error var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocketSendError resetTestPushDataset(nngpush, stub.ValidEndpoints) - err = nngpush.DistributeAll(stub.ValidPolicies) + err = nngpush.DistributeToEp(stub.ValidPolicies,rtmgr.Eps["localhost"]) if err != nil { - t.Errorf("nngpush.DistributeAll(policies) was incorrect, got: %v, want: %v.", err, "nil") + t.Errorf("nngpush.DistributetoEp(policies) was incorrect, got: %v, want: %v.", err, "nil") } } -func TestNngPushDeleteEndpoint(t *testing.T) { +func TestDeleteEndpoint(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"]) + err = nngpush.DeleteEndpoint(rtmgr.Eps["localhost"]) if err != nil { t.Errorf("nngpush.DeleteEndpoint() was incorrect, got: %v, want: %v.", err, "nil") } } -func TestNngPushDeleteEndpointWithSocketCloseError(t *testing.T) { - var err error +func TestCreateEndpoint(t *testing.T) { var nngpush = NngPush{} - nngpush.NewSocket = createNewStubPushSocketCloseError + resetTestPushDataset(nngpush, stub.ValidEndpoints1) + nngpush.CreateEndpoint("192.168.0.1:0") + nngpush.CreateEndpoint("localhost:4560") +} +/* +Initialize and send policies +*/ +func TestNngPushInitializeandsendPolicies(t *testing.T) { + var nngpush = NngPush{} 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") - } + policies := []string{"hello","welcome"} + nngpush.send(rtmgr.Eps["localhost"],&policies) }