[KA_AUTOMATION] - add logs to test
[ric-plt/e2mgr.git] / E2Manager / managers / ran_disconnection_manager_test.go
index 644c552..6ef0f54 100644 (file)
@@ -57,7 +57,7 @@ func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RmrMessenge
        return logger, rmrMessengerMock, readerMock, writerMock, ranDisconnectionManager, httpClient
 }
 
-func TestRanReconnectionGetNodebFailure(t *testing.T) {
+func TestRanDisconnectionGetNodebFailure(t *testing.T) {
        _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
 
        var nodebInfo *entities.NodebInfo
@@ -68,7 +68,7 @@ func TestRanReconnectionGetNodebFailure(t *testing.T) {
        writerMock.AssertNotCalled(t, "UpdateNodebInfo")
 }
 
-func TestShutdownRanReconnection(t *testing.T) {
+func TestShutdownRan(t *testing.T) {
        _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
 
        origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN}
@@ -80,7 +80,7 @@ func TestShutdownRanReconnection(t *testing.T) {
        writerMock.AssertNotCalled(t, "UpdateNodebInfo")
 }
 
-func TestShuttingdownRanReconnection(t *testing.T) {
+func TestShuttingdownRan(t *testing.T) {
        _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
 
        origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
@@ -95,7 +95,37 @@ func TestShuttingdownRanReconnection(t *testing.T) {
        writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
 }
 
-func TestConnectingRanDissociateSucceeds(t *testing.T) {
+func TestShuttingDownRanUpdateNodebInfoFailure(t *testing.T) {
+       _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
+
+       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
+       var rnibErr error
+       readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
+       updatedNodebInfo := *origNodebInfo
+       updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN
+       writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error")))
+       err := ranDisconnectionManager.DisconnectRan(ranName)
+       assert.NotNil(t, err)
+       readerMock.AssertCalled(t, "GetNodeb", ranName)
+       writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
+}
+
+func TestConnectingRanUpdateNodebInfoFailure(t *testing.T) {
+       _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
+
+       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING}
+       var rnibErr error
+       readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
+       updatedNodebInfo := *origNodebInfo
+       updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
+       writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error")))
+       err := ranDisconnectionManager.DisconnectRan(ranName)
+       assert.NotNil(t, err)
+       readerMock.AssertCalled(t, "GetNodeb", ranName)
+       writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
+}
+
+func TestConnectingRanDisconnectSucceeds(t *testing.T) {
        _, _, readerMock, writerMock, ranDisconnectionManager, httpClient := initRanLostConnectionTest(t)
 
        origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: E2TAddress}
@@ -120,10 +150,10 @@ func TestConnectingRanDissociateSucceeds(t *testing.T) {
        writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2)
 }
 
-func TestConnectingRanDissociateFails(t *testing.T) {
-       _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
+func TestConnectingRanDissociateFailsRmError(t *testing.T) {
+       _, _, readerMock, writerMock, ranDisconnectionManager, httpClient := initRanLostConnectionTest(t)
 
-       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: e2tAddress}
+       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: E2TAddress}
        var rnibErr error
        readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
        updatedNodebInfo1 := *origNodebInfo
@@ -133,43 +163,38 @@ func TestConnectingRanDissociateFails(t *testing.T) {
        updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
        updatedNodebInfo2.AssociatedE2TInstanceAddress = ""
        writerMock.On("UpdateNodebInfo", &updatedNodebInfo2).Return(rnibErr)
-       e2tInstance := &entities.E2TInstance{Address: e2tAddress, AssociatedRanList: []string{ranName}}
-       readerMock.On("GetE2TInstance", e2tAddress).Return(e2tInstance, common.NewInternalError(errors.New("Error")))
+       e2tInstance := &entities.E2TInstance{Address: E2TAddress, AssociatedRanList: []string{ranName}}
+       readerMock.On("GetE2TInstance", E2TAddress).Return(e2tInstance, nil)
+       e2tInstanceToSave := * e2tInstance
+       e2tInstanceToSave.AssociatedRanList = []string{}
+       writerMock.On("SaveE2TInstance", &e2tInstanceToSave).Return(nil)
+       mockHttpClient(httpClient, clients.DissociateRanE2TInstanceApiSuffix, false)
        err := ranDisconnectionManager.DisconnectRan(ranName)
-       assert.NotNil(t, err)
+       assert.Nil(t, err)
        readerMock.AssertCalled(t, "GetNodeb", ranName)
        writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2)
-       writerMock.AssertNotCalled(t, "SaveE2TInstance", )
 }
 
-func TestShuttingDownRanUpdateNodebInfoFailure(t *testing.T) {
+func TestConnectingRanDissociateFailsDbError(t *testing.T) {
        _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
 
-       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
-       var rnibErr error
-       readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
-       updatedNodebInfo := *origNodebInfo
-       updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN
-       writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error")))
-       err := ranDisconnectionManager.DisconnectRan(ranName)
-       assert.NotNil(t, err)
-       readerMock.AssertCalled(t, "GetNodeb", ranName)
-       writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
-}
-
-func TestRanDisconnectedUpdateNodebInfoFailure(t *testing.T) {
-       _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
-
-       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING}
+       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: e2tAddress}
        var rnibErr error
        readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
-       updatedNodebInfo := *origNodebInfo
-       updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
-       writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error")))
+       updatedNodebInfo1 := *origNodebInfo
+       updatedNodebInfo1.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
+       writerMock.On("UpdateNodebInfo", &updatedNodebInfo1).Return(rnibErr)
+       updatedNodebInfo2 := *origNodebInfo
+       updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
+       updatedNodebInfo2.AssociatedE2TInstanceAddress = ""
+       writerMock.On("UpdateNodebInfo", &updatedNodebInfo2).Return(rnibErr)
+       e2tInstance := &entities.E2TInstance{Address: e2tAddress, AssociatedRanList: []string{ranName}}
+       readerMock.On("GetE2TInstance", e2tAddress).Return(e2tInstance, common.NewInternalError(errors.New("Error")))
        err := ranDisconnectionManager.DisconnectRan(ranName)
        assert.NotNil(t, err)
        readerMock.AssertCalled(t, "GetNodeb", ranName)
-       writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
+       writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2)
+       writerMock.AssertNotCalled(t, "SaveE2TInstance", )
 }
 
 func initRmrSender(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *rmrsender.RmrSender {